source: josm/trunk/test/unit/org/openstreetmap/josm/data/protobuf/ProtobufParserTest.java@ 17862

Last change on this file since 17862 was 17862, checked in by simon04, 3 years ago

fix #17177 - Add support for Mapbox Vector Tile (patch by taylor.smock)

Signed-off-by: Taylor Smock <tsmock@…>

File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.protobuf;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5
6import org.junit.jupiter.api.Test;
7
8/**
9 * Test class for {@link ProtobufParser}
10 * @author Taylor Smock
11 * @since xxx
12 */
13class ProtobufParserTest {
14 /**
15 * Check that we are appropriately converting values to the "smallest" type
16 */
17 @Test
18 void testConvertLong() {
19 // No casting due to auto conversions
20 assertEquals(Byte.MAX_VALUE, ProtobufParser.convertLong(Byte.MAX_VALUE));
21 assertEquals(Byte.MIN_VALUE, ProtobufParser.convertLong(Byte.MIN_VALUE));
22 assertEquals(Short.MIN_VALUE, ProtobufParser.convertLong(Short.MIN_VALUE));
23 assertEquals(Short.MAX_VALUE, ProtobufParser.convertLong(Short.MAX_VALUE));
24 assertEquals(Integer.MAX_VALUE, ProtobufParser.convertLong(Integer.MAX_VALUE));
25 assertEquals(Integer.MIN_VALUE, ProtobufParser.convertLong(Integer.MIN_VALUE));
26 assertEquals(Long.MIN_VALUE, ProtobufParser.convertLong(Long.MIN_VALUE));
27 assertEquals(Long.MAX_VALUE, ProtobufParser.convertLong(Long.MAX_VALUE));
28 }
29
30 /**
31 * Check that zig zags are appropriately encoded.
32 */
33 @Test
34 void testEncodeZigZag() {
35 assertEquals(0, ProtobufParser.encodeZigZag(0).byteValue());
36 assertEquals(1, ProtobufParser.encodeZigZag(-1).byteValue());
37 assertEquals(2, ProtobufParser.encodeZigZag(1).byteValue());
38 assertEquals(3, ProtobufParser.encodeZigZag(-2).byteValue());
39 assertEquals(254, ProtobufParser.encodeZigZag(Byte.MAX_VALUE).shortValue());
40 assertEquals(255, ProtobufParser.encodeZigZag(Byte.MIN_VALUE).shortValue());
41 assertEquals(65_534, ProtobufParser.encodeZigZag(Short.MAX_VALUE).intValue());
42 assertEquals(65_535, ProtobufParser.encodeZigZag(Short.MIN_VALUE).intValue());
43 // These integers check a possible boundary condition (the boundary between using the 32/64 bit encoding methods)
44 assertEquals(4_294_967_292L, ProtobufParser.encodeZigZag(Integer.MAX_VALUE - 1).longValue());
45 assertEquals(4_294_967_293L, ProtobufParser.encodeZigZag(Integer.MIN_VALUE + 1).longValue());
46 assertEquals(4_294_967_294L, ProtobufParser.encodeZigZag(Integer.MAX_VALUE).longValue());
47 assertEquals(4_294_967_295L, ProtobufParser.encodeZigZag(Integer.MIN_VALUE).longValue());
48 assertEquals(4_294_967_296L, ProtobufParser.encodeZigZag(Integer.MAX_VALUE + 1L).longValue());
49 assertEquals(4_294_967_297L, ProtobufParser.encodeZigZag(Integer.MIN_VALUE - 1L).longValue());
50 }
51}
Note: See TracBrowser for help on using the repository browser.