| Index: third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ParserTest.java
|
| diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ParserTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ParserTest.java
|
| similarity index 66%
|
| copy from third_party/protobuf/java/core/src/test/java/com/google/protobuf/ParserTest.java
|
| copy to third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ParserTest.java
|
| index 30842d2c0833fc13b91bd65a87f45274ad115091..b35af689cd2c62fbfa301fc13c7f6efeb2bc85bf 100644
|
| --- a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ParserTest.java
|
| +++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ParserTest.java
|
| @@ -1,6 +1,6 @@
|
| // Protocol Buffers - Google's data interchange format
|
| // Copyright 2008 Google Inc. All rights reserved.
|
| -// https://developers.google.com/protocol-buffers/
|
| +// http://code.google.com/p/protobuf/
|
| //
|
| // Redistribution and use in source and binary forms, with or without
|
| // modification, are permitted provided that the following conditions are
|
| @@ -28,20 +28,18 @@
|
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| -package com.google.protobuf;
|
| +package com.google.protobuf.test;
|
| +import com.google.protobuf.*;
|
|
|
| -import com.google.protobuf.UnittestLite.TestAllTypesLite;
|
| -import com.google.protobuf.UnittestLite.TestPackedExtensionsLite;
|
| -import com.google.protobuf.UnittestLite.TestParsingMergeLite;
|
| -import protobuf_unittest.UnittestOptimizeFor;
|
| import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize;
|
| import protobuf_unittest.UnittestOptimizeFor.TestRequiredOptimizedForSize;
|
| -import protobuf_unittest.UnittestProto;
|
| +import protobuf_unittest.UnittestOptimizeFor;
|
| import protobuf_unittest.UnittestProto.ForeignMessage;
|
| import protobuf_unittest.UnittestProto.TestAllTypes;
|
| import protobuf_unittest.UnittestProto.TestEmptyMessage;
|
| -import protobuf_unittest.UnittestProto.TestParsingMerge;
|
| import protobuf_unittest.UnittestProto.TestRequired;
|
| +import protobuf_unittest.UnittestProto.TestParsingMerge;
|
| +import protobuf_unittest.UnittestProto;
|
|
|
| import junit.framework.TestCase;
|
|
|
| @@ -58,7 +56,8 @@ import java.io.InputStream;
|
| public class ParserTest extends TestCase {
|
| public void testGeneratedMessageParserSingleton() throws Exception {
|
| for (int i = 0; i < 10; i++) {
|
| - assertEquals(TestAllTypes.parser(), TestUtil.getAllSet().getParserForType());
|
| + assertEquals(TestAllTypes.PARSER,
|
| + TestUtil.getAllSet().getParserForType());
|
| }
|
| }
|
|
|
| @@ -82,15 +81,12 @@ public class ParserTest extends TestCase {
|
| CodedInputStream.newInstance(data), registry));
|
| }
|
|
|
| - @SuppressWarnings("unchecked")
|
| private void assertRoundTripEquals(MessageLite message) throws Exception {
|
| final byte[] data = message.toByteArray();
|
| final int offset = 20;
|
| final int length = data.length;
|
| final int padding = 30;
|
| -
|
| - Parser<MessageLite> parser =
|
| - (Parser<MessageLite>) message.getParserForType();
|
| + Parser<? extends MessageLite> parser = message.getParserForType();
|
| assertMessageEquals(message, parser.parseFrom(data));
|
| assertMessageEquals(message, parser.parseFrom(
|
| generatePaddingArray(data, offset, padding),
|
| @@ -102,8 +98,7 @@ public class ParserTest extends TestCase {
|
| CodedInputStream.newInstance(data)));
|
| }
|
|
|
| - private void assertMessageEquals(
|
| - MessageLite expected, MessageLite actual)
|
| + private void assertMessageEquals(MessageLite expected, MessageLite actual)
|
| throws Exception {
|
| if (expected instanceof Message) {
|
| assertEquals(expected, actual);
|
| @@ -122,16 +117,15 @@ public class ParserTest extends TestCase {
|
| assertRoundTripEquals(TestUtil.getAllSet());
|
| }
|
|
|
| -
|
| public void testParsePartial() throws Exception {
|
| - assertParsePartial(TestRequired.parser(), TestRequired.newBuilder().setA(1).buildPartial());
|
| - }
|
| -
|
| - private <T extends MessageLite> void assertParsePartial(
|
| - Parser<T> parser, T partialMessage) throws Exception {
|
| + Parser<TestRequired> parser = TestRequired.PARSER;
|
| final String errorString =
|
| "Should throw exceptions when the parsed message isn't initialized.";
|
|
|
| + // TestRequired.b and TestRequired.c are not set.
|
| + TestRequired partialMessage = TestRequired.newBuilder()
|
| + .setA(1).buildPartial();
|
| +
|
| // parsePartialFrom should pass.
|
| byte[] data = partialMessage.toByteArray();
|
| assertEquals(partialMessage, parser.parsePartialFrom(data));
|
| @@ -176,52 +170,27 @@ public class ParserTest extends TestCase {
|
| }
|
| }
|
|
|
| - public void testParseExtensions() throws Exception {
|
| - assertRoundTripEquals(TestUtil.getAllExtensionsSet(),
|
| - TestUtil.getExtensionRegistry());
|
| - assertRoundTripEquals(
|
| - TestUtilLite.getAllLiteExtensionsSet(), TestUtilLite.getExtensionRegistryLite());
|
| - }
|
| -
|
| - public void testParsePacked() throws Exception {
|
| - assertRoundTripEquals(TestUtil.getPackedSet());
|
| - assertRoundTripEquals(TestUtil.getPackedExtensionsSet(),
|
| - TestUtil.getExtensionRegistry());
|
| - assertRoundTripEquals(
|
| - TestUtilLite.getLitePackedExtensionsSet(), TestUtilLite.getExtensionRegistryLite());
|
| - }
|
| -
|
| public void testParseDelimitedTo() throws Exception {
|
| // Write normal Message.
|
| TestAllTypes normalMessage = TestUtil.getAllSet();
|
| ByteArrayOutputStream output = new ByteArrayOutputStream();
|
| normalMessage.writeDelimitedTo(output);
|
|
|
| - // Write MessageLite with packed extension fields.
|
| - TestPackedExtensionsLite packedMessage = TestUtilLite.getLitePackedExtensionsSet();
|
| - packedMessage.writeDelimitedTo(output);
|
| -
|
| InputStream input = new ByteArrayInputStream(output.toByteArray());
|
| assertMessageEquals(
|
| normalMessage,
|
| normalMessage.getParserForType().parseDelimitedFrom(input));
|
| - assertMessageEquals(
|
| - packedMessage,
|
| - packedMessage
|
| - .getParserForType()
|
| - .parseDelimitedFrom(input, TestUtilLite.getExtensionRegistryLite()));
|
| }
|
|
|
| public void testParseUnknownFields() throws Exception {
|
| // All fields will be treated as unknown fields in emptyMessage.
|
| - TestEmptyMessage emptyMessage =
|
| - TestEmptyMessage.parser().parseFrom(TestUtil.getAllSet().toByteString());
|
| + TestEmptyMessage emptyMessage = TestEmptyMessage.PARSER.parseFrom(
|
| + TestUtil.getAllSet().toByteString());
|
| assertEquals(
|
| TestUtil.getAllSet().toByteString(),
|
| emptyMessage.toByteString());
|
| }
|
|
|
| -
|
| public void testOptimizeForSize() throws Exception {
|
| TestOptimizedForSize.Builder builder = TestOptimizedForSize.newBuilder();
|
| builder.setI(12).setMsg(ForeignMessage.newBuilder().setC(34).build());
|
| @@ -244,14 +213,6 @@ public class ParserTest extends TestCase {
|
| assertEquals("hello", allTypes.getOptionalString());
|
| }
|
|
|
| - /** Helper method for {@link #testParsingMergeLite()}.*/
|
| - private void assertMessageMerged(TestAllTypesLite allTypes)
|
| - throws Exception {
|
| - assertEquals(3, allTypes.getOptionalInt32());
|
| - assertEquals(2, allTypes.getOptionalInt64());
|
| - assertEquals("hello", allTypes.getOptionalString());
|
| - }
|
| -
|
| public void testParsingMerge() throws Exception {
|
| // Build messages.
|
| TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
| @@ -296,7 +257,8 @@ public class ParserTest extends TestCase {
|
| // Parse TestParsingMerge.
|
| ExtensionRegistry registry = ExtensionRegistry.newInstance();
|
| UnittestProto.registerAllExtensions(registry);
|
| - TestParsingMerge parsingMerge = TestParsingMerge.parser().parseFrom(data, registry);
|
| + TestParsingMerge parsingMerge =
|
| + TestParsingMerge.PARSER.parseFrom(data, registry);
|
|
|
| // Required and optional fields should be merged.
|
| assertMessageMerged(parsingMerge.getRequiredAllTypes());
|
| @@ -313,65 +275,4 @@ public class ParserTest extends TestCase {
|
| TestParsingMerge.repeatedExt));
|
| }
|
|
|
| - public void testParsingMergeLite() throws Exception {
|
| - // Build messages.
|
| - TestAllTypesLite.Builder builder =
|
| - TestAllTypesLite.newBuilder();
|
| - TestAllTypesLite msg1 = builder.setOptionalInt32(1).build();
|
| - builder.clear();
|
| - TestAllTypesLite msg2 = builder.setOptionalInt64(2).build();
|
| - builder.clear();
|
| - TestAllTypesLite msg3 = builder.setOptionalInt32(3)
|
| - .setOptionalString("hello").build();
|
| -
|
| - // Build groups.
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group1 optionalG1 =
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group1.newBuilder()
|
| - .setField1(msg1).build();
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group1 optionalG2 =
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group1.newBuilder()
|
| - .setField1(msg2).build();
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group1 optionalG3 =
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group1.newBuilder()
|
| - .setField1(msg3).build();
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group2 repeatedG1 =
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group2.newBuilder()
|
| - .setField1(msg1).build();
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group2 repeatedG2 =
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group2.newBuilder()
|
| - .setField1(msg2).build();
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group2 repeatedG3 =
|
| - TestParsingMergeLite.RepeatedFieldsGenerator.Group2.newBuilder()
|
| - .setField1(msg3).build();
|
| -
|
| - // Assign and serialize RepeatedFieldsGenerator.
|
| - ByteString data = TestParsingMergeLite.RepeatedFieldsGenerator.newBuilder()
|
| - .addField1(msg1).addField1(msg2).addField1(msg3)
|
| - .addField2(msg1).addField2(msg2).addField2(msg3)
|
| - .addField3(msg1).addField3(msg2).addField3(msg3)
|
| - .addGroup1(optionalG1).addGroup1(optionalG2).addGroup1(optionalG3)
|
| - .addGroup2(repeatedG1).addGroup2(repeatedG2).addGroup2(repeatedG3)
|
| - .addExt1(msg1).addExt1(msg2).addExt1(msg3)
|
| - .addExt2(msg1).addExt2(msg2).addExt2(msg3)
|
| - .build().toByteString();
|
| -
|
| - // Parse TestParsingMergeLite.
|
| - ExtensionRegistry registry = ExtensionRegistry.newInstance();
|
| - UnittestLite.registerAllExtensions(registry);
|
| - TestParsingMergeLite parsingMerge = TestParsingMergeLite.parser().parseFrom(data, registry);
|
| -
|
| - // Required and optional fields should be merged.
|
| - assertMessageMerged(parsingMerge.getRequiredAllTypes());
|
| - assertMessageMerged(parsingMerge.getOptionalAllTypes());
|
| - assertMessageMerged(
|
| - parsingMerge.getOptionalGroup().getOptionalGroupAllTypes());
|
| - assertMessageMerged(parsingMerge.getExtension(
|
| - TestParsingMergeLite.optionalExt));
|
| -
|
| - // Repeated fields should not be merged.
|
| - assertEquals(3, parsingMerge.getRepeatedAllTypesCount());
|
| - assertEquals(3, parsingMerge.getRepeatedGroupCount());
|
| - assertEquals(3, parsingMerge.getExtensionCount(
|
| - TestParsingMergeLite.repeatedExt));
|
| - }
|
| }
|
|
|