aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/text_format_unittest.cc
diff options
context:
space:
mode:
authorGravatar kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2008-11-21 00:06:27 +0000
committerGravatar kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2008-11-21 00:06:27 +0000
commit26bd9eee6ee6d116e1cc0dedeb660cd69d7aac45 (patch)
treed35cca89e0da44f136090a554ff9abc93a794fa8 /src/google/protobuf/text_format_unittest.cc
parenta2a32c20434807e9966e3f48375f9419134d1b55 (diff)
Integrate changes from internal code.
protoc * Enum values may now have custom options, using syntax similar to field options. * Fixed bug where .proto files which use custom options but don't actually define them (i.e. they import another .proto file defining the options) had to explicitly import descriptor.proto. * Adjacent string literals in .proto files will now be concatenated, like in C. C++ * Generated message classes now have a Swap() method which efficiently swaps the contents of two objects. * All message classes now have a SpaceUsed() method which returns an estimate of the number of bytes of allocated memory currently owned by the object. This is particularly useful when you are reusing a single message object to improve performance but want to make sure it doesn't bloat up too large. * New method Message::SerializeAsString() returns a string containing the serialized data. May be more convenient than calling SerializeToString(string*). * In debug mode, log error messages when string-type fields are found to contain bytes that are not valid UTF-8. * Fixed bug where a message with multiple extension ranges couldn't parse extensions. * Fixed bug where MergeFrom(const Message&) didn't do anything if invoked on a message that contained no fields (but possibly contained extensions). * Fixed ShortDebugString() to not be O(n^2). Durr. * Fixed crash in TextFormat parsing if the first token in the input caused a tokenization error. Java * New overload of mergeFrom() which parses a slice of a byte array instead of the whole thing. * New method ByteString.asReadOnlyByteBuffer() does what it sounds like. * Improved performance of isInitialized() when optimizing for code size. Python * Corrected ListFields() signature in Message base class to match what subclasses actually implement. * Some minor refactoring.
Diffstat (limited to 'src/google/protobuf/text_format_unittest.cc')
-rw-r--r--src/google/protobuf/text_format_unittest.cc36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc
index 7610c384..3d2cda9d 100644
--- a/src/google/protobuf/text_format_unittest.cc
+++ b/src/google/protobuf/text_format_unittest.cc
@@ -64,12 +64,12 @@ inline bool IsNaN(double value) {
// A basic string with different escapable characters for testing.
const string kEscapeTestString =
"\"A string with ' characters \n and \r newlines and \t tabs and \001 "
- "slashes \\";
+ "slashes \\ and multiple spaces";
// A representation of the above string with all the characters escaped.
const string kEscapeTestStringEscaped =
"\"\\\"A string with \\' characters \\n and \\r newlines "
- "and \\t tabs and \\001 slashes \\\\\"";
+ "and \\t tabs and \\001 slashes \\\\ and multiple spaces\"";
class TextFormatTest : public testing::Test {
public:
@@ -126,6 +126,18 @@ TEST_F(TextFormatExtensionsTest, Extensions) {
EXPECT_EQ(proto_debug_string_, proto_.DebugString());
}
+TEST_F(TextFormatTest, ShortDebugString) {
+ proto_.set_optional_int32(1);
+ proto_.set_optional_string("hello");
+ proto_.mutable_optional_nested_message()->set_bb(2);
+ proto_.mutable_optional_foreign_message();
+
+ EXPECT_EQ("optional_int32: 1 optional_string: \"hello\" "
+ "optional_nested_message { bb: 2 } "
+ "optional_foreign_message { }",
+ proto_.ShortDebugString());
+}
+
TEST_F(TextFormatTest, StringEscape) {
// Set the string value to test.
proto_.set_optional_string(kEscapeTestString);
@@ -140,6 +152,10 @@ TEST_F(TextFormatTest, StringEscape) {
// Compare.
EXPECT_EQ(correct_string, debug_string);
+
+ string expected_short_debug_string = "optional_string: "
+ + kEscapeTestStringEscaped;
+ EXPECT_EQ(expected_short_debug_string, proto_.ShortDebugString());
}
TEST_F(TextFormatTest, PrintUnknownFields) {
@@ -736,6 +752,22 @@ TEST_F(TextFormatParserTest, PrintErrorsToStderr) {
errors[0]);
}
+TEST_F(TextFormatParserTest, FailsOnTokenizationError) {
+ vector<string> errors;
+
+ {
+ ScopedMemoryLog log;
+ unittest::TestAllTypes proto;
+ EXPECT_FALSE(TextFormat::ParseFromString("\020", &proto));
+ errors = log.GetMessages(ERROR);
+ }
+
+ ASSERT_EQ(1, errors.size());
+ EXPECT_EQ("Error parsing text-format protobuf_unittest.TestAllTypes: "
+ "1:1: Invalid control characters encountered in text.",
+ errors[0]);
+}
+
class TextFormatMessageSetTest : public testing::Test {
protected: