| Index: third_party/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc b/third_party/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc
|
| index 85ebdef1fc926aa08db91817c90f0981fd614ccc..e2c6cdc0bbc7ca6079331e35a2c3059831c24865 100644
|
| --- a/third_party/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc
|
| @@ -222,7 +222,7 @@ TEST(GeneratedMessageReflectionTest, SwapFields) {
|
| message2.set_optional_string("hello");
|
| message2.mutable_repeated_int64()->Add(30);
|
|
|
| - vector<const FieldDescriptor*> fields;
|
| + std::vector<const FieldDescriptor*> fields;
|
| const Descriptor* descriptor = message1.GetDescriptor();
|
| fields.push_back(descriptor->FindFieldByName("optional_double"));
|
| fields.push_back(descriptor->FindFieldByName("repeated_int32"));
|
| @@ -255,7 +255,7 @@ TEST(GeneratedMessageReflectionTest, SwapFieldsAll) {
|
|
|
| TestUtil::SetAllFields(&message2);
|
|
|
| - vector<const FieldDescriptor*> fields;
|
| + std::vector<const FieldDescriptor*> fields;
|
| const Reflection* reflection = message1.GetReflection();
|
| reflection->ListFields(message2, &fields);
|
| reflection->SwapFields(&message1, &message2, fields);
|
| @@ -270,7 +270,7 @@ TEST(GeneratedMessageReflectionTest, SwapFieldsAllExtension) {
|
|
|
| TestUtil::SetAllExtensions(&message1);
|
|
|
| - vector<const FieldDescriptor*> fields;
|
| + std::vector<const FieldDescriptor*> fields;
|
| const Reflection* reflection = message1.GetReflection();
|
| reflection->ListFields(message1, &fields);
|
| reflection->SwapFields(&message1, &message2, fields);
|
| @@ -306,7 +306,7 @@ TEST(GeneratedMessageReflectionTest, SwapFieldsOneof) {
|
| unittest::TestOneof2 message1, message2;
|
| TestUtil::SetOneof1(&message1);
|
|
|
| - vector<const FieldDescriptor*> fields;
|
| + std::vector<const FieldDescriptor*> fields;
|
| const Descriptor* descriptor = message1.GetDescriptor();
|
| for (int i = 0; i < descriptor->field_count(); i++) {
|
| fields.push_back(descriptor->field(i));
|
| @@ -608,7 +608,7 @@ TEST(GeneratedMessageReflectionTest, ListFieldsOneOf) {
|
| TestUtil::SetOneof1(&message);
|
|
|
| const Reflection* reflection = message.GetReflection();
|
| - vector<const FieldDescriptor*> fields;
|
| + std::vector<const FieldDescriptor*> fields;
|
| reflection->ListFields(message, &fields);
|
| EXPECT_EQ(4, fields.size());
|
| }
|
| @@ -795,6 +795,73 @@ TEST(GeneratedMessageReflectionTest, ReleaseOneofMessageTest) {
|
| EXPECT_TRUE(released == NULL);
|
| }
|
|
|
| +TEST(GeneratedMessageReflectionTest, ArenaReleaseMessageTest) {
|
| + ::google::protobuf::Arena arena;
|
| + unittest::TestAllTypes* message =
|
| + ::google::protobuf::Arena::CreateMessage<unittest::TestAllTypes>(&arena);
|
| + TestUtil::ReflectionTester reflection_tester(
|
| + unittest::TestAllTypes::descriptor());
|
| +
|
| + // When nothing is set, we expect all released messages to be NULL.
|
| + reflection_tester.ExpectMessagesReleasedViaReflection(
|
| + message, TestUtil::ReflectionTester::IS_NULL);
|
| +
|
| + // After fields are set we should get non-NULL releases.
|
| + reflection_tester.SetAllFieldsViaReflection(message);
|
| + reflection_tester.ExpectMessagesReleasedViaReflection(
|
| + message, TestUtil::ReflectionTester::NOT_NULL);
|
| +
|
| + // After Clear() we may or may not get a message from ReleaseMessage().
|
| + // This is implementation specific.
|
| + reflection_tester.SetAllFieldsViaReflection(message);
|
| + message->Clear();
|
| + reflection_tester.ExpectMessagesReleasedViaReflection(
|
| + message, TestUtil::ReflectionTester::CAN_BE_NULL);
|
| +}
|
| +
|
| +TEST(GeneratedMessageReflectionTest, ArenaReleaseExtensionMessageTest) {
|
| + ::google::protobuf::Arena arena;
|
| + unittest::TestAllExtensions* message =
|
| + ::google::protobuf::Arena::CreateMessage<unittest::TestAllExtensions>(&arena);
|
| + TestUtil::ReflectionTester reflection_tester(
|
| + unittest::TestAllExtensions::descriptor());
|
| +
|
| + // When nothing is set, we expect all released messages to be NULL.
|
| + reflection_tester.ExpectMessagesReleasedViaReflection(
|
| + message, TestUtil::ReflectionTester::IS_NULL);
|
| +
|
| + // After fields are set we should get non-NULL releases.
|
| + reflection_tester.SetAllFieldsViaReflection(message);
|
| + reflection_tester.ExpectMessagesReleasedViaReflection(
|
| + message, TestUtil::ReflectionTester::NOT_NULL);
|
| +
|
| + // After Clear() we may or may not get a message from ReleaseMessage().
|
| + // This is implementation specific.
|
| + reflection_tester.SetAllFieldsViaReflection(message);
|
| + message->Clear();
|
| + reflection_tester.ExpectMessagesReleasedViaReflection(
|
| + message, TestUtil::ReflectionTester::CAN_BE_NULL);
|
| +}
|
| +
|
| +TEST(GeneratedMessageReflectionTest, ArenaReleaseOneofMessageTest) {
|
| + ::google::protobuf::Arena arena;
|
| + unittest::TestOneof2* message =
|
| + ::google::protobuf::Arena::CreateMessage<unittest::TestOneof2>(&arena);
|
| + TestUtil::ReflectionTester::SetOneofViaReflection(message);
|
| +
|
| + const Descriptor* descriptor = unittest::TestOneof2::descriptor();
|
| + const Reflection* reflection = message->GetReflection();
|
| + Message* released = reflection->ReleaseMessage(
|
| + message, descriptor->FindFieldByName("foo_lazy_message"));
|
| +
|
| + EXPECT_TRUE(released != NULL);
|
| + delete released;
|
| +
|
| + released = reflection->ReleaseMessage(
|
| + message, descriptor->FindFieldByName("foo_lazy_message"));
|
| + EXPECT_TRUE(released == NULL);
|
| +}
|
| +
|
| #ifdef PROTOBUF_HAS_DEATH_TEST
|
|
|
| TEST(GeneratedMessageReflectionTest, UsageErrors) {
|
|
|