aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/lite_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/lite_unittest.cc')
-rw-r--r--src/google/protobuf/lite_unittest.cc401
1 files changed, 373 insertions, 28 deletions
diff --git a/src/google/protobuf/lite_unittest.cc b/src/google/protobuf/lite_unittest.cc
index d1948ab5..b42a7b14 100644
--- a/src/google/protobuf/lite_unittest.cc
+++ b/src/google/protobuf/lite_unittest.cc
@@ -36,24 +36,26 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/arena_test_util.h>
-#include <google/protobuf/map_lite_unittest.pb.h>
#include <google/protobuf/map_lite_test_util.h>
+#include <google/protobuf/map_lite_unittest.pb.h>
#include <google/protobuf/test_util_lite.h>
#include <google/protobuf/unittest_lite.pb.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/wire_format_lite_inl.h>
+#include <gtest/gtest.h>
+
#include <google/protobuf/stubs/strutil.h>
-using namespace std;
+using std::string;
namespace {
// Helper methods to test parsing merge behavior.
void ExpectMessageMerged(const google::protobuf::unittest::TestAllTypesLite& message) {
- GOOGLE_CHECK(message.optional_int32() == 3);
- GOOGLE_CHECK(message.optional_int64() == 2);
- GOOGLE_CHECK(message.optional_string() == "hello");
+ EXPECT_EQ(message.optional_int32(), 3);
+ EXPECT_EQ(message.optional_int64(), 2);
+ EXPECT_EQ(message.optional_string(), "hello");
}
void AssignParsingMergeMessages(
@@ -89,14 +91,8 @@ void SetSomeTypesInEmptyMessageUnknownFields(
} // namespace
-#define EXPECT_TRUE GOOGLE_CHECK
-#define ASSERT_TRUE GOOGLE_CHECK
-#define EXPECT_FALSE(COND) GOOGLE_CHECK(!(COND))
-#define EXPECT_EQ GOOGLE_CHECK_EQ
-#define ASSERT_EQ GOOGLE_CHECK_EQ
-
-int main(int argc, char* argv[]) {
- string data, data2, packed_data;
+TEST(Lite, AllLite1) {
+ string data;
{
protobuf_unittest::TestAllTypesLite message, message2, message3;
@@ -113,7 +109,10 @@ int main(int argc, char* argv[]) {
message.Clear();
google::protobuf::TestUtilLite::ExpectClear(message);
}
+}
+TEST(Lite, AllLite2) {
+ string data;
{
protobuf_unittest::TestAllExtensionsLite message, message2, message3;
google::protobuf::TestUtilLite::ExpectExtensionsClear(message);
@@ -129,6 +128,10 @@ int main(int argc, char* argv[]) {
message.Clear();
google::protobuf::TestUtilLite::ExpectExtensionsClear(message);
}
+}
+
+TEST(Lite, AllLite3) {
+ string data, packed_data;
{
protobuf_unittest::TestPackedTypesLite message, message2, message3;
@@ -152,7 +155,7 @@ int main(int argc, char* argv[]) {
google::protobuf::TestUtilLite::SetPackedExtensions(&message);
message2.CopyFrom(message);
string packed_extensions_data = message.SerializeAsString();
- GOOGLE_CHECK(packed_extensions_data == packed_data);
+ EXPECT_EQ(packed_extensions_data, packed_data);
message3.ParseFromString(packed_extensions_data);
google::protobuf::TestUtilLite::ExpectPackedExtensionsSet(message);
google::protobuf::TestUtilLite::ExpectPackedExtensionsSet(message2);
@@ -162,6 +165,10 @@ int main(int argc, char* argv[]) {
message.Clear();
google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message);
}
+}
+
+TEST(Lite, AllLite5) {
+ string data;
{
// Test that if an optional or required message/group field appears multiple
@@ -209,11 +216,16 @@ int main(int argc, char* argv[]) {
google::protobuf::unittest::TestParsingMergeLite::optional_ext));
// Repeated fields should not be merged.
- GOOGLE_CHECK(parsing_merge.repeated_all_types_size() == 3);
- GOOGLE_CHECK(parsing_merge.repeatedgroup_size() == 3);
- GOOGLE_CHECK(parsing_merge.ExtensionSize(
- google::protobuf::unittest::TestParsingMergeLite::repeated_ext) == 3);
+ EXPECT_EQ(parsing_merge.repeated_all_types_size(), 3);
+ EXPECT_EQ(parsing_merge.repeatedgroup_size(), 3);
+ EXPECT_EQ(parsing_merge.ExtensionSize(
+ google::protobuf::unittest::TestParsingMergeLite::repeated_ext),
+ 3);
}
+}
+
+TEST(Lite, AllLite6) {
+ string data;
// Test unknown fields support for lite messages.
{
@@ -231,6 +243,10 @@ int main(int argc, char* argv[]) {
message.Clear();
google::protobuf::TestUtilLite::ExpectClear(message);
}
+}
+
+TEST(Lite, AllLite7) {
+ string data;
{
protobuf_unittest::TestAllExtensionsLite message, message2;
@@ -247,6 +263,10 @@ int main(int argc, char* argv[]) {
message.Clear();
google::protobuf::TestUtilLite::ExpectExtensionsClear(message);
}
+}
+
+TEST(Lite, AllLite8) {
+ string data;
{
protobuf_unittest::TestPackedTypesLite message, message2;
@@ -263,6 +283,10 @@ int main(int argc, char* argv[]) {
message.Clear();
google::protobuf::TestUtilLite::ExpectPackedClear(message);
}
+}
+
+TEST(Lite, AllLite9) {
+ string data;
{
protobuf_unittest::TestPackedExtensionsLite message, message2;
@@ -279,6 +303,10 @@ int main(int argc, char* argv[]) {
message.Clear();
google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message);
}
+}
+
+TEST(Lite, AllLite10) {
+ string data;
{
// Test Unknown fields swap
@@ -286,11 +314,15 @@ int main(int argc, char* argv[]) {
SetAllTypesInEmptyMessageUnknownFields(&empty_message);
SetSomeTypesInEmptyMessageUnknownFields(&empty_message2);
data = empty_message.SerializeAsString();
- data2 = empty_message2.SerializeAsString();
+ string data2 = empty_message2.SerializeAsString();
empty_message.Swap(&empty_message2);
- GOOGLE_CHECK_EQ(data, empty_message2.SerializeAsString());
- GOOGLE_CHECK_EQ(data2, empty_message.SerializeAsString());
+ EXPECT_EQ(data, empty_message2.SerializeAsString());
+ EXPECT_EQ(data2, empty_message.SerializeAsString());
}
+}
+
+TEST(Lite, AllLite11) {
+ string data;
{
// Test unknown fields swap with self
@@ -298,8 +330,12 @@ int main(int argc, char* argv[]) {
SetAllTypesInEmptyMessageUnknownFields(&empty_message);
data = empty_message.SerializeAsString();
empty_message.Swap(&empty_message);
- GOOGLE_CHECK_EQ(data, empty_message.SerializeAsString());
+ EXPECT_EQ(data, empty_message.SerializeAsString());
}
+}
+
+TEST(Lite, AllLite12) {
+ string data;
{
// Test MergeFrom with unknown fields
@@ -324,8 +360,12 @@ int main(int argc, char* argv[]) {
// We do not compare the serialized output of a normal message and a lite
// message because the order of fields do not match. We convert lite message
// back into normal message, then compare.
- GOOGLE_CHECK_EQ(message.SerializeAsString(), message2.SerializeAsString());
+ EXPECT_EQ(message.SerializeAsString(), message2.SerializeAsString());
}
+}
+
+TEST(Lite, AllLite13) {
+ string data;
{
// Test unknown enum value
@@ -345,18 +385,26 @@ int main(int argc, char* argv[]) {
}
message.ParseFromString(buffer);
data = message.SerializeAsString();
- GOOGLE_CHECK_EQ(data, buffer);
+ EXPECT_EQ(data, buffer);
}
+}
+
+TEST(Lite, AllLite14) {
+ string data;
{
// Test Clear with unknown fields
protobuf_unittest::TestEmptyMessageLite empty_message;
SetAllTypesInEmptyMessageUnknownFields(&empty_message);
empty_message.Clear();
- GOOGLE_CHECK_EQ(0, empty_message.unknown_fields().size());
+ EXPECT_EQ(0, empty_message.unknown_fields().size());
}
+}
- // Tests for map lite =============================================
+// Tests for map lite =============================================
+
+TEST(Lite, AllLite15) {
+ string data;
{
// Accessors
@@ -368,6 +416,10 @@ int main(int argc, char* argv[]) {
google::protobuf::MapLiteTestUtil::ModifyMapFields(&message);
google::protobuf::MapLiteTestUtil::ExpectMapFieldsModified(message);
}
+}
+
+TEST(Lite, AllLite16) {
+ string data;
{
// SetMapFieldsInitialized
@@ -376,6 +428,10 @@ int main(int argc, char* argv[]) {
google::protobuf::MapLiteTestUtil::SetMapFieldsInitialized(&message);
google::protobuf::MapLiteTestUtil::ExpectMapFieldsSetInitialized(message);
}
+}
+
+TEST(Lite, AllLite17) {
+ string data;
{
// Clear
@@ -385,6 +441,10 @@ int main(int argc, char* argv[]) {
message.Clear();
google::protobuf::MapLiteTestUtil::ExpectClear(message);
}
+}
+
+TEST(Lite, AllLite18) {
+ string data;
{
// ClearMessageMap
@@ -394,6 +454,10 @@ int main(int argc, char* argv[]) {
google::protobuf::TestUtilLite::ExpectClear(
(*message.mutable_map_int32_message())[0]);
}
+}
+
+TEST(Lite, AllLite19) {
+ string data;
{
// CopyFrom
@@ -407,6 +471,10 @@ int main(int argc, char* argv[]) {
message2.CopyFrom(message2);
google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2);
}
+}
+
+TEST(Lite, AllLite20) {
+ string data;
{
// CopyFromMessageMap
@@ -421,6 +489,10 @@ int main(int argc, char* argv[]) {
EXPECT_EQ(1, message1.map_int32_message().at(0).repeated_int32_size());
EXPECT_EQ(101, message1.map_int32_message().at(0).repeated_int32(0));
}
+}
+
+TEST(Lite, AllLite21) {
+ string data;
{
// SwapWithEmpty
@@ -434,6 +506,10 @@ int main(int argc, char* argv[]) {
google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2);
google::protobuf::MapLiteTestUtil::ExpectClear(message1);
}
+}
+
+TEST(Lite, AllLite22) {
+ string data;
{
// SwapWithSelf
@@ -445,6 +521,10 @@ int main(int argc, char* argv[]) {
message.Swap(&message);
google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message);
}
+}
+
+TEST(Lite, AllLite23) {
+ string data;
{
// SwapWithOther
@@ -458,6 +538,10 @@ int main(int argc, char* argv[]) {
google::protobuf::MapLiteTestUtil::ExpectMapFieldsModified(message1);
google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2);
}
+}
+
+TEST(Lite, AllLite24) {
+ string data;
{
// CopyConstructor
@@ -467,6 +551,10 @@ int main(int argc, char* argv[]) {
protobuf_unittest::TestMapLite message2(message1);
google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2);
}
+}
+
+TEST(Lite, AllLite25) {
+ string data;
{
// CopyAssignmentOperator
@@ -481,6 +569,10 @@ int main(int argc, char* argv[]) {
message2.operator=(message2);
google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2);
}
+}
+
+TEST(Lite, AllLite26) {
+ string data;
{
// NonEmptyMergeFrom
@@ -499,6 +591,10 @@ int main(int argc, char* argv[]) {
message1.MergeFrom(message2);
google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message1);
}
+}
+
+TEST(Lite, AllLite27) {
+ string data;
{
// MergeFromMessageMap
@@ -513,6 +609,10 @@ int main(int argc, char* argv[]) {
EXPECT_EQ(1, message1.map_int32_message().at(0).repeated_int32_size());
EXPECT_EQ(101, message1.map_int32_message().at(0).repeated_int32(0));
}
+}
+
+TEST(Lite, AllLite28) {
+ string data;
{
// Test the generated SerializeWithCachedSizesToArray()
@@ -521,12 +621,16 @@ int main(int argc, char* argv[]) {
google::protobuf::MapLiteTestUtil::SetMapFields(&message1);
int size = message1.ByteSize();
data.resize(size);
- ::google::protobuf::uint8* start = reinterpret_cast< ::google::protobuf::uint8*>(::google::protobuf::string_as_array(&data));
+ ::google::protobuf::uint8* start = reinterpret_cast<::google::protobuf::uint8*>(::google::protobuf::string_as_array(&data));
::google::protobuf::uint8* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2);
}
+}
+
+TEST(Lite, AllLite29) {
+ string data;
{
// Test the generated SerializeWithCachedSizes()
@@ -547,7 +651,11 @@ int main(int argc, char* argv[]) {
EXPECT_TRUE(message2.ParseFromString(data));
google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2);
}
+}
+
+TEST(Lite, AllLite32) {
+ string data;
{
// Proto2UnknownEnum
@@ -578,6 +686,10 @@ int main(int argc, char* argv[]) {
EXPECT_EQ(protobuf_unittest::E_PROTO2_MAP_ENUM_EXTRA_LITE,
from.unknown_map_field().at(0));
}
+}
+
+TEST(Lite, AllLite33) {
+ string data;
{
// StandardWireFormat
@@ -588,6 +700,10 @@ int main(int argc, char* argv[]) {
EXPECT_EQ(1, message.map_int32_int32().size());
EXPECT_EQ(1, message.map_int32_int32().at(1));
}
+}
+
+TEST(Lite, AllLite34) {
+ string data;
{
// UnorderedWireFormat
@@ -600,6 +716,10 @@ int main(int argc, char* argv[]) {
EXPECT_EQ(1, message.map_int32_int32().size());
EXPECT_EQ(1, message.map_int32_int32().at(2));
}
+}
+
+TEST(Lite, AllLite35) {
+ string data;
{
// DuplicatedKeyWireFormat
@@ -612,6 +732,10 @@ int main(int argc, char* argv[]) {
EXPECT_EQ(1, message.map_int32_int32().size());
EXPECT_EQ(1, message.map_int32_int32().at(2));
}
+}
+
+TEST(Lite, AllLite36) {
+ string data;
{
// DuplicatedValueWireFormat
@@ -624,6 +748,10 @@ int main(int argc, char* argv[]) {
EXPECT_EQ(1, message.map_int32_int32().size());
EXPECT_EQ(2, message.map_int32_int32().at(1));
}
+}
+
+TEST(Lite, AllLite37) {
+ string data;
{
// MissedKeyWireFormat
@@ -636,6 +764,10 @@ int main(int argc, char* argv[]) {
EXPECT_EQ(1, message.map_int32_int32().size());
EXPECT_EQ(1, message.map_int32_int32().at(0));
}
+}
+
+TEST(Lite, AllLite38) {
+ string data;
{
// MissedValueWireFormat
@@ -648,6 +780,10 @@ int main(int argc, char* argv[]) {
EXPECT_EQ(1, message.map_int32_int32().size());
EXPECT_EQ(0, message.map_int32_int32().at(1));
}
+}
+
+TEST(Lite, AllLite39) {
+ string data;
{
// UnknownFieldWireFormat
@@ -660,6 +796,10 @@ int main(int argc, char* argv[]) {
EXPECT_EQ(1, message.map_int32_int32().size());
EXPECT_EQ(3, message.map_int32_int32().at(2));
}
+}
+
+TEST(Lite, AllLite40) {
+ string data;
{
// CorruptedWireFormat
@@ -670,6 +810,10 @@ int main(int argc, char* argv[]) {
EXPECT_FALSE(message.ParseFromString(data));
}
+}
+
+TEST(Lite, AllLite41) {
+ string data;
{
// IsInitialized
@@ -685,7 +829,208 @@ int main(int argc, char* argv[]) {
(*map_message.mutable_map_field())[0].set_c(0);
EXPECT_TRUE(map_message.IsInitialized());
}
+}
+
+TEST(Lite, AllLite42) {
+ string data;
+
+ {
+ // Check that adding more values to enum does not corrupt message
+ // when passed through an old client.
+ protobuf_unittest::V2MessageLite v2_message;
+ v2_message.set_int_field(800);
+ // Set enum field to the value not understood by the old client.
+ v2_message.set_enum_field(protobuf_unittest::V2_SECOND);
+ string v2_bytes = v2_message.SerializeAsString();
+
+ protobuf_unittest::V1MessageLite v1_message;
+ v1_message.ParseFromString(v2_bytes);
+ EXPECT_TRUE(v1_message.IsInitialized());
+ EXPECT_EQ(v1_message.int_field(), v2_message.int_field());
+ // V1 client does not understand V2_SECOND value, so it discards it and
+ // uses default value instead.
+ EXPECT_EQ(v1_message.enum_field(), protobuf_unittest::V1_FIRST);
+
+ // However, when re-serialized, it should preserve enum value.
+ string v1_bytes = v1_message.SerializeAsString();
+
+ protobuf_unittest::V2MessageLite same_v2_message;
+ same_v2_message.ParseFromString(v1_bytes);
+
+ EXPECT_EQ(v2_message.int_field(), same_v2_message.int_field());
+ EXPECT_EQ(v2_message.enum_field(), same_v2_message.enum_field());
+ }
+}
+
+// Test that when parsing a oneof, we can successfully clear whatever already
+// happened to be stored in the oneof.
+TEST(Lite, AllLite43) {
+ protobuf_unittest::TestOneofParsingLite message1;
+
+ message1.set_oneof_int32(17);
+ string serialized;
+ EXPECT_TRUE(message1.SerializeToString(&serialized));
+
+ // Submessage
+ {
+ protobuf_unittest::TestOneofParsingLite message2;
+ message2.mutable_oneof_submessage();
+ google::protobuf::io::CodedInputStream input_stream(
+ reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()), serialized.size());
+ EXPECT_TRUE(message2.MergeFromCodedStream(&input_stream));
+ EXPECT_EQ(17, message2.oneof_int32());
+ }
+
+ // String
+ {
+ protobuf_unittest::TestOneofParsingLite message2;
+ message2.set_oneof_string("string");
+ google::protobuf::io::CodedInputStream input_stream(
+ reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()), serialized.size());
+ EXPECT_TRUE(message2.MergeFromCodedStream(&input_stream));
+ EXPECT_EQ(17, message2.oneof_int32());
+ }
+
+ // Bytes
+ {
+ protobuf_unittest::TestOneofParsingLite message2;
+ message2.set_oneof_bytes("bytes");
+ google::protobuf::io::CodedInputStream input_stream(
+ reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()), serialized.size());
+ EXPECT_TRUE(message2.MergeFromCodedStream(&input_stream));
+ EXPECT_EQ(17, message2.oneof_int32());
+ }
+}
+
+// Verify that we can successfully parse fields of various types within oneof
+// fields. We also verify that we can parse the same data twice into the same
+// message.
+TEST(Lite, AllLite44) {
+ // Int32
+ {
+ protobuf_unittest::TestOneofParsingLite original;
+ original.set_oneof_int32(17);
+ string serialized;
+ EXPECT_TRUE(original.SerializeToString(&serialized));
+ protobuf_unittest::TestOneofParsingLite parsed;
+ for (int i = 0; i < 2; ++i) {
+ google::protobuf::io::CodedInputStream input_stream(
+ reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()),
+ serialized.size());
+ EXPECT_TRUE(parsed.MergeFromCodedStream(&input_stream));
+ EXPECT_EQ(17, parsed.oneof_int32());
+ }
+ }
+
+ // Submessage
+ {
+ protobuf_unittest::TestOneofParsingLite original;
+ original.mutable_oneof_submessage()->set_optional_int32(5);
+ string serialized;
+ EXPECT_TRUE(original.SerializeToString(&serialized));
+ protobuf_unittest::TestOneofParsingLite parsed;
+ for (int i = 0; i < 2; ++i) {
+ google::protobuf::io::CodedInputStream input_stream(
+ reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()),
+ serialized.size());
+ EXPECT_TRUE(parsed.MergeFromCodedStream(&input_stream));
+ EXPECT_EQ(5, parsed.oneof_submessage().optional_int32());
+ }
+ }
+
+ // String
+ {
+ protobuf_unittest::TestOneofParsingLite original;
+ original.set_oneof_string("string");
+ string serialized;
+ EXPECT_TRUE(original.SerializeToString(&serialized));
+ protobuf_unittest::TestOneofParsingLite parsed;
+ for (int i = 0; i < 2; ++i) {
+ google::protobuf::io::CodedInputStream input_stream(
+ reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()),
+ serialized.size());
+ EXPECT_TRUE(parsed.MergeFromCodedStream(&input_stream));
+ EXPECT_EQ("string", parsed.oneof_string());
+ }
+ }
+
+ // Bytes
+ {
+ protobuf_unittest::TestOneofParsingLite original;
+ original.set_oneof_bytes("bytes");
+ string serialized;
+ EXPECT_TRUE(original.SerializeToString(&serialized));
+ protobuf_unittest::TestOneofParsingLite parsed;
+ for (int i = 0; i < 2; ++i) {
+ google::protobuf::io::CodedInputStream input_stream(
+ reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()),
+ serialized.size());
+ EXPECT_TRUE(parsed.MergeFromCodedStream(&input_stream));
+ EXPECT_EQ("bytes", parsed.oneof_bytes());
+ }
+ }
+
+ // Enum
+ {
+ protobuf_unittest::TestOneofParsingLite original;
+ original.set_oneof_enum(protobuf_unittest::V2_SECOND);
+ string serialized;
+ EXPECT_TRUE(original.SerializeToString(&serialized));
+ protobuf_unittest::TestOneofParsingLite parsed;
+ for (int i = 0; i < 2; ++i) {
+ google::protobuf::io::CodedInputStream input_stream(
+ reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()),
+ serialized.size());
+ EXPECT_TRUE(parsed.MergeFromCodedStream(&input_stream));
+ EXPECT_EQ(protobuf_unittest::V2_SECOND, parsed.oneof_enum());
+ }
+ }
std::cout << "PASS" << std::endl;
- return 0;
+}
+
+TEST(Lite, AllLite45) {
+ // Test unknown fields are not discarded upon parsing.
+ string data = "\20\1"; // varint 1 with field number 2
+
+ protobuf_unittest::ForeignMessageLite a;
+ EXPECT_TRUE(a.ParseFromString(data));
+ google::protobuf::io::CodedInputStream input_stream(
+ reinterpret_cast<const ::google::protobuf::uint8*>(data.data()), data.size());
+ EXPECT_TRUE(a.MergePartialFromCodedStream(&input_stream));
+
+ string serialized = a.SerializeAsString();
+ EXPECT_EQ(serialized.substr(0, 2), data);
+ EXPECT_EQ(serialized.substr(2), data);
+}
+
+// The following two tests check for wire compatibility between packed and
+// unpacked repeated fields. There used to be a bug in the generated parsing
+// code that caused us to calculate the highest possible tag number without
+// taking into account that a repeated field might not be in the packed (or
+// unpacked) state we expect. These tests specifically check for that issue by
+// making sure we can parse repeated fields when the tag is higher than we would
+// expect.
+TEST(Lite, AllLite46) {
+ protobuf_unittest::PackedInt32 packed;
+ packed.add_repeated_int32(42);
+ string serialized;
+ ASSERT_TRUE(packed.SerializeToString(&serialized));
+
+ protobuf_unittest::NonPackedInt32 non_packed;
+ ASSERT_TRUE(non_packed.ParseFromString(serialized));
+ ASSERT_EQ(1, non_packed.repeated_int32_size());
+ EXPECT_EQ(42, non_packed.repeated_int32(0));
+}
+
+TEST(Lite, AllLite47) {
+ protobuf_unittest::NonPackedFixed32 non_packed;
+ non_packed.add_repeated_fixed32(42);
+ string serialized;
+ ASSERT_TRUE(non_packed.SerializeToString(&serialized));
+
+ protobuf_unittest::PackedFixed32 packed;
+ ASSERT_TRUE(packed.ParseFromString(serialized));
+ ASSERT_EQ(1, packed.repeated_fixed32_size());
+ EXPECT_EQ(42, packed.repeated_fixed32(0));
}