Index: third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/WireFormatTest.java |
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/WireFormatTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/WireFormatTest.java |
similarity index 75% |
copy from third_party/protobuf/java/core/src/test/java/com/google/protobuf/WireFormatTest.java |
copy to third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/WireFormatTest.java |
index e66b371cdebc065e16ec4c43031925cb81cda8df..7452872620b750a1fe3109746c852c0e543fe9f0 100644 |
--- a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/WireFormatTest.java |
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/WireFormatTest.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,28 +28,25 @@ |
// (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 junit.framework.TestCase; |
+ |
+import java.io.ByteArrayInputStream; |
+import java.io.ByteArrayOutputStream; |
+import java.util.List; |
-import com.google.protobuf.UnittestLite.TestAllExtensionsLite; |
-import com.google.protobuf.UnittestLite.TestPackedExtensionsLite; |
-import protobuf_unittest.UnittestMset.RawMessageSet; |
-import protobuf_unittest.UnittestMset.TestMessageSetExtension1; |
-import protobuf_unittest.UnittestMset.TestMessageSetExtension2; |
import protobuf_unittest.UnittestProto; |
import protobuf_unittest.UnittestProto.TestAllExtensions; |
import protobuf_unittest.UnittestProto.TestAllTypes; |
import protobuf_unittest.UnittestProto.TestFieldOrderings; |
-import protobuf_unittest.UnittestProto.TestOneof2; |
-import protobuf_unittest.UnittestProto.TestOneofBackwardsCompatible; |
import protobuf_unittest.UnittestProto.TestPackedExtensions; |
import protobuf_unittest.UnittestProto.TestPackedTypes; |
-import proto2_wireformat_unittest.UnittestMsetWireFormat.TestMessageSet; |
- |
-import junit.framework.TestCase; |
- |
-import java.io.ByteArrayInputStream; |
-import java.io.ByteArrayOutputStream; |
-import java.util.List; |
+import protobuf_unittest.UnittestMset.TestMessageSet; |
+import protobuf_unittest.UnittestMset.RawMessageSet; |
+import protobuf_unittest.UnittestMset.TestMessageSetExtension1; |
+import protobuf_unittest.UnittestMset.TestMessageSetExtension2; |
/** |
* Tests related to parsing and serialization. |
@@ -127,32 +124,6 @@ public class WireFormatTest extends TestCase { |
TestUtil.assertPackedFieldsSet(message2); |
} |
- public void testSerializeExtensionsLite() throws Exception { |
- // TestAllTypes and TestAllExtensions should have compatible wire formats, |
- // so if we serialize a TestAllExtensions then parse it as TestAllTypes |
- // it should work. |
- |
- TestAllExtensionsLite message = TestUtilLite.getAllLiteExtensionsSet(); |
- ByteString rawBytes = message.toByteString(); |
- assertEquals(rawBytes.size(), message.getSerializedSize()); |
- |
- TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes); |
- |
- TestUtil.assertAllFieldsSet(message2); |
- } |
- |
- public void testSerializePackedExtensionsLite() throws Exception { |
- // TestPackedTypes and TestPackedExtensions should have compatible wire |
- // formats; check that they serialize to the same string. |
- TestPackedExtensionsLite message = TestUtilLite.getLitePackedExtensionsSet(); |
- ByteString rawBytes = message.toByteString(); |
- |
- TestPackedTypes message2 = TestUtil.getPackedSet(); |
- ByteString rawBytes2 = message2.toByteString(); |
- |
- assertEquals(rawBytes, rawBytes2); |
- } |
- |
public void testParseExtensions() throws Exception { |
// TestAllTypes and TestAllExtensions should have compatible wire formats, |
// so if we serialize a TestAllTypes then parse it as TestAllExtensions |
@@ -182,46 +153,9 @@ public class WireFormatTest extends TestCase { |
TestUtil.assertPackedExtensionsSet(message2); |
} |
- public void testParseExtensionsLite() throws Exception { |
- // TestAllTypes and TestAllExtensions should have compatible wire formats, |
- // so if we serialize a TestAllTypes then parse it as TestAllExtensions |
- // it should work. |
- |
- TestAllTypes message = TestUtil.getAllSet(); |
- ByteString rawBytes = message.toByteString(); |
- |
- ExtensionRegistryLite registry_lite = TestUtilLite.getExtensionRegistryLite(); |
- |
- TestAllExtensionsLite message2 = |
- TestAllExtensionsLite.parseFrom(rawBytes, registry_lite); |
- |
- TestUtil.assertAllExtensionsSet(message2); |
- |
- // Try again using a full extension registry. |
- ExtensionRegistry registry = TestUtil.getExtensionRegistry(); |
- |
- TestAllExtensionsLite message3 = |
- TestAllExtensionsLite.parseFrom(rawBytes, registry); |
- |
- TestUtil.assertAllExtensionsSet(message3); |
- } |
- |
- public void testParsePackedExtensionsLite() throws Exception { |
- // Ensure that packed extensions can be properly parsed. |
- TestPackedExtensionsLite message = TestUtilLite.getLitePackedExtensionsSet(); |
- ByteString rawBytes = message.toByteString(); |
- |
- ExtensionRegistryLite registry = TestUtilLite.getExtensionRegistryLite(); |
- |
- TestPackedExtensionsLite message2 = |
- TestPackedExtensionsLite.parseFrom(rawBytes, registry); |
- |
- TestUtil.assertPackedExtensionsSet(message2); |
- } |
- |
public void testExtensionsSerializedSize() throws Exception { |
- assertNotSame(TestUtil.getAllSet().getSerializedSize(), |
- TestUtil.getAllExtensionsSet().getSerializedSize()); |
+ assertEquals(TestUtil.getAllSet().getSerializedSize(), |
+ TestUtil.getAllExtensionsSet().getSerializedSize()); |
} |
public void testSerializeDelimited() throws Exception { |
@@ -528,79 +462,4 @@ public class WireFormatTest extends TestCase { |
assertEquals(123, messageSet.getExtension( |
TestMessageSetExtension1.messageSetExtension).getI()); |
} |
- |
- public void testMergeMessageSetExtensionEagerly() throws Exception { |
- testMergeMessageSetExtensionWithFlag(true); |
- } |
- |
- public void testMergeMessageSetExtensionNotEagerly() throws Exception { |
- testMergeMessageSetExtensionWithFlag(false); |
- } |
- |
- private void testMergeMessageSetExtensionWithFlag(boolean eagerParsing) |
- throws Exception { |
- ExtensionRegistryLite.setEagerlyParseMessageSets(eagerParsing); |
- ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance(); |
- extensionRegistry.add(TestMessageSetExtension1.messageSetExtension); |
- |
- // Set up a RawMessageSet with a known messages. |
- int TYPE_ID_1 = |
- TestMessageSetExtension1 |
- .getDescriptor().getExtensions().get(0).getNumber(); |
- RawMessageSet raw = |
- RawMessageSet.newBuilder() |
- .addItem( |
- RawMessageSet.Item.newBuilder() |
- .setTypeId(TYPE_ID_1) |
- .setMessage( |
- TestMessageSetExtension1.newBuilder() |
- .setI(123) |
- .build().toByteString()) |
- .build()) |
- .build(); |
- |
- // Serialize RawMessageSet unnormally (message value before type id) |
- ByteString.CodedBuilder out = ByteString.newCodedBuilder( |
- raw.getSerializedSize()); |
- CodedOutputStream output = out.getCodedOutput(); |
- List<RawMessageSet.Item> items = raw.getItemList(); |
- for (int i = 0; i < items.size(); i++) { |
- RawMessageSet.Item item = items.get(i); |
- output.writeTag(1, WireFormat.WIRETYPE_START_GROUP); |
- output.writeBytes(3, item.getMessage()); |
- output.writeInt32(2, item.getTypeId()); |
- output.writeTag(1, WireFormat.WIRETYPE_END_GROUP); |
- } |
- ByteString data = out.build(); |
- |
- // Merge bytes into TestMessageSet and check the contents. |
- TestMessageSet messageSet = |
- TestMessageSet.newBuilder().mergeFrom(data, extensionRegistry).build(); |
- assertEquals(123, messageSet.getExtension( |
- TestMessageSetExtension1.messageSetExtension).getI()); |
- } |
- |
- // ================================================================ |
- // oneof |
- public void testOneofWireFormat() throws Exception { |
- TestOneof2.Builder builder = TestOneof2.newBuilder(); |
- TestUtil.setOneof(builder); |
- TestOneof2 message = builder.build(); |
- ByteString rawBytes = message.toByteString(); |
- |
- assertEquals(rawBytes.size(), message.getSerializedSize()); |
- |
- TestOneof2 message2 = TestOneof2.parseFrom(rawBytes); |
- TestUtil.assertOneofSet(message2); |
- } |
- |
- public void testOneofOnlyLastSet() throws Exception { |
- TestOneofBackwardsCompatible source = TestOneofBackwardsCompatible |
- .newBuilder().setFooInt(100).setFooString("101").build(); |
- |
- ByteString rawBytes = source.toByteString(); |
- TestOneof2 message = TestOneof2.parseFrom(rawBytes); |
- assertFalse(message.hasFooInt()); |
- assertTrue(message.hasFooString()); |
- } |
} |