// (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>
#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
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");
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);
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());
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());
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);
TEST(Proto3ArenaTest, SetAllocatedMessage) {
Arena arena;
- TestAllTypes *arena_message = Arena::CreateMessage<TestAllTypes>(&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);
}
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);
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);