| Index: third_party/protobuf/src/google/protobuf/reflection_ops_unittest.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/reflection_ops_unittest.cc b/third_party/protobuf/src/google/protobuf/reflection_ops_unittest.cc
|
| index 29229b5a7e40cb607759054f53b1379ea63e00cb..32740ea4696579b59e70624e3cf31f5941b2c85c 100644
|
| --- a/third_party/protobuf/src/google/protobuf/reflection_ops_unittest.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/reflection_ops_unittest.cc
|
| @@ -1,6 +1,6 @@
|
| // Protocol Buffers - Google's data interchange format
|
| // Copyright 2008 Google Inc. All rights reserved.
|
| -// http://code.google.com/p/protobuf/
|
| +// https://developers.google.com/protocol-buffers/
|
| //
|
| // Redistribution and use in source and binary forms, with or without
|
| // modification, are permitted provided that the following conditions are
|
| @@ -78,6 +78,18 @@ TEST(ReflectionOpsTest, CopyExtensions) {
|
| TestUtil::ExpectAllExtensionsSet(message2);
|
| }
|
|
|
| +TEST(ReflectionOpsTest, CopyOneof) {
|
| + unittest::TestOneof2 message, message2;
|
| + TestUtil::SetOneof1(&message);
|
| + ReflectionOps::Copy(message, &message2);
|
| + TestUtil::ExpectOneofSet1(message2);
|
| +
|
| + TestUtil::SetOneof2(&message);
|
| + TestUtil::ExpectOneofSet2(message);
|
| + ReflectionOps::Copy(message, &message2);
|
| + TestUtil::ExpectOneofSet2(message2);
|
| +}
|
| +
|
| TEST(ReflectionOpsTest, Merge) {
|
| // Note: Copy is implemented in terms of Merge() so technically the Copy
|
| // test already tested most of this.
|
| @@ -152,6 +164,24 @@ TEST(ReflectionOpsTest, MergeUnknown) {
|
| EXPECT_EQ(2, message1.unknown_fields().field(1).varint());
|
| }
|
|
|
| +TEST(ReflectionOpsTest, MergeOneof) {
|
| + unittest::TestOneof2 message1, message2;
|
| + TestUtil::SetOneof1(&message1);
|
| +
|
| + // Merge to empty message
|
| + ReflectionOps::Merge(message1, &message2);
|
| + TestUtil::ExpectOneofSet1(message2);
|
| +
|
| + // Merge with the same oneof fields
|
| + ReflectionOps::Merge(message1, &message2);
|
| + TestUtil::ExpectOneofSet1(message2);
|
| +
|
| + // Merge with different oneof fields
|
| + TestUtil::SetOneof2(&message1);
|
| + ReflectionOps::Merge(message1, &message2);
|
| + TestUtil::ExpectOneofSet2(message2);
|
| +}
|
| +
|
| #ifdef PROTOBUF_HAS_DEATH_TEST
|
|
|
| TEST(ReflectionOpsTest, MergeFromSelf) {
|
| @@ -220,6 +250,23 @@ TEST(ReflectionOpsTest, ClearUnknown) {
|
| EXPECT_EQ(0, message.unknown_fields().field_count());
|
| }
|
|
|
| +TEST(ReflectionOpsTest, ClearOneof) {
|
| + unittest::TestOneof2 message;
|
| +
|
| + TestUtil::ExpectOneofClear(message);
|
| + TestUtil::SetOneof1(&message);
|
| + TestUtil::ExpectOneofSet1(message);
|
| + ReflectionOps::Clear(&message);
|
| + TestUtil::ExpectOneofClear(message);
|
| +
|
| + TestUtil::SetOneof1(&message);
|
| + TestUtil::ExpectOneofSet1(message);
|
| + TestUtil::SetOneof2(&message);
|
| + TestUtil::ExpectOneofSet2(message);
|
| + ReflectionOps::Clear(&message);
|
| + TestUtil::ExpectOneofClear(message);
|
| +}
|
| +
|
| TEST(ReflectionOpsTest, DiscardUnknownFields) {
|
| unittest::TestAllTypes message;
|
| TestUtil::SetAllFields(&message);
|
| @@ -354,10 +401,26 @@ TEST(ReflectionOpsTest, ExtensionIsInitialized) {
|
| EXPECT_TRUE(ReflectionOps::IsInitialized(message));
|
| }
|
|
|
| +TEST(ReflectionOpsTest, OneofIsInitialized) {
|
| + unittest::TestRequiredOneof message;
|
| + EXPECT_TRUE(ReflectionOps::IsInitialized(message));
|
| +
|
| + message.mutable_foo_message();
|
| + EXPECT_FALSE(ReflectionOps::IsInitialized(message));
|
| +
|
| + message.set_foo_int(1);
|
| + EXPECT_TRUE(ReflectionOps::IsInitialized(message));
|
| +
|
| + message.mutable_foo_message();
|
| + EXPECT_FALSE(ReflectionOps::IsInitialized(message));
|
| + message.mutable_foo_message()->set_required_double(0.1);
|
| + EXPECT_TRUE(ReflectionOps::IsInitialized(message));
|
| +}
|
| +
|
| static string FindInitializationErrors(const Message& message) {
|
| vector<string> errors;
|
| ReflectionOps::FindInitializationErrors(message, "", &errors);
|
| - return JoinStrings(errors, ",");
|
| + return Join(errors, ",");
|
| }
|
|
|
| TEST(ReflectionOpsTest, FindInitializationErrors) {
|
| @@ -399,6 +462,13 @@ TEST(ReflectionOpsTest, FindExtensionInitializationErrors) {
|
| FindInitializationErrors(message));
|
| }
|
|
|
| +TEST(ReflectionOpsTest, FindOneofInitializationErrors) {
|
| + unittest::TestRequiredOneof message;
|
| + message.mutable_foo_message();
|
| + EXPECT_EQ("foo_message.required_double",
|
| + FindInitializationErrors(message));
|
| +}
|
| +
|
| } // namespace
|
| } // namespace internal
|
| } // namespace protobuf
|
|
|