diff options
author | Ulas Kirazci <ulas@google.com> | 2013-07-29 11:08:34 -0700 |
---|---|---|
committer | Ulas Kirazci <ulas@google.com> | 2013-07-31 14:15:10 -0700 |
commit | 14dd1f02ac95f61087e311bf61c85047fb218a29 (patch) | |
tree | 06d4b7f14f54763ac1fd96a2315549e18fbb0a1c /java | |
parent | 021f8f1badf1c4db519e3f35d600dec4b5c52eff (diff) | |
download | external_protobuf-14dd1f02ac95f61087e311bf61c85047fb218a29.zip external_protobuf-14dd1f02ac95f61087e311bf61c85047fb218a29.tar.gz external_protobuf-14dd1f02ac95f61087e311bf61c85047fb218a29.tar.bz2 |
Fixed packed repeated serialization.
Remove buggy memoization. Memoization also is too fragile for the api
because the repeated field is public.
Change-Id: I538b8426d274b22df2eeea5935023abbe7df49fe
Diffstat (limited to 'java')
-rw-r--r-- | java/src/test/java/com/google/protobuf/NanoTest.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java index 0ea80d4..edb0a20 100644 --- a/java/src/test/java/com/google/protobuf/NanoTest.java +++ b/java/src/test/java/com/google/protobuf/NanoTest.java @@ -46,6 +46,7 @@ import com.google.protobuf.nano.UnittestImportNano; import junit.framework.TestCase; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -1955,6 +1956,24 @@ public class NanoTest extends TestCase { assertEquals(TestAllTypesNano.BAR, msg.repeatedPackedNestedEnum[1]); } + public void testNanoRepeatedPackedSerializedSize() throws Exception { + TestAllTypesNano msg = new TestAllTypesNano(); + msg.repeatedPackedInt32 = new int[] { 123, 789, 456 }; + int msgSerializedSize = msg.getSerializedSize(); + byte [] result = MessageNano.toByteArray(msg); + //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length); + assertTrue(msgSerializedSize == 11); + assertEquals(result.length, msgSerializedSize); + TestAllTypesNano msg2 = new TestAllTypesNano(); + msg2.repeatedPackedInt32 = new int[] { 123, 789, 456 }; + byte [] result2 = new byte[msgSerializedSize]; + MessageNano.toByteArray(msg2, result2, 0, msgSerializedSize); + + // Check equal size and content. + assertEquals(msgSerializedSize, msg2.getSerializedSize()); + assertTrue(Arrays.equals(result, result2)); + } + public void testNanoRepeatedInt32ReMerge() throws Exception { TestAllTypesNano msg = new TestAllTypesNano(); msg.repeatedInt32 = new int[] { 234 }; |