aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/wire_format_unittest.cc
diff options
context:
space:
mode:
authorGravatar temporal <temporal@630680e5-0e50-0410-840e-4b1c322b438d>2008-08-13 03:15:00 +0000
committerGravatar temporal <temporal@630680e5-0e50-0410-840e-4b1c322b438d>2008-08-13 03:15:00 +0000
commit779f61c6a3ce02a119e28e802f229e61b69b9046 (patch)
tree9131ef5f0acdc3d708a795fc6703488674741ee0 /src/google/protobuf/wire_format_unittest.cc
parenta0f27fcd96c5bf2509ca88cca54f00b78f7b8bc5 (diff)
Integrate recent changes from google3.
protoc - New flags --encode and --decode can be used to convert between protobuf text format and binary format from the command-line. - New flag --descriptor_set_out can be used to write FileDescriptorProtos for all parsed files directly into a single output file. This is particularly useful if you wish to parse .proto files from programs written in languages other than C++: just run protoc as a background process and have it output a FileDescriptorList, then parse that natively. C++ - Reflection objects are now per-class rather than per-instance. To make this possible, the Reflection interface had to be changed such that all methods take the Message instance as a parameter. This change improves performance significantly in memory-bandwidth-limited use cases, since it makes the message objects smaller. Note that source-incompatible interface changes like this will not be made again after the library leaves beta. Python - MergeFrom(message) and CopyFrom(message) are now implemented. - SerializeToString() raises an exception if the message is missing required fields. - Code organization improvements. - Fixed doc comments for RpcController and RpcChannel, which had somehow been swapped.
Diffstat (limited to 'src/google/protobuf/wire_format_unittest.cc')
-rw-r--r--src/google/protobuf/wire_format_unittest.cc55
1 files changed, 31 insertions, 24 deletions
diff --git a/src/google/protobuf/wire_format_unittest.cc b/src/google/protobuf/wire_format_unittest.cc
index 7430786c..f5953bea 100644
--- a/src/google/protobuf/wire_format_unittest.cc
+++ b/src/google/protobuf/wire_format_unittest.cc
@@ -53,8 +53,7 @@ TEST(WireFormatTest, Parse) {
// Parse using WireFormat.
io::ArrayInputStream raw_input(data.data(), data.size());
io::CodedInputStream input(&raw_input);
- WireFormat::ParseAndMergePartial(unittest::TestAllTypes::descriptor(),
- &input, dest.GetReflection());
+ WireFormat::ParseAndMergePartial(&input, &dest);
// Check.
TestUtil::ExpectAllFieldsSet(dest);
@@ -71,8 +70,7 @@ TEST(WireFormatTest, ParseExtensions) {
// Parse using WireFormat.
io::ArrayInputStream raw_input(data.data(), data.size());
io::CodedInputStream input(&raw_input);
- WireFormat::ParseAndMergePartial(unittest::TestAllExtensions::descriptor(),
- &input, dest.GetReflection());
+ WireFormat::ParseAndMergePartial(&input, &dest);
// Check.
TestUtil::ExpectAllExtensionsSet(dest);
@@ -82,13 +80,10 @@ TEST(WireFormatTest, ByteSize) {
unittest::TestAllTypes message;
TestUtil::SetAllFields(&message);
- EXPECT_EQ(message.ByteSize(),
- WireFormat::ByteSize(unittest::TestAllTypes::descriptor(),
- message.GetReflection()));
+ EXPECT_EQ(message.ByteSize(), WireFormat::ByteSize(message));
message.Clear();
EXPECT_EQ(0, message.ByteSize());
- EXPECT_EQ(0, WireFormat::ByteSize(unittest::TestAllTypes::descriptor(),
- message.GetReflection()));
+ EXPECT_EQ(0, WireFormat::ByteSize(message));
}
TEST(WireFormatTest, ByteSizeExtensions) {
@@ -96,12 +91,10 @@ TEST(WireFormatTest, ByteSizeExtensions) {
TestUtil::SetAllExtensions(&message);
EXPECT_EQ(message.ByteSize(),
- WireFormat::ByteSize(unittest::TestAllExtensions::descriptor(),
- message.GetReflection()));
+ WireFormat::ByteSize(message));
message.Clear();
EXPECT_EQ(0, message.ByteSize());
- EXPECT_EQ(0, WireFormat::ByteSize(unittest::TestAllExtensions::descriptor(),
- message.GetReflection()));
+ EXPECT_EQ(0, WireFormat::ByteSize(message));
}
TEST(WireFormatTest, Serialize) {
@@ -123,9 +116,7 @@ TEST(WireFormatTest, Serialize) {
{
io::StringOutputStream raw_output(&dynamic_data);
io::CodedOutputStream output(&raw_output);
- WireFormat::SerializeWithCachedSizes(
- unittest::TestAllTypes::descriptor(),
- message.GetReflection(), size, &output);
+ WireFormat::SerializeWithCachedSizes(message, size, &output);
}
// Should be the same.
@@ -153,9 +144,7 @@ TEST(WireFormatTest, SerializeExtensions) {
{
io::StringOutputStream raw_output(&dynamic_data);
io::CodedOutputStream output(&raw_output);
- WireFormat::SerializeWithCachedSizes(
- unittest::TestAllExtensions::descriptor(),
- message.GetReflection(), size, &output);
+ WireFormat::SerializeWithCachedSizes(message, size, &output);
}
// Should be the same.
@@ -183,9 +172,7 @@ TEST(WireFormatTest, SerializeFieldsAndExtensions) {
{
io::StringOutputStream raw_output(&dynamic_data);
io::CodedOutputStream output(&raw_output);
- WireFormat::SerializeWithCachedSizes(
- unittest::TestFieldOrderings::descriptor(),
- message.GetReflection(), size, &output);
+ WireFormat::SerializeWithCachedSizes(message, size, &output);
}
// Should be the same.
@@ -497,9 +484,9 @@ TEST_F(WireFormatInvalidInputTest, InvalidGroup) {
}
TEST_F(WireFormatInvalidInputTest, InvalidUnknownGroup) {
- // Use ForeignMessage so that the group made by MakeInvalidGroup will not
+ // Use TestEmptyMessage so that the group made by MakeInvalidGroup will not
// be a known tag number.
- unittest::ForeignMessage message;
+ unittest::TestEmptyMessage message;
// Control case.
EXPECT_TRUE(message.ParseFromString(MakeInvalidGroup("", 0, true)));
@@ -520,6 +507,26 @@ TEST_F(WireFormatInvalidInputTest, InvalidUnknownGroup) {
EXPECT_FALSE(message.ParseFromString(MakeInvalidGroup("\017", 1, true)));
}
+TEST_F(WireFormatInvalidInputTest, InvalidStringInUnknownGroup) {
+ // Test a bug fix: SkipMessage should fail if the message contains a string
+ // whose length would extend beyond the message end.
+
+ unittest::TestAllTypes message;
+ message.set_optional_string("foo foo foo foo");
+ string data;
+ message.SerializeToString(&data);
+
+ // Chop some bytes off the end.
+ data.resize(data.size() - 4);
+
+ // Try to skip it. Note that the bug was only present when parsing to an
+ // UnknownFieldSet.
+ io::ArrayInputStream raw_input(data.data(), data.size());
+ io::CodedInputStream coded_input(&raw_input);
+ UnknownFieldSet unknown_fields;
+ EXPECT_FALSE(WireFormat::SkipMessage(&coded_input, &unknown_fields));
+}
+
} // namespace
} // namespace internal
} // namespace protobuf