aboutsummaryrefslogtreecommitdiffhomepage
path: root/java/core/src/test/java/com/google/protobuf/ParserTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/core/src/test/java/com/google/protobuf/ParserTest.java')
-rw-r--r--java/core/src/test/java/com/google/protobuf/ParserTest.java27
1 files changed, 23 insertions, 4 deletions
diff --git a/java/core/src/test/java/com/google/protobuf/ParserTest.java b/java/core/src/test/java/com/google/protobuf/ParserTest.java
index 8c2e4c26..4bd34112 100644
--- a/java/core/src/test/java/com/google/protobuf/ParserTest.java
+++ b/java/core/src/test/java/com/google/protobuf/ParserTest.java
@@ -79,6 +79,8 @@ public class ParserTest extends TestCase {
new ByteArrayInputStream(data), registry));
assertMessageEquals(message, parser.parseFrom(
CodedInputStream.newInstance(data), registry));
+ assertMessageEquals(
+ message, parser.parseFrom(message.toByteString().asReadOnlyByteBuffer(), registry));
}
@SuppressWarnings("unchecked")
@@ -99,6 +101,7 @@ public class ParserTest extends TestCase {
new ByteArrayInputStream(data)));
assertMessageEquals(message, parser.parseFrom(
CodedInputStream.newInstance(data)));
+ assertMessageEquals(message, parser.parseFrom(message.toByteString().asReadOnlyByteBuffer()));
}
private void assertMessageEquals(
@@ -178,6 +181,9 @@ public class ParserTest extends TestCase {
public void testParseExtensions() throws Exception {
assertRoundTripEquals(TestUtil.getAllExtensionsSet(),
TestUtil.getExtensionRegistry());
+ }
+
+ public void testParseExtensionsLite() throws Exception {
assertRoundTripEquals(
TestUtilLite.getAllLiteExtensionsSet(), TestUtilLite.getExtensionRegistryLite());
}
@@ -186,6 +192,9 @@ public class ParserTest extends TestCase {
assertRoundTripEquals(TestUtil.getPackedSet());
assertRoundTripEquals(TestUtil.getPackedExtensionsSet(),
TestUtil.getExtensionRegistry());
+ }
+
+ public void testParsePackedLite() throws Exception {
assertRoundTripEquals(
TestUtilLite.getLitePackedExtensionsSet(), TestUtilLite.getExtensionRegistryLite());
}
@@ -195,15 +204,26 @@ public class ParserTest extends TestCase {
TestAllTypes normalMessage = TestUtil.getAllSet();
ByteArrayOutputStream output = new ByteArrayOutputStream();
normalMessage.writeDelimitedTo(output);
+ normalMessage.writeDelimitedTo(output);
+ InputStream input = new ByteArrayInputStream(output.toByteArray());
+ assertMessageEquals(normalMessage, normalMessage.getParserForType().parseDelimitedFrom(input));
+ assertMessageEquals(normalMessage, normalMessage.getParserForType().parseDelimitedFrom(input));
+ }
+
+ public void testParseDelimitedToLite() throws Exception {
// Write MessageLite with packed extension fields.
TestPackedExtensionsLite packedMessage = TestUtilLite.getLitePackedExtensionsSet();
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ packedMessage.writeDelimitedTo(output);
packedMessage.writeDelimitedTo(output);
InputStream input = new ByteArrayInputStream(output.toByteArray());
assertMessageEquals(
- normalMessage,
- normalMessage.getParserForType().parseDelimitedFrom(input));
+ packedMessage,
+ packedMessage
+ .getParserForType()
+ .parseDelimitedFrom(input, TestUtilLite.getExtensionRegistryLite()));
assertMessageEquals(
packedMessage,
packedMessage
@@ -314,8 +334,7 @@ public class ParserTest extends TestCase {
public void testParsingMergeLite() throws Exception {
// Build messages.
- TestAllTypesLite.Builder builder =
- TestAllTypesLite.newBuilder();
+ TestAllTypesLite.Builder builder = TestAllTypesLite.newBuilder();
TestAllTypesLite msg1 = builder.setOptionalInt32(1).build();
builder.clear();
TestAllTypesLite msg2 = builder.setOptionalInt64(2).build();