aboutsummaryrefslogtreecommitdiffhomepage
path: root/javanano/src/test
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2015-02-05 15:23:37 -0800
committerGravatar Jisi Liu <jisi.liu@gmail.com>2015-02-05 15:23:37 -0800
commit7f3693184ae098b18dc7b136e26c723cf6ab45a5 (patch)
tree3a82871821dc4c31c30b011c4e0684122b13804c /javanano/src/test
parentbd3573cb096cb8f0ec4bf29f0e11744a06a9e5a6 (diff)
Add tests merging empty entries in JavaNano map
Diffstat (limited to 'javanano/src/test')
-rw-r--r--javanano/src/test/java/com/google/protobuf/nano/NanoTest.java30
1 files changed, 30 insertions, 0 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 bf8a391a..d7de331f 100644
--- a/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
+++ b/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
@@ -3795,6 +3795,36 @@ public class NanoTest extends TestCase {
assertEquals(0, mergedValue.value2);
}
+ /**
+ * Tests that when merging with empty entries,
+ * we will use default for the key and value, instead of null.
+ */
+ public void testMapMergeEmptyEntry() throws Exception {
+ TestMap testMap = new TestMap();
+ byte[] buffer = new byte[1024];
+ CodedOutputByteBufferNano output =
+ CodedOutputByteBufferNano.newInstance(buffer);
+ // An empty entry for int32_to_int32 map.
+ output.writeTag(1, WireFormatNano.WIRETYPE_LENGTH_DELIMITED);
+ output.writeRawVarint32(0);
+ // An empty entry for int32_to_message map.
+ output.writeTag(5, WireFormatNano.WIRETYPE_LENGTH_DELIMITED);
+ output.writeRawVarint32(0);
+
+ CodedInputByteBufferNano input = CodedInputByteBufferNano.newInstance(
+ buffer, 0, buffer.length - output.spaceLeft());
+ testMap.mergeFrom(input);
+ assertNotNull(testMap.int32ToInt32Field);;
+ assertEquals(1, testMap.int32ToInt32Field.size());
+ assertEquals(Integer.valueOf(0), testMap.int32ToInt32Field.get(0));
+ assertNotNull(testMap.int32ToMessageField);
+ assertEquals(1, testMap.int32ToMessageField.size());
+ TestMap.MessageValue messageValue = testMap.int32ToMessageField.get(0);
+ assertNotNull(messageValue);
+ assertEquals(0, messageValue.value);
+ assertEquals(0, messageValue.value2);
+ }
+
private static final Integer[] int32Values = new Integer[] {
0, 1, -1, Integer.MAX_VALUE, Integer.MIN_VALUE,
};