Changeset 18826 in josm for trunk/test/unit/org/openstreetmap/josm/data/protobuf
- Timestamp:
- 2023-09-12T18:04:57+02:00 (19 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/protobuf/ProtobufParserTest.java
r17867 r18826 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 5 6 import java.util.stream.Stream; 7 6 8 import org.junit.jupiter.api.Test; 9 import org.junit.jupiter.params.ParameterizedTest; 10 import org.junit.jupiter.params.provider.Arguments; 11 import org.junit.jupiter.params.provider.MethodSource; 7 12 8 13 /** … … 49 54 assertEquals(4_294_967_297L, ProtobufParser.encodeZigZag(Integer.MIN_VALUE - 1L).longValue()); 50 55 } 56 57 static Stream<Arguments> testDecode() { 58 return Stream.of( 59 Arguments.of(21L, 42L), 60 Arguments.of(9223372036854775785L, -46L) 61 ); 62 } 63 64 @ParameterizedTest 65 @MethodSource 66 void testDecode(long expected, long toDecode) { 67 assertEquals(expected, ProtobufParser.decodeZigZag(toDecode)); 68 } 69 70 static Stream<Arguments> testDecodeVarInt() { 71 return Stream.of( 72 Arguments.of(1, new int[] {0x01}), 73 Arguments.of(150, new int[] {0x96, 0x01}), 74 Arguments.of(9223372036854775806L, new int[] {0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}), 75 Arguments.of(Long.MAX_VALUE, new int[] {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}) 76 ); 77 } 78 79 @ParameterizedTest 80 @MethodSource 81 void testDecodeVarInt(long expected, int[] bytes) { 82 // Drop most significant bit 83 for (int i = 0; i < bytes.length; i++) { 84 bytes[i] = bytes[i] & 0x7F; 85 } 86 assertEquals(expected, ProtobufParser.convertByteArray(ProtobufTest.toByteArray(bytes), (byte) 7, 0, bytes.length)); 87 } 51 88 }
Note:
See TracChangeset
for help on using the changeset viewer.