diff options
author | Nicholas Seckar <seckar@google.com> | 2013-11-09 16:12:17 -0800 |
---|---|---|
committer | Nicholas Seckar <seckar@google.com> | 2013-11-15 07:54:07 -0800 |
commit | 62a22a732fb134e5f34dd3e01920933ca5b16346 (patch) | |
tree | 408f11eb68a020bfbe59bc81fc4088b608d6779b /java/src/test/java/com | |
parent | 8a15121c1077fe883f428bd27dee6b99e06e48b6 (diff) | |
download | external_protobuf-62a22a732fb134e5f34dd3e01920933ca5b16346.zip external_protobuf-62a22a732fb134e5f34dd3e01920933ca5b16346.tar.gz external_protobuf-62a22a732fb134e5f34dd3e01920933ca5b16346.tar.bz2 |
Update MessageNano#toString() to return mostly valid TextFormat.
The output of toString is now aligned with that used by non-nano and C++
runtimes, with the exception of groups. Groups should be serialized using a
camelized name (e.g. "FooBar" rather than "foo_bar") however the nano runtime
does not have information on which fields are groups.
Changes are:
- bytes fields are output within double-quotes, non-printable characters are
output as octal escape sequences (i.e. \NNN);
- field identifiers are output in underscored format;
- unset fields are not output (rather than printing "null");
- the type name of the root message is not output.
With these changes the nano toString, normal toString, and C++'s DebugString all
produce equivalent output when given the same message. (Provided that message
uses no deprecated features.)
Change-Id: Id4791d73822846db29344db9f7bc3781c3e183a6
Diffstat (limited to 'java/src/test/java/com')
-rw-r--r-- | java/src/test/java/com/google/protobuf/NanoTest.java | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java index 68d2c45..724e741 100644 --- a/java/src/test/java/com/google/protobuf/NanoTest.java +++ b/java/src/test/java/com/google/protobuf/NanoTest.java @@ -2490,14 +2490,14 @@ public class NanoTest extends TestCase { msg.optionalInt32 = 14; msg.optionalFloat = 42.3f; msg.optionalString = "String \"with' both quotes"; - msg.optionalBytes = new byte[5]; + msg.optionalBytes = new byte[] {'"', '\0', 1, 8}; msg.optionalGroup = new TestAllTypesNano.OptionalGroup(); msg.optionalGroup.a = 15; msg.repeatedInt64 = new long[2]; msg.repeatedInt64[0] = 1L; msg.repeatedInt64[1] = -1L; msg.repeatedBytes = new byte[2][]; - msg.repeatedBytes[1] = new byte[5]; + msg.repeatedBytes[1] = new byte[] {'h', 'e', 'l', 'l', 'o'}; msg.repeatedGroup = new TestAllTypesNano.RepeatedGroup[2]; msg.repeatedGroup[0] = new TestAllTypesNano.RepeatedGroup(); msg.repeatedGroup[0].a = -27; @@ -2514,28 +2514,31 @@ public class NanoTest extends TestCase { msg.repeatedNestedEnum = new int[2]; msg.repeatedNestedEnum[0] = TestAllTypesNano.BAR; msg.repeatedNestedEnum[1] = TestAllTypesNano.FOO; + msg.repeatedStringPiece = new String[] {null, "world"}; String protoPrint = msg.toString(); - assertTrue(protoPrint.contains("TestAllTypesNano <")); - assertTrue(protoPrint.contains(" optional_int32: 14")); - assertTrue(protoPrint.contains(" optional_float: 42.3")); - assertTrue(protoPrint.contains(" optional_double: 0.0")); - assertTrue(protoPrint.contains(" optional_string: \"String \\u0022with\\u0027 both quotes\"")); - assertTrue(protoPrint.contains(" optional_bytes: [B@")); - assertTrue(protoPrint.contains(" optionalGroup <\n a: 15\n >")); - - assertTrue(protoPrint.contains(" repeated_int64: 1")); - assertTrue(protoPrint.contains(" repeated_int64: -1")); - assertTrue(protoPrint.contains(" repeated_bytes: null\n repeated_bytes: [B@")); - assertTrue(protoPrint.contains(" repeatedGroup <\n a: -27\n >\n" - + " repeatedGroup <\n a: -72\n >")); - assertTrue(protoPrint.contains(" optionalNestedMessage <\n bb: 7\n >")); - assertTrue(protoPrint.contains(" repeatedNestedMessage <\n bb: 77\n >\n" - + " repeatedNestedMessage <\n bb: 88\n >")); - assertTrue(protoPrint.contains(" optional_nested_enum: 3")); - assertTrue(protoPrint.contains(" repeated_nested_enum: 2\n repeated_nested_enum: 1")); - assertTrue(protoPrint.contains(" default_int32: 41")); - assertTrue(protoPrint.contains(" default_string: \"hello\"")); + assertTrue(protoPrint.contains("optional_int32: 14")); + assertTrue(protoPrint.contains("optional_float: 42.3")); + assertTrue(protoPrint.contains("optional_double: 0.0")); + assertTrue(protoPrint.contains("optional_string: \"String \\u0022with\\u0027 both quotes\"")); + assertTrue(protoPrint.contains("optional_bytes: \"\\\"\\000\\001\\010\"")); + assertTrue(protoPrint.contains("optional_group <\n a: 15\n>")); + + assertTrue(protoPrint.contains("repeated_int64: 1")); + assertTrue(protoPrint.contains("repeated_int64: -1")); + assertFalse(protoPrint.contains("repeated_bytes: \"\"")); // null should be dropped + assertTrue(protoPrint.contains("repeated_bytes: \"hello\"")); + assertTrue(protoPrint.contains("repeated_group <\n a: -27\n>\n" + + "repeated_group <\n a: -72\n>")); + assertTrue(protoPrint.contains("optional_nested_message <\n bb: 7\n>")); + assertTrue(protoPrint.contains("repeated_nested_message <\n bb: 77\n>\n" + + "repeated_nested_message <\n bb: 88\n>")); + assertTrue(protoPrint.contains("optional_nested_enum: 3")); + assertTrue(protoPrint.contains("repeated_nested_enum: 2\nrepeated_nested_enum: 1")); + assertTrue(protoPrint.contains("default_int32: 41")); + assertTrue(protoPrint.contains("default_string: \"hello\"")); + assertFalse(protoPrint.contains("repeated_string_piece: \"\"")); // null should be dropped + assertTrue(protoPrint.contains("repeated_string_piece: \"world\"")); } public void testExtensions() throws Exception { |