diff options
Diffstat (limited to 'src/google/protobuf/reflection_ops_unittest.cc')
-rw-r--r-- | src/google/protobuf/reflection_ops_unittest.cc | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/src/google/protobuf/reflection_ops_unittest.cc b/src/google/protobuf/reflection_ops_unittest.cc index 29229b5a..898c20c0 100644 --- a/src/google/protobuf/reflection_ops_unittest.cc +++ b/src/google/protobuf/reflection_ops_unittest.cc @@ -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 |