Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: third_party/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Update to new HEAD (b7632464b4) + restore GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 788
789 EXPECT_TRUE(released != NULL); 789 EXPECT_TRUE(released != NULL);
790 EXPECT_EQ(&sub_message, released); 790 EXPECT_EQ(&sub_message, released);
791 delete released; 791 delete released;
792 792
793 released = reflection->ReleaseMessage( 793 released = reflection->ReleaseMessage(
794 &message, descriptor->FindFieldByName("foo_lazy_message")); 794 &message, descriptor->FindFieldByName("foo_lazy_message"));
795 EXPECT_TRUE(released == NULL); 795 EXPECT_TRUE(released == NULL);
796 } 796 }
797 797
798 TEST(GeneratedMessageReflectionTest, ArenaReleaseMessageTest) {
799 ::google::protobuf::Arena arena;
800 unittest::TestAllTypes* message =
801 ::google::protobuf::Arena::CreateMessage<unittest::TestAllTypes>(&arena);
802 TestUtil::ReflectionTester reflection_tester(
803 unittest::TestAllTypes::descriptor());
804
805 // When nothing is set, we expect all released messages to be NULL.
806 reflection_tester.ExpectMessagesReleasedViaReflection(
807 message, TestUtil::ReflectionTester::IS_NULL);
808
809 // After fields are set we should get non-NULL releases.
810 reflection_tester.SetAllFieldsViaReflection(message);
811 reflection_tester.ExpectMessagesReleasedViaReflection(
812 message, TestUtil::ReflectionTester::NOT_NULL);
813
814 // After Clear() we may or may not get a message from ReleaseMessage().
815 // This is implementation specific.
816 reflection_tester.SetAllFieldsViaReflection(message);
817 message->Clear();
818 reflection_tester.ExpectMessagesReleasedViaReflection(
819 message, TestUtil::ReflectionTester::CAN_BE_NULL);
820 }
821
822 TEST(GeneratedMessageReflectionTest, ArenaReleaseExtensionMessageTest) {
823 ::google::protobuf::Arena arena;
824 unittest::TestAllExtensions* message =
825 ::google::protobuf::Arena::CreateMessage<unittest::TestAllExtensions>(&are na);
826 TestUtil::ReflectionTester reflection_tester(
827 unittest::TestAllExtensions::descriptor());
828
829 // When nothing is set, we expect all released messages to be NULL.
830 reflection_tester.ExpectMessagesReleasedViaReflection(
831 message, TestUtil::ReflectionTester::IS_NULL);
832
833 // After fields are set we should get non-NULL releases.
834 reflection_tester.SetAllFieldsViaReflection(message);
835 reflection_tester.ExpectMessagesReleasedViaReflection(
836 message, TestUtil::ReflectionTester::NOT_NULL);
837
838 // After Clear() we may or may not get a message from ReleaseMessage().
839 // This is implementation specific.
840 reflection_tester.SetAllFieldsViaReflection(message);
841 message->Clear();
842 reflection_tester.ExpectMessagesReleasedViaReflection(
843 message, TestUtil::ReflectionTester::CAN_BE_NULL);
844 }
845
846 TEST(GeneratedMessageReflectionTest, ArenaReleaseOneofMessageTest) {
847 ::google::protobuf::Arena arena;
848 unittest::TestOneof2* message =
849 ::google::protobuf::Arena::CreateMessage<unittest::TestOneof2>(&arena);
850 TestUtil::ReflectionTester::SetOneofViaReflection(message);
851
852 const Descriptor* descriptor = unittest::TestOneof2::descriptor();
853 const Reflection* reflection = message->GetReflection();
854 Message* released = reflection->ReleaseMessage(
855 message, descriptor->FindFieldByName("foo_lazy_message"));
856
857 EXPECT_TRUE(released != NULL);
858 delete released;
859
860 released = reflection->ReleaseMessage(
861 message, descriptor->FindFieldByName("foo_lazy_message"));
862 EXPECT_TRUE(released == NULL);
863 }
864
798 #ifdef PROTOBUF_HAS_DEATH_TEST 865 #ifdef PROTOBUF_HAS_DEATH_TEST
799 866
800 TEST(GeneratedMessageReflectionTest, UsageErrors) { 867 TEST(GeneratedMessageReflectionTest, UsageErrors) {
801 unittest::TestAllTypes message; 868 unittest::TestAllTypes message;
802 const Reflection* reflection = message.GetReflection(); 869 const Reflection* reflection = message.GetReflection();
803 const Descriptor* descriptor = message.GetDescriptor(); 870 const Descriptor* descriptor = message.GetDescriptor();
804 871
805 #define f(NAME) descriptor->FindFieldByName(NAME) 872 #define f(NAME) descriptor->FindFieldByName(NAME)
806 873
807 // Testing every single failure mode would be too much work. Let's just 874 // Testing every single failure mode would be too much work. Let's just
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 910
844 #undef f 911 #undef f
845 } 912 }
846 913
847 #endif // PROTOBUF_HAS_DEATH_TEST 914 #endif // PROTOBUF_HAS_DEATH_TEST
848 915
849 916
850 } // namespace 917 } // namespace
851 } // namespace protobuf 918 } // namespace protobuf
852 } // namespace google 919 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698