Imported Upstream version 3.8.0
[platform/upstream/protobuf.git] / src / google / protobuf / proto3_arena_unittest.cc
index dac7378..d4b0135 100644 (file)
@@ -28,8 +28,8 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#include <string>
 #include <memory>
+#include <string>
 #include <vector>
 
 #include <google/protobuf/test_util.h>
@@ -39,9 +39,9 @@
 #include <google/protobuf/testing/googletest.h>
 #include <gtest/gtest.h>
 
-namespace google {
 using proto3_arena_unittest::TestAllTypes;
 
+namespace google {
 namespace protobuf {
 namespace {
 // We selectively set/check a few representative fields rather than all fields
@@ -54,8 +54,7 @@ void SetAllFields(TestAllTypes* m) {
   m->mutable_optional_foreign_message()->set_c(43);
   m->set_optional_nested_enum(
       proto3_arena_unittest::TestAllTypes_NestedEnum_BAZ);
-  m->set_optional_foreign_enum(
-      proto3_arena_unittest::FOREIGN_BAZ);
+  m->set_optional_foreign_enum(proto3_arena_unittest::FOREIGN_BAZ);
   m->mutable_optional_lazy_message()->set_bb(45);
   m->add_repeated_int32(100);
   m->add_repeated_string("asdf");
@@ -64,8 +63,7 @@ void SetAllFields(TestAllTypes* m) {
   m->add_repeated_foreign_message()->set_c(47);
   m->add_repeated_nested_enum(
       proto3_arena_unittest::TestAllTypes_NestedEnum_BAZ);
-  m->add_repeated_foreign_enum(
-      proto3_arena_unittest::FOREIGN_BAZ);
+  m->add_repeated_foreign_enum(proto3_arena_unittest::FOREIGN_BAZ);
   m->add_repeated_lazy_message()->set_bb(49);
 
   m->set_oneof_uint32(1);
@@ -83,8 +81,7 @@ void ExpectAllFieldsSet(const TestAllTypes& m) {
   EXPECT_EQ(43, m.optional_foreign_message().c());
   EXPECT_EQ(proto3_arena_unittest::TestAllTypes_NestedEnum_BAZ,
             m.optional_nested_enum());
-  EXPECT_EQ(proto3_arena_unittest::FOREIGN_BAZ,
-            m.optional_foreign_enum());
+  EXPECT_EQ(proto3_arena_unittest::FOREIGN_BAZ, m.optional_foreign_enum());
   EXPECT_EQ(true, m.has_optional_lazy_message());
   EXPECT_EQ(45, m.optional_lazy_message().bb());
 
@@ -102,8 +99,7 @@ void ExpectAllFieldsSet(const TestAllTypes& m) {
   EXPECT_EQ(proto3_arena_unittest::TestAllTypes_NestedEnum_BAZ,
             m.repeated_nested_enum(0));
   EXPECT_EQ(1, m.repeated_foreign_enum_size());
-  EXPECT_EQ(proto3_arena_unittest::FOREIGN_BAZ,
-            m.repeated_foreign_enum(0));
+  EXPECT_EQ(proto3_arena_unittest::FOREIGN_BAZ, m.repeated_foreign_enum(0));
   EXPECT_EQ(1, m.repeated_lazy_message_size());
   EXPECT_EQ(49, m.repeated_lazy_message(0).bb());
 
@@ -126,30 +122,7 @@ TEST(Proto3ArenaTest, Parsing) {
   ExpectAllFieldsSet(*arena_message);
 }
 
-TEST(Proto3ArenaTest, UnknownFieldsDefaultDrop) {
-  ::google::protobuf::internal::SetProto3PreserveUnknownsDefault(false);
-  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);
-  // But the change will never will serialized back.
-  ASSERT_EQ(original.ByteSize(), arena_message->ByteSize());
-  ASSERT_TRUE(
-      arena_message->GetReflection()->GetUnknownFields(*arena_message).empty());
-}
-
-TEST(Proto3ArenaTest, UnknownFieldsDefaultPreserve) {
-  ::google::protobuf::internal::SetProto3PreserveUnknownsDefault(true);
+TEST(Proto3ArenaTest, UnknownFields) {
   TestAllTypes original;
   SetAllFields(&original);
 
@@ -184,7 +157,7 @@ TEST(Proto3ArenaTest, Swap) {
 
 TEST(Proto3ArenaTest, SetAllocatedMessage) {
   Arena arena;
-  TestAllTypes *arena_message = Arena::CreateMessage<TestAllTypes>(&arena);
+  TestAllTypesarena_message = Arena::CreateMessage<TestAllTypes>(&arena);
   TestAllTypes::NestedMessage* nested = new TestAllTypes::NestedMessage;
   nested->set_bb(118);
   arena_message->set_allocated_optional_nested_message(nested);
@@ -201,7 +174,7 @@ TEST(Proto3ArenaTest, ReleaseMessage) {
 }
 
 TEST(Proto3ArenaTest, MessageFieldClear) {
-  // GitHub issue #310: https://github.com/google/protobuf/issues/310
+  // GitHub issue #310: https://github.com/protocolbuffers/protobuf/issues/310
   Arena arena;
   TestAllTypes* arena_message = Arena::CreateMessage<TestAllTypes>(&arena);
   arena_message->mutable_optional_nested_message()->set_bb(118);
@@ -215,8 +188,8 @@ TEST(Proto3ArenaTest, MessageFieldClearViaReflection) {
   TestAllTypes* message = Arena::CreateMessage<TestAllTypes>(&arena);
   const Reflection* r = message->GetReflection();
   const Descriptor* d = message->GetDescriptor();
-  const FieldDescriptor* msg_field = d->FindFieldByName(
-      "optional_nested_message");
+  const FieldDescriptor* msg_field =
+      d->FindFieldByName("optional_nested_message");
 
   message->mutable_optional_nested_message()->set_bb(1);
   r->ClearField(message, msg_field);