|
1 | 1 | package com.maxmind.maxminddb; |
2 | 2 |
|
| 3 | +import static org.junit.Assert.assertArrayEquals; |
3 | 4 | import static org.junit.Assert.assertEquals; |
4 | 5 | import static org.junit.Assert.assertNull; |
| 6 | +import static org.junit.Assert.assertTrue; |
5 | 7 |
|
6 | 8 | import java.io.File; |
7 | 9 | import java.io.IOException; |
| 10 | +import java.math.BigInteger; |
8 | 11 | import java.net.InetAddress; |
9 | 12 | import java.net.URI; |
10 | 13 | import java.net.URISyntaxException; |
|
13 | 16 |
|
14 | 17 | import org.junit.Test; |
15 | 18 |
|
| 19 | +import com.fasterxml.jackson.databind.JsonNode; |
16 | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
17 | 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
18 | 22 |
|
@@ -57,6 +61,35 @@ public void testNoIpV4SearchTree() throws IOException, URISyntaxException { |
57 | 61 | .textValue()); |
58 | 62 | } |
59 | 63 |
|
| 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 | + |
60 | 93 | private void testMetadata(MaxMindDbReader reader, int ipVersion, |
61 | 94 | long recordSize) { |
62 | 95 |
|
|
0 commit comments