diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2017-07-18 15:38:30 -0700 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2017-07-18 15:38:30 -0700 |
commit | 09354db1434859a31a3c81abebcc4018d42f2715 (patch) | |
tree | b87c7cdc2255e6c8062ab92b4082665cd698d753 /src/google/protobuf/proto3_arena_unittest.cc | |
parent | 9053033a5076f82cf18b823c31f352e95e5bfd8d (diff) |
Merge from Google internal for 3.4 release
Diffstat (limited to 'src/google/protobuf/proto3_arena_unittest.cc')
-rw-r--r-- | src/google/protobuf/proto3_arena_unittest.cc | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/google/protobuf/proto3_arena_unittest.cc b/src/google/protobuf/proto3_arena_unittest.cc index 2838e0fc..3a0fb804 100644 --- a/src/google/protobuf/proto3_arena_unittest.cc +++ b/src/google/protobuf/proto3_arena_unittest.cc @@ -129,7 +129,8 @@ TEST(Proto3ArenaTest, Parsing) { ExpectAllFieldsSet(*arena_message); } -TEST(Proto3ArenaTest, UnknownFields) { +TEST(Proto3ArenaTest, UnknownFieldsDefaultDrop) { + ::google::protobuf::internal::SetProto3PreserveUnknownsDefault(false); TestAllTypes original; SetAllFields(&original); @@ -150,6 +151,28 @@ TEST(Proto3ArenaTest, UnknownFields) { arena_message->GetReflection()->GetUnknownFields(*arena_message).empty()); } +TEST(Proto3ArenaTest, UnknownFieldsDefaultPreserve) { + ::google::protobuf::internal::SetProto3PreserveUnknownsDefault(true); + TestAllTypes original; + SetAllFields(&original); + + Arena arena; + TestAllTypes* arena_message = Arena::CreateMessage<TestAllTypes>(&arena); + arena_message->ParseFromString(original.SerializeAsString()); + ExpectAllFieldsSet(*arena_message); + + // In proto3 we can still get a pointer to the UnknownFieldSet through + // reflection API. + UnknownFieldSet* unknown_fields = + arena_message->GetReflection()->MutableUnknownFields(arena_message); + // We can modify this UnknownFieldSet. + unknown_fields->AddVarint(1, 2); + // And the unknown fields should be changed. + ASSERT_NE(original.ByteSize(), arena_message->ByteSize()); + ASSERT_FALSE( + arena_message->GetReflection()->GetUnknownFields(*arena_message).empty()); +} + TEST(Proto3ArenaTest, Swap) { Arena arena1; Arena arena2; |