Skip to content

Commit 7943313

Browse files
committed
add some tests
1 parent 286ad41 commit 7943313

File tree

4 files changed

+208
-2
lines changed

4 files changed

+208
-2
lines changed

ydb/core/config/tools/protobuf_plugin/ut.cpp

+151
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <ydb/core/config/tools/protobuf_plugin/ut/protos/config_root_test.pb.h>
2+
#include <ydb/core/config/tools/protobuf_plugin/ut/protos/copy_to_test.pb.h>
23

34
#include <library/cpp/testing/unittest/registar.h>
45

@@ -21,4 +22,154 @@ Y_UNIT_TEST_SUITE(ValidationTests) {
2122
UNIT_ASSERT(msg.HasField1());
2223
UNIT_ASSERT((msg.*has1)());
2324
}
25+
26+
Y_UNIT_TEST(CanCopyTo) {
27+
NKikimrConfig::SourceMessage source;
28+
NKikimrConfig::FirstSinkMessage firstSink;
29+
NKikimrConfig::SecondSinkMessage secondSink;
30+
31+
source.CopyToFirstSinkMessage(firstSink);
32+
source.CopyToSecondSinkMessage(secondSink);
33+
34+
UNIT_ASSERT(!source.HasStringField1());
35+
UNIT_ASSERT(!source.HasStringField2());
36+
UNIT_ASSERT(!source.HasStringField3());
37+
UNIT_ASSERT(!source.HasStringField4());
38+
UNIT_ASSERT(!source.StringField5Size());
39+
UNIT_ASSERT(!source.StringField6Size());
40+
UNIT_ASSERT(!source.StringField7Size());
41+
UNIT_ASSERT(!source.StringField8Size());
42+
UNIT_ASSERT(!source.HasComplexMessage1());
43+
UNIT_ASSERT(!source.HasComplexMessage2());
44+
UNIT_ASSERT(!source.HasComplexMessage3());
45+
UNIT_ASSERT(!source.HasComplexMessage4());
46+
UNIT_ASSERT(!source.ComplexMessage5Size());
47+
UNIT_ASSERT(!source.ComplexMessage6Size());
48+
UNIT_ASSERT(!source.ComplexMessage7Size());
49+
UNIT_ASSERT(!source.ComplexMessage8Size());
50+
51+
UNIT_ASSERT(!firstSink.HasStringField2());
52+
UNIT_ASSERT(!firstSink.HasStringField4());
53+
UNIT_ASSERT(!firstSink.StringField6Size());
54+
UNIT_ASSERT(!firstSink.StringField8Size());
55+
UNIT_ASSERT(!firstSink.HasComplexMessage2());
56+
UNIT_ASSERT(!firstSink.HasComplexMessage4());
57+
UNIT_ASSERT(!firstSink.ComplexMessage6Size());
58+
UNIT_ASSERT(!firstSink.ComplexMessage8Size());
59+
60+
UNIT_ASSERT(!secondSink.HasStringField3());
61+
UNIT_ASSERT(!secondSink.HasStringField4());
62+
UNIT_ASSERT(!secondSink.StringField7Size());
63+
UNIT_ASSERT(!secondSink.StringField8Size());
64+
UNIT_ASSERT(!secondSink.HasComplexMessage3());
65+
UNIT_ASSERT(!secondSink.HasComplexMessage4());
66+
UNIT_ASSERT(!secondSink.ComplexMessage7Size());
67+
UNIT_ASSERT(!secondSink.ComplexMessage8Size());
68+
69+
source.SetStringField1("string1");
70+
source.SetStringField2("string2");
71+
source.SetStringField3("string3");
72+
source.SetStringField4("string4");
73+
source.AddStringField5("string5-1");
74+
source.AddStringField5("string5-2");
75+
source.AddStringField6("string6-1");
76+
source.AddStringField6("string6-2");
77+
source.AddStringField6("string6-3");
78+
source.AddStringField7("string7-1");
79+
source.AddStringField7("string7-2");
80+
source.AddStringField7("string7-3");
81+
source.AddStringField7("string7-4");
82+
source.AddStringField8("string8-1");
83+
source.AddStringField8("string8-2");
84+
source.AddStringField8("string8-3");
85+
source.AddStringField8("string8-4");
86+
source.AddStringField8("string8-5");
87+
88+
source.SetIntField(1);
89+
90+
source.MutableComplexMessage1()->SetStringField("cm1-string");
91+
source.MutableComplexMessage2()->SetStringField("cm2-string");
92+
source.MutableComplexMessage3()->SetStringField("cm3-string");
93+
source.MutableComplexMessage4()->SetStringField("cm4-string");
94+
source.AddComplexMessage5()->SetStringField("cm5-string-1");
95+
source.AddComplexMessage5()->SetStringField("cm5-string-2");
96+
source.AddComplexMessage6()->SetStringField("cm6-string-1");
97+
source.AddComplexMessage6()->SetStringField("cm6-string-2");
98+
source.AddComplexMessage6()->SetStringField("cm6-string-3");
99+
source.AddComplexMessage7()->SetStringField("cm7-string-1");
100+
source.AddComplexMessage7()->SetStringField("cm7-string-2");
101+
source.AddComplexMessage7()->SetStringField("cm7-string-3");
102+
source.AddComplexMessage7()->SetStringField("cm7-string-4");
103+
source.AddComplexMessage8()->SetStringField("cm8-string-1");
104+
source.AddComplexMessage8()->SetStringField("cm8-string-2");
105+
source.AddComplexMessage8()->SetStringField("cm8-string-3");
106+
source.AddComplexMessage8()->SetStringField("cm8-string-4");
107+
source.AddComplexMessage8()->SetStringField("cm8-string-5");
108+
109+
firstSink.SetIntField(2);
110+
secondSink.SetIntField(3);
111+
112+
TString expectedSource = source.ShortDebugString();
113+
114+
source.CopyToFirstSinkMessage(firstSink);
115+
116+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetStringField2(), source.GetStringField2());
117+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetStringField4(), source.GetStringField4());
118+
UNIT_ASSERT_VALUES_EQUAL(firstSink.StringField6Size(), source.StringField6Size());
119+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetStringField6(0), source.GetStringField6(0));
120+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetStringField6(1), source.GetStringField6(1));
121+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetStringField6(2), source.GetStringField6(2));
122+
UNIT_ASSERT_VALUES_EQUAL(firstSink.StringField8Size(), source.StringField8Size());
123+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetStringField8(0), source.GetStringField8(0));
124+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetStringField8(1), source.GetStringField8(1));
125+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetStringField8(2), source.GetStringField8(2));
126+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetStringField8(3), source.GetStringField8(3));
127+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetStringField8(4), source.GetStringField8(4));
128+
UNIT_ASSERT_VALUES_EQUAL(firstSink.ComplexMessage6Size(), source.ComplexMessage6Size());
129+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetComplexMessage6(0).ShortDebugString(), source.GetComplexMessage6(0).ShortDebugString());
130+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetComplexMessage6(1).ShortDebugString(), source.GetComplexMessage6(1).ShortDebugString());
131+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetComplexMessage6(2).ShortDebugString(), source.GetComplexMessage6(2).ShortDebugString());
132+
UNIT_ASSERT_VALUES_EQUAL(firstSink.ComplexMessage8Size(), source.ComplexMessage8Size());
133+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetComplexMessage8(0).ShortDebugString(), source.GetComplexMessage8(0).ShortDebugString());
134+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetComplexMessage8(1).ShortDebugString(), source.GetComplexMessage8(1).ShortDebugString());
135+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetComplexMessage8(2).ShortDebugString(), source.GetComplexMessage8(2).ShortDebugString());
136+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetComplexMessage8(3).ShortDebugString(), source.GetComplexMessage8(3).ShortDebugString());
137+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetComplexMessage8(4).ShortDebugString(), source.GetComplexMessage8(4).ShortDebugString());
138+
UNIT_ASSERT_VALUES_EQUAL(firstSink.GetIntField(), 2);
139+
140+
UNIT_ASSERT_VALUES_EQUAL(expectedSource, source.ShortDebugString());
141+
142+
TString expectedFirstSink = firstSink.ShortDebugString();
143+
144+
source.CopyToSecondSinkMessage(secondSink);
145+
146+
UNIT_ASSERT_VALUES_EQUAL(expectedSource, source.ShortDebugString());
147+
UNIT_ASSERT_VALUES_EQUAL(expectedFirstSink, firstSink.ShortDebugString());
148+
149+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetStringField3(), source.GetStringField3());
150+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetStringField4(), source.GetStringField4());
151+
UNIT_ASSERT_VALUES_EQUAL(secondSink.StringField7Size(), source.StringField7Size());
152+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetStringField7(0), source.GetStringField7(0));
153+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetStringField7(1), source.GetStringField7(1));
154+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetStringField7(2), source.GetStringField7(2));
155+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetStringField7(3), source.GetStringField7(3));
156+
UNIT_ASSERT_VALUES_EQUAL(secondSink.StringField8Size(), source.StringField8Size());
157+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetStringField8(0), source.GetStringField8(0));
158+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetStringField8(1), source.GetStringField8(1));
159+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetStringField8(2), source.GetStringField8(2));
160+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetStringField8(3), source.GetStringField8(3));
161+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetStringField8(4), source.GetStringField8(4));
162+
UNIT_ASSERT_VALUES_EQUAL(secondSink.ComplexMessage7Size(), source.ComplexMessage7Size());
163+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetComplexMessage7(0).ShortDebugString(), source.GetComplexMessage7(0).ShortDebugString());
164+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetComplexMessage7(1).ShortDebugString(), source.GetComplexMessage7(1).ShortDebugString());
165+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetComplexMessage7(2).ShortDebugString(), source.GetComplexMessage7(2).ShortDebugString());
166+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetComplexMessage7(3).ShortDebugString(), source.GetComplexMessage7(3).ShortDebugString());
167+
UNIT_ASSERT_VALUES_EQUAL(secondSink.ComplexMessage8Size(), source.ComplexMessage8Size());
168+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetComplexMessage8(0).ShortDebugString(), source.GetComplexMessage8(0).ShortDebugString());
169+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetComplexMessage8(1).ShortDebugString(), source.GetComplexMessage8(1).ShortDebugString());
170+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetComplexMessage8(2).ShortDebugString(), source.GetComplexMessage8(2).ShortDebugString());
171+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetComplexMessage8(3).ShortDebugString(), source.GetComplexMessage8(3).ShortDebugString());
172+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetComplexMessage8(4).ShortDebugString(), source.GetComplexMessage8(4).ShortDebugString());
173+
UNIT_ASSERT_VALUES_EQUAL(secondSink.GetIntField(), 3);
174+
}
24175
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import "ydb/core/config/protos/marker.proto";
2+
3+
package NKikimrConfig;
4+
option java_package = "ru.yandex.kikimr.proto";
5+
6+
message SomeComplexMessage {
7+
optional string StringField = 1;
8+
optional uint32 IntField = 2;
9+
}
10+
11+
message SourceMessage {
12+
option (NMarkers.CombinedType) = true;
13+
optional string StringField1 = 1;
14+
optional string StringField2 = 2 [(NMarkers.CopyTo) = "FirstSinkMessage"];
15+
optional string StringField3 = 3 [(NMarkers.CopyTo) = "SecondSinkMessage"];
16+
optional string StringField4 = 4 [(NMarkers.CopyTo) = "FirstSinkMessage", (NMarkers.CopyTo) = "SecondSinkMessage"];
17+
repeated string StringField5 = 5;
18+
repeated string StringField6 = 6 [(NMarkers.CopyTo) = "FirstSinkMessage"];
19+
repeated string StringField7 = 7 [(NMarkers.CopyTo) = "SecondSinkMessage"];
20+
repeated string StringField8 = 8 [(NMarkers.CopyTo) = "FirstSinkMessage", (NMarkers.CopyTo) = "SecondSinkMessage"];
21+
optional uint32 IntField = 9;
22+
optional SomeComplexMessage ComplexMessage1 = 10;
23+
optional SomeComplexMessage ComplexMessage2 = 11 [(NMarkers.CopyTo) = "FirstSinkMessage"];
24+
optional SomeComplexMessage ComplexMessage3 = 12 [(NMarkers.CopyTo) = "SecondSinkMessage"];
25+
optional SomeComplexMessage ComplexMessage4 = 13 [(NMarkers.CopyTo) = "FirstSinkMessage", (NMarkers.CopyTo) = "SecondSinkMessage"];
26+
repeated SomeComplexMessage ComplexMessage5 = 14;
27+
repeated SomeComplexMessage ComplexMessage6 = 15 [(NMarkers.CopyTo) = "FirstSinkMessage"];
28+
repeated SomeComplexMessage ComplexMessage7 = 16 [(NMarkers.CopyTo) = "SecondSinkMessage"];
29+
repeated SomeComplexMessage ComplexMessage8 = 17 [(NMarkers.CopyTo) = "FirstSinkMessage", (NMarkers.CopyTo) = "SecondSinkMessage"];
30+
}
31+
32+
message FirstSinkMessage {
33+
optional string StringField2 = 1;
34+
optional string StringField4 = 3;
35+
repeated string StringField6 = 4;
36+
repeated string StringField8 = 8;
37+
optional uint32 IntField = 9;
38+
optional SomeComplexMessage ComplexMessage2 = 101;
39+
optional SomeComplexMessage ComplexMessage4 = 103;
40+
repeated SomeComplexMessage ComplexMessage6 = 104;
41+
repeated SomeComplexMessage ComplexMessage8 = 106;
42+
}
43+
44+
message SecondSinkMessage {
45+
optional string StringField3 = 2;
46+
optional string StringField4 = 3;
47+
repeated string StringField7 = 5;
48+
repeated string StringField8 = 8;
49+
optional uint32 IntField = 9;
50+
optional SomeComplexMessage ComplexMessage3 = 102;
51+
optional SomeComplexMessage ComplexMessage4 = 103;
52+
repeated SomeComplexMessage ComplexMessage7 = 105;
53+
repeated SomeComplexMessage ComplexMessage8 = 106;
54+
}

ydb/core/config/tools/protobuf_plugin/ut/protos/ya.make

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PEERDIR(
66

77
SRCS(
88
config_root_test.proto
9+
copy_to_test.proto
910
)
1011

1112
CPP_PROTO_PLUGIN0(config_proto_plugin ydb/core/config/tools/protobuf_plugin)

ydb/public/lib/protobuf/macro.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#define WITH_INDENT(printer) if (TScopeIndentPrinterGuard indentGuard(printer); true)
2-
#define WITH_PLUGIN_MARKUP(printer, pluginName) if (TPluginMarkupPrinterGuard indentGuard(printer, pluginName); true)
1+
#define WITH_INDENT(printer) if (::NKikimr::NProtobuf::TScopeIndentPrinterGuard indentGuard(printer); true)
2+
#define WITH_PLUGIN_MARKUP(printer, pluginName) if (::NKikimr::NProtobuf::TPluginMarkupPrinterGuard indentGuard(printer, pluginName); true)

0 commit comments

Comments
 (0)