@@ -46,6 +46,17 @@ const char kMessages[] = R"(
46
46
repeated_msg { required_int32: 67 }
47
47
repeated_msg {}
48
48
}
49
+ any {
50
+ [type.googleapis.com/protobuf_mutator.Msg] {
51
+ optional_msg {}
52
+ repeated_msg {}
53
+ any {
54
+ [type.googleapis.com/protobuf_mutator.Msg3.SubMsg] {
55
+ optional_int64: -5
56
+ }
57
+ }
58
+ }
59
+ }
49
60
)" ;
50
61
51
62
const char kMessagesProto3 [] = R"(
@@ -59,6 +70,17 @@ const char kMessagesProto3[] = R"(
59
70
repeated_msg { optional_int32: 67 }
60
71
repeated_msg {}
61
72
}
73
+ any {
74
+ [type.googleapis.com/protobuf_mutator.Msg] {
75
+ optional_msg {}
76
+ repeated_msg {}
77
+ any {
78
+ [type.googleapis.com/protobuf_mutator.Msg3.SubMsg] {
79
+ optional_int64: -5
80
+ }
81
+ }
82
+ }
83
+ }
62
84
)" ;
63
85
64
86
const char kRequiredFields [] = R"(
@@ -154,6 +176,18 @@ const char kRequiredNestedFields[] = R"(
154
176
}
155
177
)" ;
156
178
179
+ const char kRequiredInAnyFields [] = R"(
180
+ any {
181
+ [type.googleapis.com/protobuf_mutator.Msg] {
182
+ required_uint32: 14486213
183
+ required_uint64: 520229415
184
+ required_sint64: -6057486163525532641
185
+ required_string: "qwert"
186
+ required_bytes: "asdf"
187
+ }
188
+ }
189
+ )" ;
190
+
157
191
const char kOptionalNestedFields [] = R"(
158
192
optional_int32: 123
159
193
optional_msg {
@@ -176,6 +210,18 @@ const char kOptionalNestedFields[] = R"(
176
210
}
177
211
)" ;
178
212
213
+ const char kOptionalInAnyFields [] = R"(
214
+ any {
215
+ [type.googleapis.com/protobuf_mutator.Msg] {
216
+ optional_uint32: 440
217
+ optional_uint64: 1559
218
+ optional_sint32: 440615
219
+ optional_string: "XYZ"
220
+ optional_enum: ENUM_4
221
+ }
222
+ }
223
+ )" ;
224
+
179
225
const char kRepeatedNestedFields [] = R"(
180
226
optional_int32: 123
181
227
optional_msg {
@@ -214,6 +260,39 @@ const char kRepeatedNestedFields[] = R"(
214
260
}
215
261
)" ;
216
262
263
+ const char kRepeatedInAnyFields [] = R"(
264
+ any {
265
+ [type.googleapis.com/protobuf_mutator.Msg] {
266
+ repeated_double: 1.931778501556e-31
267
+ repeated_double: 1.26685288449177e-31
268
+ repeated_float: 4.739759e-41
269
+ repeated_float: 5.98038e-39
270
+ repeated_int32: 400201
271
+ repeated_int32: 673
272
+ repeated_int64: 104
273
+ repeated_int64: 52850685
274
+ }
275
+ }
276
+ )" ;
277
+
278
+ const char kOptionalInDeepAnyFields [] = R"(
279
+ any {
280
+ [type.googleapis.com/protobuf_mutator.Msg] {
281
+ any {
282
+ [type.googleapis.com/protobuf_mutator.Msg] {
283
+ any {
284
+ [type.googleapis.com/protobuf_mutator.Msg] {
285
+ optional_double: 1.9317850152856e-314
286
+ optional_sint64: 1743625000076
287
+ optional_string: "XYZ"
288
+ }
289
+ }
290
+ }
291
+ }
292
+ }
293
+ }
294
+ )" ;
295
+
217
296
class TestMutator : public Mutator {
218
297
public:
219
298
explicit TestMutator (bool keep_initialized,
@@ -286,6 +365,7 @@ std::vector<TestParams> GetFieldTestParams(
286
365
for (auto t : tests) {
287
366
auto lines = Split (t);
288
367
for (size_t i = 0 ; i != lines.size (); ++i) {
368
+ if (lines[i].find (" any {" ) != std::string::npos) break ;
289
369
if (lines[i].find (' :' ) != std::string::npos)
290
370
results.push_back (
291
371
std::make_tuple (&T::default_instance (), t, i, lines[i]));
@@ -301,6 +381,7 @@ std::vector<TestParams> GetMessageTestParams(
301
381
for (auto t : tests) {
302
382
auto lines = Split (t);
303
383
for (size_t i = 0 ; i != lines.size (); ++i) {
384
+ if (lines[i].find (" any {" ) != std::string::npos) break ;
304
385
if (lines[i].find (" {}" ) != std::string::npos)
305
386
results.push_back (
306
387
std::make_tuple (&T::default_instance (), t, i, lines[i]));
@@ -310,7 +391,7 @@ std::vector<TestParams> GetMessageTestParams(
310
391
}
311
392
312
393
bool Mutate (const protobuf::Message& from, const protobuf::Message& to,
313
- int iterations = 10000 ) {
394
+ int iterations = 100000 ) {
314
395
EXPECT_FALSE (MessageDifferencer::Equals (from, to));
315
396
ReducedTestMutator mutator;
316
397
std::unique_ptr<protobuf::Message> message (from.New ());
@@ -322,13 +403,13 @@ bool Mutate(const protobuf::Message& from, const protobuf::Message& to,
322
403
}
323
404
324
405
ADD_FAILURE () << " Failed to get from:\n "
325
- << SaveMessageAsText ( from) << " \n to:\n "
326
- << SaveMessageAsText (to );
406
+ << from. DebugString ( ) << " \n to:\n "
407
+ << to. DebugString ( );
327
408
return false ;
328
409
}
329
410
330
411
bool CrossOver (const protobuf::Message& from, const protobuf::Message& with,
331
- const protobuf::Message& to, int iterations = 10000 ) {
412
+ const protobuf::Message& to, int iterations = 100000 ) {
332
413
EXPECT_FALSE (MessageDifferencer::Equals (from, to));
333
414
ReducedTestMutator mutator;
334
415
std::unique_ptr<protobuf::Message> message (from.New ());
@@ -401,8 +482,10 @@ class MutatorFieldInsDelTest : public MutatorTest {};
401
482
INSTANTIATE_TEST_SUITE_P (Proto2, MutatorFieldInsDelTest,
402
483
ValuesIn (GetFieldTestParams<Msg>(
403
484
{kRequiredFields , kOptionalFields , kRepeatedFields ,
404
- kRequiredNestedFields , kOptionalNestedFields ,
405
- kRepeatedNestedFields })));
485
+ kRequiredNestedFields , kRequiredInAnyFields ,
486
+ kOptionalNestedFields , kOptionalInAnyFields ,
487
+ kRepeatedNestedFields , kRepeatedInAnyFields ,
488
+ kOptionalInDeepAnyFields })));
406
489
407
490
TEST_P (MutatorFieldInsDelTest, DeleteField) {
408
491
LoadMessage (m1_.get ());
@@ -424,12 +507,16 @@ class MutatorFieldTest : public MutatorTest {
424
507
INSTANTIATE_TEST_SUITE_P (Proto2, MutatorFieldTest,
425
508
ValuesIn (GetFieldTestParams<Msg>(
426
509
{kRequiredFields , kOptionalFields , kRepeatedFields ,
427
- kRequiredNestedFields , kOptionalNestedFields ,
428
- kRepeatedNestedFields })));
510
+ kRequiredNestedFields , kRequiredInAnyFields ,
511
+ kOptionalNestedFields , kOptionalInAnyFields ,
512
+ kRepeatedNestedFields , kRepeatedInAnyFields ,
513
+ kOptionalInDeepAnyFields })));
429
514
INSTANTIATE_TEST_SUITE_P (Proto3, MutatorFieldTest,
430
515
ValuesIn (GetFieldTestParams<Msg3>(
431
516
{kOptionalFields , kRepeatedFields ,
432
- kOptionalNestedFields , kRepeatedNestedFields })));
517
+ kOptionalNestedFields , kOptionalInAnyFields ,
518
+ kRepeatedNestedFields , kRepeatedInAnyFields ,
519
+ kOptionalInDeepAnyFields })));
433
520
434
521
TEST_P (MutatorFieldTest, Initialized) {
435
522
LoadWithoutLine (m1_.get ());
0 commit comments