diff options
author | Max Cai <maxtroy@google.com> | 2013-11-06 17:35:06 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2013-11-06 17:35:07 +0000 |
commit | 8a15121c1077fe883f428bd27dee6b99e06e48b6 (patch) | |
tree | 461e3f0b97a639536d0b3b34e748eeefc8890917 /java | |
parent | bb971d53626cb286f8dc491c15d2731001c4891b (diff) | |
parent | beb57e08a44a140bf52235717f1f907ca857f360 (diff) | |
download | external_protobuf-8a15121c1077fe883f428bd27dee6b99e06e48b6.zip external_protobuf-8a15121c1077fe883f428bd27dee6b99e06e48b6.tar.gz external_protobuf-8a15121c1077fe883f428bd27dee6b99e06e48b6.tar.bz2 |
Merge "Allow for ref-type arrays containing null elements."
Diffstat (limited to 'java')
-rw-r--r-- | java/src/test/java/com/google/protobuf/NanoTest.java | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java index b9061e9..68d2c45 100644 --- a/java/src/test/java/com/google/protobuf/NanoTest.java +++ b/java/src/test/java/com/google/protobuf/NanoTest.java @@ -2724,8 +2724,6 @@ public class NanoTest extends TestCase { // Complete equality for messages with accessors: TestNanoAccessors f = createMessageWithAccessorsForHashCodeEqualsTest(); TestNanoAccessors fEquivalent = createMessageWithAccessorsForHashCodeEqualsTest(); - System.out.println("equals: " + f.equals(fEquivalent)); - System.out.println("hashCode: " + f.hashCode() + " vs " + fEquivalent.hashCode()); // If using accessors, explicitly setting a field to its default value // should make the message different. @@ -2965,6 +2963,37 @@ public class NanoTest extends TestCase { assertEquals(TestAllTypesNano.BAR, message.repeatedPackedNestedEnum[1]); } + public void testNullRepeatedFieldElements() throws Exception { + // Check that serialization with null array elements doesn't NPE. + String string1 = "1"; + String string2 = "2"; + byte[] bytes1 = {3, 4}; + byte[] bytes2 = {5, 6}; + TestAllTypesNano.NestedMessage msg1 = new TestAllTypesNano.NestedMessage(); + msg1.bb = 7; + TestAllTypesNano.NestedMessage msg2 = new TestAllTypesNano.NestedMessage(); + msg2.bb = 8; + + TestAllTypesNano message = new TestAllTypesNano(); + message.repeatedString = new String[] {null, string1, string2}; + message.repeatedBytes = new byte[][] {bytes1, null, bytes2}; + message.repeatedNestedMessage = new TestAllTypesNano.NestedMessage[] {msg1, msg2, null}; + message.repeatedGroup = new TestAllTypesNano.RepeatedGroup[] {null, null, null}; + + byte[] serialized = MessageNano.toByteArray(message); // should not NPE + TestAllTypesNano deserialized = MessageNano.mergeFrom(new TestAllTypesNano(), serialized); + assertEquals(2, deserialized.repeatedString.length); + assertEquals(string1, deserialized.repeatedString[0]); + assertEquals(string2, deserialized.repeatedString[1]); + assertEquals(2, deserialized.repeatedBytes.length); + assertTrue(Arrays.equals(bytes1, deserialized.repeatedBytes[0])); + assertTrue(Arrays.equals(bytes2, deserialized.repeatedBytes[1])); + assertEquals(2, deserialized.repeatedNestedMessage.length); + assertEquals(msg1.bb, deserialized.repeatedNestedMessage[0].bb); + assertEquals(msg2.bb, deserialized.repeatedNestedMessage[1].bb); + assertEquals(0, deserialized.repeatedGroup.length); + } + public void testRepeatedMerge() throws Exception { // Check that merging repeated fields cause the arrays to expand with // new data. |