Skip to content

Commit 7e4322d

Browse files
committed
Added test of decoded data in Reader
1 parent 44cf3e3 commit 7e4322d

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,54 @@ public void testNoIpV4SearchTree() throws IOException, URISyntaxException {
6161
.textValue());
6262
}
6363

64+
@Test
65+
public void testDecodingTypes() 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("::1.1.1.0"));
71+
72+
assertEquals(true, record.get("boolean").booleanValue());
73+
74+
assertArrayEquals(new byte[] { 0, 0, 0, (byte) 42 }, record
75+
.get("bytes").binaryValue());
76+
77+
assertEquals("unicode! ☯ - ♫", record.get("utf8_string").textValue());
78+
79+
assertTrue(record.get("array").isArray());
80+
JsonNode array = record.get("array");
81+
assertEquals(3, array.size());
82+
assertEquals(3, array.size());
83+
assertEquals(1, array.get(0).intValue());
84+
assertEquals(2, array.get(1).intValue());
85+
assertEquals(3, array.get(2).intValue());
86+
87+
assertTrue(record.get("map").isObject());
88+
assertEquals(1, record.get("map").size());
89+
90+
JsonNode mapX = record.get("map").get("mapX");
91+
assertEquals(2, mapX.size());
92+
93+
JsonNode arrayX = mapX.get("arrayX");
94+
assertEquals(3, arrayX.size());
95+
assertEquals(7, arrayX.get(0).intValue());
96+
assertEquals(8, arrayX.get(1).intValue());
97+
assertEquals(9, arrayX.get(2).intValue());
98+
99+
assertEquals("hello", mapX.get("utf8_stringX").textValue());
100+
101+
assertEquals(42.123456, record.get("double").doubleValue(), 0.000000001);
102+
assertEquals(1.1, record.get("float").floatValue(), 0.000001);
103+
assertEquals(-268435456, record.get("int32").intValue());
104+
assertEquals(100, record.get("uint16").intValue());
105+
assertEquals(268435456, record.get("uint32").intValue());
106+
assertEquals(new BigInteger("1152921504606846976"), record
107+
.get("uint64").bigIntegerValue());
108+
assertEquals(new BigInteger("1329227995784915872903807060280344576"),
109+
record.get("uint128").bigIntegerValue());
110+
}
111+
64112
@Test
65113
public void testZeros() throws URISyntaxException, IOException {
66114
URI file = ReaderTest.class.getResource(

0 commit comments

Comments
 (0)