Index: third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteTest.java |
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteTest.java |
index 88c3e0b2a37c273425b60ab9582fdd9ea8eb9679..538432f7c1b1e833460d0ccbf9fe4f3f74071465 100644 |
--- a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteTest.java |
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteTest.java |
@@ -35,7 +35,6 @@ import static java.util.Collections.singletonList; |
import com.google.protobuf.UnittestImportLite.ImportEnumLite; |
import com.google.protobuf.UnittestImportPublicLite.PublicImportMessageLite; |
-import com.google.protobuf.UnittestLite; |
import com.google.protobuf.UnittestLite.ForeignEnumLite; |
import com.google.protobuf.UnittestLite.ForeignMessageLite; |
import com.google.protobuf.UnittestLite.TestAllExtensionsLite; |
@@ -46,21 +45,15 @@ import com.google.protobuf.UnittestLite.TestAllTypesLite.OneofFieldCase; |
import com.google.protobuf.UnittestLite.TestAllTypesLite.OptionalGroup; |
import com.google.protobuf.UnittestLite.TestAllTypesLite.RepeatedGroup; |
import com.google.protobuf.UnittestLite.TestAllTypesLiteOrBuilder; |
+import com.google.protobuf.UnittestLite.TestHugeFieldNumbersLite; |
import com.google.protobuf.UnittestLite.TestNestedExtensionLite; |
import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Bar; |
import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.BarPrime; |
import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Foo; |
import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.TestOneofEquals; |
import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.TestRecursiveOneof; |
- |
import junit.framework.TestCase; |
-import java.io.ByteArrayInputStream; |
-import java.io.ByteArrayOutputStream; |
-import java.io.NotSerializableException; |
-import java.io.ObjectInputStream; |
-import java.io.ObjectOutputStream; |
- |
/** |
* Test lite runtime. |
* |
@@ -139,7 +132,6 @@ public class LiteTest extends TestCase { |
UnittestLite.optionalNestedMessageExtensionLite).getBb()); |
} |
- |
public void testClone() { |
TestAllTypesLite.Builder expected = TestAllTypesLite.newBuilder() |
.setOptionalInt32(123); |
@@ -1433,6 +1425,12 @@ public class LiteTest extends TestCase { |
assertToStringEquals("", TestAllTypesLite.getDefaultInstance()); |
} |
+ public void testToStringScalarFieldsSuffixedWithList() throws Exception { |
+ assertToStringEquals("deceptively_named_list: 7", TestAllTypesLite.newBuilder() |
+ .setDeceptivelyNamedList(7) |
+ .build()); |
+ } |
+ |
public void testToStringPrimitives() throws Exception { |
TestAllTypesLite proto = TestAllTypesLite.newBuilder() |
.setOptionalInt32(1) |
@@ -1630,7 +1628,7 @@ public class LiteTest extends TestCase { |
fail(); |
} catch (InvalidProtocolBufferException expected) {} |
} |
- |
+ |
public void testMergeFrom_sanity() throws Exception { |
TestAllTypesLite one = TestUtilLite.getAllLiteSetBuilder().build(); |
byte[] bytes = one.toByteArray(); |
@@ -1642,7 +1640,19 @@ public class LiteTest extends TestCase { |
assertEquals(two, one); |
assertEquals(one.hashCode(), two.hashCode()); |
} |
- |
+ |
+ public void testMergeFromNoLazyFieldSharing() throws Exception { |
+ TestAllTypesLite.Builder sourceBuilder = TestAllTypesLite.newBuilder().setOptionalLazyMessage( |
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(1)); |
+ TestAllTypesLite.Builder targetBuilder = |
+ TestAllTypesLite.newBuilder().mergeFrom(sourceBuilder.build()); |
+ assertEquals(1, sourceBuilder.getOptionalLazyMessage().getBb()); |
+ // now change the sourceBuilder, and target value shouldn't be affected. |
+ sourceBuilder.setOptionalLazyMessage( |
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(2)); |
+ assertEquals(1, targetBuilder.getOptionalLazyMessage().getBb()); |
+ } |
+ |
public void testEquals_notEqual() throws Exception { |
TestAllTypesLite one = TestUtilLite.getAllLiteSetBuilder().build(); |
byte[] bytes = one.toByteArray(); |
@@ -2202,6 +2212,21 @@ public class LiteTest extends TestCase { |
assertEqualsAndHashCodeAreFalse(fooWithOnlyValue, fooWithValueAndUnknownFields); |
assertEqualsAndHashCodeAreFalse(fooWithValueAndExtension, fooWithValueAndUnknownFields); |
} |
+ |
+ public void testEqualsAndHashCodeWithExtensions() throws InvalidProtocolBufferException { |
+ Foo fooWithOnlyValue = Foo.newBuilder() |
+ .setValue(1) |
+ .build(); |
+ |
+ Foo fooWithValueAndExtension = fooWithOnlyValue.toBuilder() |
+ .setValue(1) |
+ .setExtension(Bar.fooExt, Bar.newBuilder() |
+ .setName("name") |
+ .build()) |
+ .build(); |
+ |
+ assertEqualsAndHashCodeAreFalse(fooWithOnlyValue, fooWithValueAndExtension); |
+ } |
// Test to ensure we avoid a class cast exception with oneofs. |
public void testEquals_oneOfMessages() { |
@@ -2217,6 +2242,25 @@ public class LiteTest extends TestCase { |
assertFalse(other.equals(mine)); |
} |
+ public void testHugeFieldNumbers() throws InvalidProtocolBufferException { |
+ TestHugeFieldNumbersLite message = |
+ TestHugeFieldNumbersLite.newBuilder() |
+ .setOptionalInt32(1) |
+ .addRepeatedInt32(2) |
+ .setOptionalEnum(ForeignEnumLite.FOREIGN_LITE_FOO) |
+ .setOptionalString("xyz") |
+ .setOptionalMessage(ForeignMessageLite.newBuilder().setC(3).build()) |
+ .build(); |
+ |
+ TestHugeFieldNumbersLite parsedMessage = |
+ TestHugeFieldNumbersLite.parseFrom(message.toByteArray()); |
+ assertEquals(1, parsedMessage.getOptionalInt32()); |
+ assertEquals(2, parsedMessage.getRepeatedInt32(0)); |
+ assertEquals(ForeignEnumLite.FOREIGN_LITE_FOO, parsedMessage.getOptionalEnum()); |
+ assertEquals("xyz", parsedMessage.getOptionalString()); |
+ assertEquals(3, parsedMessage.getOptionalMessage().getC()); |
+ } |
+ |
private void assertEqualsAndHashCodeAreFalse(Object o1, Object o2) { |
assertFalse(o1.equals(o2)); |
assertFalse(o1.hashCode() == o2.hashCode()); |