Skip to content

Commit 44cf3e3

Browse files
committed
Added tests of zero-length data
1 parent 61f9844 commit 44cf3e3

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/main/java/com/maxmind/maxminddb/Metadata.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public Metadata(JsonNode metadata) {
3232
this.recordSize = metadata.get("record_size").asInt();
3333
this.nodeByteSize = this.recordSize / 4;
3434
this.searchTreeSize = this.nodeCount * this.nodeByteSize;
35-
3635
}
3736

3837
/*

src/test/java/com/maxmind/maxminddb/ReaderTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.maxmind.maxminddb;
22

3+
import static org.junit.Assert.assertArrayEquals;
34
import static org.junit.Assert.assertEquals;
45
import static org.junit.Assert.assertNull;
6+
import static org.junit.Assert.assertTrue;
57

68
import java.io.File;
79
import java.io.IOException;
10+
import java.math.BigInteger;
811
import java.net.InetAddress;
912
import java.net.URI;
1013
import java.net.URISyntaxException;
@@ -13,6 +16,7 @@
1316

1417
import org.junit.Test;
1518

19+
import com.fasterxml.jackson.databind.JsonNode;
1620
import com.fasterxml.jackson.databind.ObjectMapper;
1721
import com.fasterxml.jackson.databind.node.ObjectNode;
1822

@@ -57,6 +61,35 @@ public void testNoIpV4SearchTree() throws IOException, URISyntaxException {
5761
.textValue());
5862
}
5963

64+
@Test
65+
public void testZeros() throws URISyntaxException, IOException {
66+
URI file = ReaderTest.class.getResource(
67+
"/maxmind-db/test-data/MaxMind-DB-test-decoder.mmdb").toURI();
68+
69+
MaxMindDbReader reader = new MaxMindDbReader(new File(file));
70+
JsonNode record = reader.get(InetAddress.getByName("::"));
71+
72+
assertEquals(false, record.get("boolean").booleanValue());
73+
74+
assertArrayEquals(new byte[0], record.get("bytes").binaryValue());
75+
76+
assertEquals("", record.get("utf8_string").textValue());
77+
78+
assertTrue(record.get("array").isArray());
79+
assertEquals(0, record.get("array").size());
80+
81+
assertTrue(record.get("map").isObject());
82+
assertEquals(0, record.get("map").size());
83+
84+
assertEquals(0, record.get("double").doubleValue(), 0.000000001);
85+
assertEquals(0, record.get("float").floatValue(), 0.000001);
86+
assertEquals(0, record.get("int32").intValue());
87+
assertEquals(0, record.get("uint16").intValue());
88+
assertEquals(0, record.get("uint32").intValue());
89+
assertEquals(BigInteger.ZERO, record.get("uint64").bigIntegerValue());
90+
assertEquals(BigInteger.ZERO, record.get("uint128").bigIntegerValue());
91+
}
92+
6093
private void testMetadata(MaxMindDbReader reader, int ipVersion,
6194
long recordSize) {
6295

0 commit comments

Comments
 (0)