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

Unified Diff: third_party/protobuf/src/google/protobuf/proto3_lite_unittest.cc

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 7 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/src/google/protobuf/proto3_lite_unittest.cc
diff --git a/third_party/protobuf/src/google/protobuf/proto3_arena_unittest.cc b/third_party/protobuf/src/google/protobuf/proto3_lite_unittest.cc
similarity index 52%
copy from third_party/protobuf/src/google/protobuf/proto3_arena_unittest.cc
copy to third_party/protobuf/src/google/protobuf/proto3_lite_unittest.cc
index 2838e0fc644078c680032375cab424248f688e41..2e2beea909883dbede32653998ceea17a2cf6ef4 100644
--- a/third_party/protobuf/src/google/protobuf/proto3_arena_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/proto3_lite_unittest.cc
@@ -37,18 +37,18 @@
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
-#include <google/protobuf/unittest_proto3_arena.pb.h>
+#include <google/protobuf/unittest_proto3_lite.pb.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
namespace google {
-using proto3_arena_unittest::TestAllTypes;
+using proto3_lite_unittest::TestAllTypes;
namespace protobuf {
namespace {
// We selectively set/check a few representative fields rather than all fields
-// as this test is only expected to cover the basics of arena support.
+// as this test is only expected to cover the basics of lite support.
void SetAllFields(TestAllTypes* m) {
m->set_optional_int32(100);
m->set_optional_string("asdf");
@@ -56,9 +56,9 @@ void SetAllFields(TestAllTypes* m) {
m->mutable_optional_nested_message()->set_bb(42);
m->mutable_optional_foreign_message()->set_c(43);
m->set_optional_nested_enum(
- proto3_arena_unittest::TestAllTypes_NestedEnum_BAZ);
+ proto3_lite_unittest::TestAllTypes_NestedEnum_BAZ);
m->set_optional_foreign_enum(
- proto3_arena_unittest::FOREIGN_BAZ);
+ proto3_lite_unittest::FOREIGN_BAZ);
m->mutable_optional_lazy_message()->set_bb(45);
m->add_repeated_int32(100);
m->add_repeated_string("asdf");
@@ -66,9 +66,9 @@ void SetAllFields(TestAllTypes* m) {
m->add_repeated_nested_message()->set_bb(46);
m->add_repeated_foreign_message()->set_c(47);
m->add_repeated_nested_enum(
- proto3_arena_unittest::TestAllTypes_NestedEnum_BAZ);
+ proto3_lite_unittest::TestAllTypes_NestedEnum_BAZ);
m->add_repeated_foreign_enum(
- proto3_arena_unittest::FOREIGN_BAZ);
+ proto3_lite_unittest::FOREIGN_BAZ);
m->add_repeated_lazy_message()->set_bb(49);
m->set_oneof_uint32(1);
@@ -84,9 +84,9 @@ void ExpectAllFieldsSet(const TestAllTypes& m) {
EXPECT_EQ(42, m.optional_nested_message().bb());
EXPECT_EQ(true, m.has_optional_foreign_message());
EXPECT_EQ(43, m.optional_foreign_message().c());
- EXPECT_EQ(proto3_arena_unittest::TestAllTypes_NestedEnum_BAZ,
+ EXPECT_EQ(proto3_lite_unittest::TestAllTypes_NestedEnum_BAZ,
m.optional_nested_enum());
- EXPECT_EQ(proto3_arena_unittest::FOREIGN_BAZ,
+ EXPECT_EQ(proto3_lite_unittest::FOREIGN_BAZ,
m.optional_foreign_enum());
EXPECT_EQ(true, m.has_optional_lazy_message());
EXPECT_EQ(45, m.optional_lazy_message().bb());
@@ -102,106 +102,42 @@ void ExpectAllFieldsSet(const TestAllTypes& m) {
EXPECT_EQ(1, m.repeated_foreign_message_size());
EXPECT_EQ(47, m.repeated_foreign_message(0).c());
EXPECT_EQ(1, m.repeated_nested_enum_size());
- EXPECT_EQ(proto3_arena_unittest::TestAllTypes_NestedEnum_BAZ,
+ EXPECT_EQ(proto3_lite_unittest::TestAllTypes_NestedEnum_BAZ,
m.repeated_nested_enum(0));
EXPECT_EQ(1, m.repeated_foreign_enum_size());
- EXPECT_EQ(proto3_arena_unittest::FOREIGN_BAZ,
+ EXPECT_EQ(proto3_lite_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());
- EXPECT_EQ(proto3_arena_unittest::TestAllTypes::kOneofString,
+ EXPECT_EQ(proto3_lite_unittest::TestAllTypes::kOneofString,
m.oneof_field_case());
EXPECT_EQ("test", m.oneof_string());
}
-// In this file we only test some basic functionalities of arena support in
-// proto3 and expect the arena support to be fully tested in proto2 unittests
-// because proto3 shares most code with proto2.
+// In this file we only test some basic functionalities of in proto3 and expect
+// the rest is fully tested in proto2 unittests because proto3 shares most code
+// with proto2.
-TEST(Proto3ArenaTest, Parsing) {
+TEST(Proto3LiteTest, Parsing) {
TestAllTypes original;
SetAllFields(&original);
- Arena arena;
- TestAllTypes* arena_message = Arena::CreateMessage<TestAllTypes>(&arena);
- arena_message->ParseFromString(original.SerializeAsString());
- ExpectAllFieldsSet(*arena_message);
+ TestAllTypes msg;
+ msg.ParseFromString(original.SerializeAsString());
+ ExpectAllFieldsSet(msg);
}
-TEST(Proto3ArenaTest, UnknownFields) {
- 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, Swap) {
- Arena arena1;
- Arena arena2;
-
+TEST(Proto3LiteTest, Swap) {
// Test Swap().
- TestAllTypes* arena1_message = Arena::CreateMessage<TestAllTypes>(&arena1);
- TestAllTypes* arena2_message = Arena::CreateMessage<TestAllTypes>(&arena2);
- arena1_message->Swap(arena2_message);
- EXPECT_EQ(&arena1, arena1_message->GetArena());
- EXPECT_EQ(&arena2, arena2_message->GetArena());
-}
-
-TEST(Proto3ArenaTest, SetAllocatedMessage) {
- Arena arena;
- TestAllTypes *arena_message = Arena::CreateMessage<TestAllTypes>(&arena);
- TestAllTypes::NestedMessage* nested = new TestAllTypes::NestedMessage;
- nested->set_bb(118);
- arena_message->set_allocated_optional_nested_message(nested);
- EXPECT_EQ(118, arena_message->optional_nested_message().bb());
-}
-
-TEST(Proto3ArenaTest, ReleaseMessage) {
- Arena arena;
- TestAllTypes* arena_message = Arena::CreateMessage<TestAllTypes>(&arena);
- arena_message->mutable_optional_nested_message()->set_bb(118);
- google::protobuf::scoped_ptr<TestAllTypes::NestedMessage> nested(
- arena_message->release_optional_nested_message());
- EXPECT_EQ(118, nested->bb());
-}
-
-TEST(Proto3ArenaTest, MessageFieldClear) {
- // GitHub issue #310: https://github.com/google/protobuf/issues/310
- Arena arena;
- TestAllTypes* arena_message = Arena::CreateMessage<TestAllTypes>(&arena);
- arena_message->mutable_optional_nested_message()->set_bb(118);
- // This should not crash, but prior to the bugfix, it tried to use `operator
- // delete` the nested message (which is on the arena):
- arena_message->Clear();
-}
-
-TEST(Proto3ArenaTest, MessageFieldClearViaReflection) {
- Arena arena;
- 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");
-
- message->mutable_optional_nested_message()->set_bb(1);
- r->ClearField(message, msg_field);
- EXPECT_FALSE(message->has_optional_nested_message());
- EXPECT_EQ(0, message->optional_nested_message().bb());
+ TestAllTypes msg1;
+ TestAllTypes msg2;
+ msg1.set_optional_string("123");
+ msg2.set_optional_string("3456");
+ msg1.Swap(&msg2);
+ EXPECT_EQ("3456", msg1.optional_string());
+ EXPECT_EQ("123", msg2.optional_string());
+ EXPECT_EQ(msg1.ByteSize(), msg2.ByteSize() + 1);
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698