diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2015-02-05 14:52:17 -0800 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2015-02-05 14:52:17 -0800 |
commit | bd3573cb096cb8f0ec4bf29f0e11744a06a9e5a6 (patch) | |
tree | 8114227aef1743eb20cdf6022fb1cebb9992c9d6 /javanano/src/test | |
parent | ca35a8030339d85cb4efb928b1aae8e38584d214 (diff) | |
download | protobuf-bd3573cb096cb8f0ec4bf29f0e11744a06a9e5a6.tar.gz protobuf-bd3573cb096cb8f0ec4bf29f0e11744a06a9e5a6.tar.bz2 protobuf-bd3573cb096cb8f0ec4bf29f0e11744a06a9e5a6.zip |
Fix the behavior when merging conflicting keys, the new value always
override the existing one even for message types.
Diffstat (limited to 'javanano/src/test')
-rw-r--r-- | javanano/src/test/java/com/google/protobuf/nano/NanoTest.java | 28 | ||||
-rw-r--r-- | javanano/src/test/java/com/google/protobuf/nano/map_test.proto | 1 |
2 files changed, 28 insertions, 1 deletions
diff --git a/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java b/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java index a7383cb4..bf8a391a 100644 --- a/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java +++ b/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java @@ -3742,7 +3742,6 @@ public class NanoTest extends TestCase { byte[] output = MessageNano.toByteArray(origin); TestMap parsed = new TestMap(); MessageNano.mergeFrom(parsed, output); - // TODO(liujisi): Test merging message type values. // TODO(liujisi): Test missing key/value in parsing. } @@ -3769,6 +3768,33 @@ public class NanoTest extends TestCase { } } + /** + * Tests that merging bytes containing conflicting keys with override the + * message value instead of merging the message value into the existing entry. + */ + public void testMapMergeOverrideMessageValues() throws Exception { + TestMap.MessageValue origValue = new TestMap.MessageValue(); + origValue.value = 1; + origValue.value2 = 2; + TestMap.MessageValue newValue = new TestMap.MessageValue(); + newValue.value = 3; + + TestMap origMessage = new TestMap(); + origMessage.int32ToMessageField = + new HashMap<Integer, MapTestProto.TestMap.MessageValue>(); + origMessage.int32ToMessageField.put(1, origValue); + + TestMap newMessage = new TestMap(); + newMessage.int32ToMessageField = + new HashMap<Integer, MapTestProto.TestMap.MessageValue>(); + newMessage.int32ToMessageField.put(1, newValue); + MessageNano.mergeFrom(origMessage, + MessageNano.toByteArray(newMessage)); + TestMap.MessageValue mergedValue = origMessage.int32ToMessageField.get(1); + assertEquals(3, mergedValue.value); + assertEquals(0, mergedValue.value2); + } + private static final Integer[] int32Values = new Integer[] { 0, 1, -1, Integer.MAX_VALUE, Integer.MIN_VALUE, }; diff --git a/javanano/src/test/java/com/google/protobuf/nano/map_test.proto b/javanano/src/test/java/com/google/protobuf/nano/map_test.proto index 5ea86717..f72833ad 100644 --- a/javanano/src/test/java/com/google/protobuf/nano/map_test.proto +++ b/javanano/src/test/java/com/google/protobuf/nano/map_test.proto @@ -38,6 +38,7 @@ option java_outer_classname = "MapTestProto"; message TestMap { message MessageValue { int32 value = 1; + int32 value2 = 2; } enum EnumValue { FOO = 0; |