| Index: third_party/protobuf/src/google/protobuf/lite_unittest.cc
|
| ===================================================================
|
| --- third_party/protobuf/src/google/protobuf/lite_unittest.cc (revision 216642)
|
| +++ third_party/protobuf/src/google/protobuf/lite_unittest.cc (working copy)
|
| @@ -33,11 +33,32 @@
|
| #include <string>
|
| #include <iostream>
|
|
|
| +#include <google/protobuf/stubs/common.h>
|
| #include <google/protobuf/test_util_lite.h>
|
| -#include <google/protobuf/stubs/common.h>
|
| +#include <google/protobuf/unittest_lite.pb.h>
|
|
|
| using namespace std;
|
|
|
| +namespace {
|
| +// Helper methods to test parsing merge behavior.
|
| +void ExpectMessageMerged(const google::protobuf::unittest::TestAllTypesLite& message) {
|
| + GOOGLE_CHECK(message.optional_int32() == 3);
|
| + GOOGLE_CHECK(message.optional_int64() == 2);
|
| + GOOGLE_CHECK(message.optional_string() == "hello");
|
| +}
|
| +
|
| +void AssignParsingMergeMessages(
|
| + google::protobuf::unittest::TestAllTypesLite* msg1,
|
| + google::protobuf::unittest::TestAllTypesLite* msg2,
|
| + google::protobuf::unittest::TestAllTypesLite* msg3) {
|
| + msg1->set_optional_int32(1);
|
| + msg2->set_optional_int64(2);
|
| + msg3->set_optional_int32(3);
|
| + msg3->set_optional_string("hello");
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| int main(int argc, char* argv[]) {
|
| string data, packed_data;
|
|
|
| @@ -107,6 +128,58 @@
|
| google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message);
|
| }
|
|
|
| + {
|
| + // Test that if an optional or required message/group field appears multiple
|
| + // times in the input, they need to be merged.
|
| + google::protobuf::unittest::TestParsingMergeLite::RepeatedFieldsGenerator generator;
|
| + google::protobuf::unittest::TestAllTypesLite* msg1;
|
| + google::protobuf::unittest::TestAllTypesLite* msg2;
|
| + google::protobuf::unittest::TestAllTypesLite* msg3;
|
| +
|
| +#define ASSIGN_REPEATED_FIELD(FIELD) \
|
| + msg1 = generator.add_##FIELD(); \
|
| + msg2 = generator.add_##FIELD(); \
|
| + msg3 = generator.add_##FIELD(); \
|
| + AssignParsingMergeMessages(msg1, msg2, msg3)
|
| +
|
| + ASSIGN_REPEATED_FIELD(field1);
|
| + ASSIGN_REPEATED_FIELD(field2);
|
| + ASSIGN_REPEATED_FIELD(field3);
|
| + ASSIGN_REPEATED_FIELD(ext1);
|
| + ASSIGN_REPEATED_FIELD(ext2);
|
| +
|
| +#undef ASSIGN_REPEATED_FIELD
|
| +#define ASSIGN_REPEATED_GROUP(FIELD) \
|
| + msg1 = generator.add_##FIELD()->mutable_field1(); \
|
| + msg2 = generator.add_##FIELD()->mutable_field1(); \
|
| + msg3 = generator.add_##FIELD()->mutable_field1(); \
|
| + AssignParsingMergeMessages(msg1, msg2, msg3)
|
| +
|
| + ASSIGN_REPEATED_GROUP(group1);
|
| + ASSIGN_REPEATED_GROUP(group2);
|
| +
|
| +#undef ASSIGN_REPEATED_GROUP
|
| +
|
| + string buffer;
|
| + generator.SerializeToString(&buffer);
|
| + google::protobuf::unittest::TestParsingMergeLite parsing_merge;
|
| + parsing_merge.ParseFromString(buffer);
|
| +
|
| + // Required and optional fields should be merged.
|
| + ExpectMessageMerged(parsing_merge.required_all_types());
|
| + ExpectMessageMerged(parsing_merge.optional_all_types());
|
| + ExpectMessageMerged(
|
| + parsing_merge.optionalgroup().optional_group_all_types());
|
| + ExpectMessageMerged(parsing_merge.GetExtension(
|
| + google::protobuf::unittest::TestParsingMergeLite::optional_ext));
|
| +
|
| + // Repeated fields should not be merged.
|
| + GOOGLE_CHECK(parsing_merge.repeated_all_types_size() == 3);
|
| + GOOGLE_CHECK(parsing_merge.repeatedgroup_size() == 3);
|
| + GOOGLE_CHECK(parsing_merge.ExtensionSize(
|
| + google::protobuf::unittest::TestParsingMergeLite::repeated_ext) == 3);
|
| + }
|
| +
|
| cout << "PASS" << endl;
|
| return 0;
|
| }
|
|
|