Index: third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnknownFieldSetTest.java |
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnknownFieldSetTest.java |
similarity index 63% |
copy from third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java |
copy to third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnknownFieldSetTest.java |
index 32380f700ac0fce21fb52b6bb076176be2e008bc..b9bfb691b1ef3c6571a9abe1a5db9cc05d959683 100644 |
--- a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java |
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnknownFieldSetTest.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,16 +28,14 @@ |
// (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 protobuf_unittest.UnittestProto; |
-import protobuf_unittest.UnittestProto.ForeignEnum; |
import protobuf_unittest.UnittestProto.TestAllExtensions; |
import protobuf_unittest.UnittestProto.TestAllTypes; |
import protobuf_unittest.UnittestProto.TestEmptyMessage; |
import protobuf_unittest.UnittestProto.TestEmptyMessageWithExtensions; |
-import protobuf_unittest.UnittestProto.TestPackedExtensions; |
-import protobuf_unittest.UnittestProto.TestPackedTypes; |
import junit.framework.TestCase; |
@@ -50,7 +48,6 @@ import java.util.Map; |
* @author kenton@google.com (Kenton Varda) |
*/ |
public class UnknownFieldSetTest extends TestCase { |
- @Override |
public void setUp() throws Exception { |
descriptor = TestAllTypes.getDescriptor(); |
allFields = TestUtil.getAllSet(); |
@@ -208,13 +205,6 @@ public class UnknownFieldSetTest extends TestCase { |
TestEmptyMessage.newBuilder().mergeFrom(emptyMessage).clear().build(); |
assertEquals(0, message.getSerializedSize()); |
} |
- |
- public void testClearField() throws Exception { |
- int fieldNumber = unknownFields.asMap().keySet().iterator().next(); |
- UnknownFieldSet fields = |
- UnknownFieldSet.newBuilder().mergeFrom(unknownFields).clearField(fieldNumber).build(); |
- assertFalse(fields.hasField(fieldNumber)); |
- } |
public void testParseKnownAndUnknown() throws Exception { |
// Test mixing known and unknown fields when parsing. |
@@ -445,210 +435,4 @@ public class UnknownFieldSetTest extends TestCase { |
assertEquals(copy, set); |
assertEquals(set.hashCode(), copy.hashCode()); |
} |
- |
- // ================================================================= |
- |
- public void testSerializeLite() throws Exception { |
- UnittestLite.TestEmptyMessageLite emptyMessageLite = |
- UnittestLite.TestEmptyMessageLite.parseFrom(allFieldsData); |
- assertEquals(allFieldsData.size(), emptyMessageLite.getSerializedSize()); |
- ByteString data = emptyMessageLite.toByteString(); |
- TestAllTypes message = TestAllTypes.parseFrom(data); |
- TestUtil.assertAllFieldsSet(message); |
- assertEquals(allFieldsData, data); |
- } |
- |
- public void testAllExtensionsLite() throws Exception { |
- TestAllExtensions allExtensions = TestUtil.getAllExtensionsSet(); |
- ByteString allExtensionsData = allExtensions.toByteString(); |
- UnittestLite.TestEmptyMessageLite emptyMessageLite = |
- UnittestLite.TestEmptyMessageLite.parser().parseFrom(allExtensionsData); |
- ByteString data = emptyMessageLite.toByteString(); |
- TestAllExtensions message = |
- TestAllExtensions.parseFrom(data, TestUtil.getExtensionRegistry()); |
- TestUtil.assertAllExtensionsSet(message); |
- assertEquals(allExtensionsData, data); |
- } |
- |
- public void testAllPackedFieldsLite() throws Exception { |
- TestPackedTypes allPackedFields = TestUtil.getPackedSet(); |
- ByteString allPackedData = allPackedFields.toByteString(); |
- UnittestLite.TestEmptyMessageLite emptyMessageLite = |
- UnittestLite.TestEmptyMessageLite.parseFrom(allPackedData); |
- ByteString data = emptyMessageLite.toByteString(); |
- TestPackedTypes message = |
- TestPackedTypes.parseFrom(data, TestUtil.getExtensionRegistry()); |
- TestUtil.assertPackedFieldsSet(message); |
- assertEquals(allPackedData, data); |
- } |
- |
- public void testAllPackedExtensionsLite() throws Exception { |
- TestPackedExtensions allPackedExtensions = TestUtil.getPackedExtensionsSet(); |
- ByteString allPackedExtensionsData = allPackedExtensions.toByteString(); |
- UnittestLite.TestEmptyMessageLite emptyMessageLite = |
- UnittestLite.TestEmptyMessageLite.parseFrom(allPackedExtensionsData); |
- ByteString data = emptyMessageLite.toByteString(); |
- TestPackedExtensions message = |
- TestPackedExtensions.parseFrom(data, TestUtil.getExtensionRegistry()); |
- TestUtil.assertPackedExtensionsSet(message); |
- assertEquals(allPackedExtensionsData, data); |
- } |
- |
- public void testCopyFromLite() throws Exception { |
- UnittestLite.TestEmptyMessageLite emptyMessageLite = |
- UnittestLite.TestEmptyMessageLite.parseFrom(allFieldsData); |
- UnittestLite.TestEmptyMessageLite emptyMessageLite2 = |
- UnittestLite.TestEmptyMessageLite.newBuilder() |
- .mergeFrom(emptyMessageLite).build(); |
- assertEquals(emptyMessageLite.toByteString(), emptyMessageLite2.toByteString()); |
- } |
- |
- public void testMergeFromLite() throws Exception { |
- TestAllTypes message1 = TestAllTypes.newBuilder() |
- .setOptionalInt32(1) |
- .setOptionalString("foo") |
- .addRepeatedString("bar") |
- .setOptionalNestedEnum(TestAllTypes.NestedEnum.BAZ) |
- .build(); |
- |
- TestAllTypes message2 = TestAllTypes.newBuilder() |
- .setOptionalInt64(2) |
- .setOptionalString("baz") |
- .addRepeatedString("qux") |
- .setOptionalForeignEnum(ForeignEnum.FOREIGN_BAZ) |
- .build(); |
- |
- ByteString data1 = message1.toByteString(); |
- UnittestLite.TestEmptyMessageLite emptyMessageLite1 = |
- UnittestLite.TestEmptyMessageLite.parseFrom(data1); |
- ByteString data2 = message2.toByteString(); |
- UnittestLite.TestEmptyMessageLite emptyMessageLite2 = |
- UnittestLite.TestEmptyMessageLite.parseFrom(data2); |
- |
- message1 = TestAllTypes.newBuilder(message1).mergeFrom(message2).build(); |
- emptyMessageLite1 = UnittestLite.TestEmptyMessageLite.newBuilder(emptyMessageLite1) |
- .mergeFrom(emptyMessageLite2).build(); |
- |
- data1 = emptyMessageLite1.toByteString(); |
- message2 = TestAllTypes.parseFrom(data1); |
- |
- assertEquals(message1, message2); |
- } |
- |
- public void testWrongTypeTreatedAsUnknownLite() throws Exception { |
- // Test that fields of the wrong wire type are treated like unknown fields |
- // when parsing. |
- |
- ByteString bizarroData = getBizarroData(); |
- TestAllTypes allTypesMessage = TestAllTypes.parseFrom(bizarroData); |
- UnittestLite.TestEmptyMessageLite emptyMessageLite = |
- UnittestLite.TestEmptyMessageLite.parseFrom(bizarroData); |
- ByteString data = emptyMessageLite.toByteString(); |
- TestAllTypes allTypesMessage2 = TestAllTypes.parseFrom(data); |
- |
- assertEquals(allTypesMessage.toString(), allTypesMessage2.toString()); |
- } |
- |
- public void testUnknownExtensionsLite() throws Exception { |
- // Make sure fields are properly parsed to the UnknownFieldSet even when |
- // they are declared as extension numbers. |
- |
- UnittestLite.TestEmptyMessageWithExtensionsLite message = |
- UnittestLite.TestEmptyMessageWithExtensionsLite.parseFrom(allFieldsData); |
- |
- assertEquals(allFieldsData, message.toByteString()); |
- } |
- |
- public void testWrongExtensionTypeTreatedAsUnknownLite() throws Exception { |
- // Test that fields of the wrong wire type are treated like unknown fields |
- // when parsing extensions. |
- |
- ByteString bizarroData = getBizarroData(); |
- TestAllExtensions allExtensionsMessage = |
- TestAllExtensions.parseFrom(bizarroData); |
- UnittestLite.TestEmptyMessageLite emptyMessageLite = |
- UnittestLite.TestEmptyMessageLite.parseFrom(bizarroData); |
- |
- // All fields should have been interpreted as unknown, so the byte strings |
- // should be the same. |
- assertEquals(emptyMessageLite.toByteString(), |
- allExtensionsMessage.toByteString()); |
- } |
- |
- public void testParseUnknownEnumValueLite() throws Exception { |
- Descriptors.FieldDescriptor singularField = |
- TestAllTypes.getDescriptor().findFieldByName("optional_nested_enum"); |
- Descriptors.FieldDescriptor repeatedField = |
- TestAllTypes.getDescriptor().findFieldByName("repeated_nested_enum"); |
- assertNotNull(singularField); |
- assertNotNull(repeatedField); |
- |
- ByteString data = |
- UnknownFieldSet.newBuilder() |
- .addField(singularField.getNumber(), |
- UnknownFieldSet.Field.newBuilder() |
- .addVarint(TestAllTypes.NestedEnum.BAR.getNumber()) |
- .addVarint(5) // not valid |
- .build()) |
- .addField(repeatedField.getNumber(), |
- UnknownFieldSet.Field.newBuilder() |
- .addVarint(TestAllTypes.NestedEnum.FOO.getNumber()) |
- .addVarint(4) // not valid |
- .addVarint(TestAllTypes.NestedEnum.BAZ.getNumber()) |
- .addVarint(6) // not valid |
- .build()) |
- .build() |
- .toByteString(); |
- |
- UnittestLite.TestEmptyMessageLite emptyMessageLite = |
- UnittestLite.TestEmptyMessageLite.parseFrom(data); |
- data = emptyMessageLite.toByteString(); |
- |
- { |
- TestAllTypes message = TestAllTypes.parseFrom(data); |
- assertEquals(TestAllTypes.NestedEnum.BAR, |
- message.getOptionalNestedEnum()); |
- assertEquals( |
- Arrays.asList(TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAZ), |
- message.getRepeatedNestedEnumList()); |
- assertEquals(Arrays.asList(5L), |
- message.getUnknownFields() |
- .getField(singularField.getNumber()) |
- .getVarintList()); |
- assertEquals(Arrays.asList(4L, 6L), |
- message.getUnknownFields() |
- .getField(repeatedField.getNumber()) |
- .getVarintList()); |
- } |
- |
- { |
- TestAllExtensions message = |
- TestAllExtensions.parseFrom(data, TestUtil.getExtensionRegistry()); |
- assertEquals(TestAllTypes.NestedEnum.BAR, |
- message.getExtension(UnittestProto.optionalNestedEnumExtension)); |
- assertEquals( |
- Arrays.asList(TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAZ), |
- message.getExtension(UnittestProto.repeatedNestedEnumExtension)); |
- assertEquals(Arrays.asList(5L), |
- message.getUnknownFields() |
- .getField(singularField.getNumber()) |
- .getVarintList()); |
- assertEquals(Arrays.asList(4L, 6L), |
- message.getUnknownFields() |
- .getField(repeatedField.getNumber()) |
- .getVarintList()); |
- } |
- } |
- |
- public void testClearLite() throws Exception { |
- UnittestLite.TestEmptyMessageLite emptyMessageLite1 = |
- UnittestLite.TestEmptyMessageLite.parseFrom(allFieldsData); |
- UnittestLite.TestEmptyMessageLite emptyMessageLite2 = |
- UnittestLite.TestEmptyMessageLite.newBuilder() |
- .mergeFrom(emptyMessageLite1).clear().build(); |
- assertEquals(0, emptyMessageLite2.getSerializedSize()); |
- ByteString data = emptyMessageLite2.toByteString(); |
- assertEquals(0, data.size()); |
- } |
- |
} |