| Index: third_party/protobuf/src/google/protobuf/arena_unittest.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/arena_unittest.cc b/third_party/protobuf/src/google/protobuf/arena_unittest.cc
|
| index ab25ffe1ad967fd50f0727986b4040526db3f015..4f9571dbffc8abc7880b1be0bb6b86a465b8df66 100644
|
| --- a/third_party/protobuf/src/google/protobuf/arena_unittest.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/arena_unittest.cc
|
| @@ -42,7 +42,6 @@
|
|
|
| #include <google/protobuf/stubs/logging.h>
|
| #include <google/protobuf/stubs/common.h>
|
| -#include <google/protobuf/stubs/scoped_ptr.h>
|
| #include <google/protobuf/arena_test_util.h>
|
| #include <google/protobuf/test_util.h>
|
| #include <google/protobuf/unittest.pb.h>
|
| @@ -152,8 +151,6 @@ class MustBeConstructedWithOneThroughEight {
|
| GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MustBeConstructedWithOneThroughEight);
|
| };
|
|
|
| -} // namespace
|
| -
|
| TEST(ArenaTest, ArenaConstructable) {
|
| EXPECT_TRUE(Arena::is_arena_constructable<TestAllTypes>::type::value);
|
| EXPECT_TRUE(Arena::is_arena_constructable<const TestAllTypes>::type::value);
|
| @@ -252,7 +249,7 @@ TEST(ArenaTest, Parsing) {
|
| arena_message->ParseFromString(original.SerializeAsString());
|
| TestUtil::ExpectAllFieldsSet(*arena_message);
|
|
|
| - // Test that string fields have null terminator bytes (earlier bug).
|
| + // Test that string fields have nul terminator bytes (earlier bug).
|
| EXPECT_EQ(strlen(original.optional_string().c_str()),
|
| strlen(arena_message->optional_string().c_str()));
|
| }
|
| @@ -894,6 +891,24 @@ TEST(ArenaTest, UnsafeArenaRelease) {
|
| delete s;
|
| }
|
|
|
| +TEST(ArenaTest, OneofMerge) {
|
| + Arena arena;
|
| + TestAllTypes* message0 = Arena::CreateMessage<TestAllTypes>(&arena);
|
| + TestAllTypes* message1 = Arena::CreateMessage<TestAllTypes>(&arena);
|
| +
|
| + message0->unsafe_arena_set_allocated_oneof_string(new string("x"));
|
| + ASSERT_TRUE(message0->has_oneof_string());
|
| + message1->unsafe_arena_set_allocated_oneof_string(new string("y"));
|
| + ASSERT_TRUE(message1->has_oneof_string());
|
| + EXPECT_EQ("x", message0->oneof_string());
|
| + EXPECT_EQ("y", message1->oneof_string());
|
| + message0->MergeFrom(*message1);
|
| + EXPECT_EQ("y", message0->oneof_string());
|
| + EXPECT_EQ("y", message1->oneof_string());
|
| + delete message0->unsafe_arena_release_oneof_string();
|
| + delete message1->unsafe_arena_release_oneof_string();
|
| +}
|
| +
|
| TEST(ArenaTest, ArenaOneofReflection) {
|
| Arena arena;
|
| TestAllTypes* message = Arena::CreateMessage<TestAllTypes>(&arena);
|
| @@ -924,7 +939,6 @@ TEST(ArenaTest, ArenaOneofReflection) {
|
| delete submsg;
|
| }
|
|
|
| -namespace {
|
| void TestSwapRepeatedField(Arena* arena1, Arena* arena2) {
|
| // Test "safe" (copying) semantics for direct Swap() on RepeatedPtrField
|
| // between arenas.
|
| @@ -963,7 +977,6 @@ void TestSwapRepeatedField(Arena* arena1, Arena* arena2) {
|
| EXPECT_EQ(i, field2.Get(i).optional_int32());
|
| }
|
| }
|
| -} // namespace
|
|
|
| TEST(ArenaTest, SwapRepeatedField) {
|
| Arena arena;
|
| @@ -1105,8 +1118,6 @@ TEST(ArenaTest, MutableMessageReflection) {
|
| #endif // !GOOGLE_PROTOBUF_NO_RTTI
|
|
|
|
|
| -namespace {
|
| -
|
| void FillArenaAwareFields(TestAllTypes* message) {
|
| string test_string = "hello world";
|
| message->set_optional_int32(42);
|
| @@ -1125,8 +1136,6 @@ void FillArenaAwareFields(TestAllTypes* message) {
|
| message->mutable_optional_lazy_message()->set_bb(42);
|
| }
|
|
|
| -}
|
| -
|
| // Test: no allocations occur on heap while touching all supported field types.
|
| TEST(ArenaTest, NoHeapAllocationsTest) {
|
| // Allocate a large initial block to avoid mallocs during hooked test.
|
| @@ -1145,6 +1154,13 @@ TEST(ArenaTest, NoHeapAllocationsTest) {
|
| arena.Reset();
|
| }
|
|
|
| +TEST(ArenaTest, ParseCorruptedString) {
|
| + TestAllTypes message;
|
| + TestUtil::SetAllFields(&message);
|
| + TestParseCorruptedString<TestAllTypes, true>(message);
|
| + TestParseCorruptedString<TestAllTypes, false>(message);
|
| +}
|
| +
|
| #ifndef GOOGLE_PROTOBUF_NO_RTTI
|
| // Test construction on an arena via generic MessageLite interface. We should be
|
| // able to successfully deserialize on the arena without incurring heap
|
| @@ -1197,9 +1213,7 @@ TEST(ArenaTest, RepeatedFieldWithNonPODType) {
|
| }
|
|
|
| // Align n to next multiple of 8
|
| -namespace {
|
| uint64 Align8(uint64 n) { return (n + 7) & -8; }
|
| -} // namespace
|
|
|
| TEST(ArenaTest, SpaceAllocated_and_Used) {
|
| ArenaOptions options;
|
| @@ -1250,6 +1264,22 @@ TEST(ArenaTest, Alignment) {
|
| }
|
| }
|
|
|
| +TEST(ArenaTest, BlockSizeSmallerThanAllocation) {
|
| + for (size_t i = 0; i <= 8; ++i) {
|
| + ::google::protobuf::ArenaOptions opt;
|
| + opt.start_block_size = opt.max_block_size = i;
|
| + ::google::protobuf::Arena arena(opt);
|
| +
|
| + *::google::protobuf::Arena::Create<int64>(&arena) = 42;
|
| + EXPECT_GE(arena.SpaceAllocated(), 8);
|
| + EXPECT_EQ(8, arena.SpaceUsed());
|
| +
|
| + *::google::protobuf::Arena::Create<int64>(&arena) = 42;
|
| + EXPECT_GE(arena.SpaceAllocated(), 16);
|
| + EXPECT_EQ(16, arena.SpaceUsed());
|
| + }
|
| +}
|
| +
|
| TEST(ArenaTest, GetArenaShouldReturnTheArenaForArenaAllocatedMessages) {
|
| ::google::protobuf::Arena arena;
|
| ArenaMessage* message = Arena::CreateMessage<ArenaMessage>(&arena);
|
| @@ -1350,5 +1380,7 @@ TEST(ArenaTest, ArenaHooksSanity) {
|
| EXPECT_EQ(1, ArenaHooksTestUtil::num_destruct);
|
| }
|
|
|
| +
|
| +} // namespace
|
| } // namespace protobuf
|
| } // namespace google
|
|
|