diff options
author | jieluo@google.com <jieluo@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2014-07-18 00:47:59 +0000 |
---|---|---|
committer | jieluo@google.com <jieluo@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2014-07-18 00:47:59 +0000 |
commit | 4de8f55113007fdc8e34107950e605fc0209d465 (patch) | |
tree | 92b7da8757a7740d9e1f2d3ead233542947d8c8c /src/google/protobuf/reflection_ops_unittest.cc | |
parent | c5553a3d18f80132b9079c5504bc0aa1f7f950a0 (diff) | |
download | protobuf-4de8f55113007fdc8e34107950e605fc0209d465.tar.gz protobuf-4de8f55113007fdc8e34107950e605fc0209d465.tar.bz2 protobuf-4de8f55113007fdc8e34107950e605fc0209d465.zip |
down integrate to svn
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 |