diff options
author | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2009-07-29 01:13:20 +0000 |
---|---|---|
committer | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2009-07-29 01:13:20 +0000 |
commit | 80b1d62bfcea65c59e2160da71dad84b1bd19cef (patch) | |
tree | 5423b830c53174fec83a7ea01ff0877e11c1ddb6 /java/src/test/java/com/google/protobuf/TextFormatTest.java | |
parent | d2fd0638c309113ccae3731a58e30419f522269a (diff) | |
download | protobuf-80b1d62bfcea65c59e2160da71dad84b1bd19cef.tar.gz protobuf-80b1d62bfcea65c59e2160da71dad84b1bd19cef.tar.bz2 protobuf-80b1d62bfcea65c59e2160da71dad84b1bd19cef.zip |
Submit recent changes from internal branch, including "lite mode" for
C++ and Java. See CHANGES.txt for more details.
Diffstat (limited to 'java/src/test/java/com/google/protobuf/TextFormatTest.java')
-rw-r--r-- | java/src/test/java/com/google/protobuf/TextFormatTest.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/java/src/test/java/com/google/protobuf/TextFormatTest.java b/java/src/test/java/com/google/protobuf/TextFormatTest.java index ec4910a3..1d73165e 100644 --- a/java/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/src/test/java/com/google/protobuf/TextFormatTest.java @@ -30,9 +30,12 @@ package com.google.protobuf; +import com.google.protobuf.Descriptors.FieldDescriptor; +import protobuf_unittest.UnittestProto.OneString; import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestAllExtensions; import protobuf_unittest.UnittestProto.TestEmptyMessage; +import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage; import protobuf_unittest.UnittestMset.TestMessageSet; import protobuf_unittest.UnittestMset.TestMessageSetExtension1; import protobuf_unittest.UnittestMset.TestMessageSetExtension2; @@ -173,6 +176,22 @@ public class TextFormatTest extends TestCase { TextFormat.printToString(message)); } + public void testPrintField() throws Exception { + final FieldDescriptor dataField = + OneString.getDescriptor().findFieldByName("data"); + assertEquals( + "data: \"test data\"\n", + TextFormat.printFieldToString(dataField, "test data")); + + final FieldDescriptor optionalField = + TestAllTypes.getDescriptor().findFieldByName("optional_nested_message"); + final Object value = NestedMessage.newBuilder().setBb(42).build(); + + assertEquals( + "optional_nested_message {\n bb: 42\n}\n", + TextFormat.printFieldToString(optionalField, value)); + } + /** * Helper to construct a ByteString from a String containing only 8-bit * characters. The characters are converted directly to bytes, *not* @@ -450,21 +469,21 @@ public class TextFormatTest extends TestCase { try { TextFormat.unescapeText("\\x"); fail("Should have thrown an exception."); - } catch (TextFormat.InvalidEscapeSequence e) { + } catch (TextFormat.InvalidEscapeSequenceException e) { // success } try { TextFormat.unescapeText("\\z"); fail("Should have thrown an exception."); - } catch (TextFormat.InvalidEscapeSequence e) { + } catch (TextFormat.InvalidEscapeSequenceException e) { // success } try { TextFormat.unescapeText("\\"); fail("Should have thrown an exception."); - } catch (TextFormat.InvalidEscapeSequence e) { + } catch (TextFormat.InvalidEscapeSequenceException e) { // success } } |