Changeset 18826 in josm for trunk/test/unit


Ignore:
Timestamp:
2023-09-12T18:04:57+02:00 (15 months ago)
Author:
taylor.smock
Message:

Fix #23165: Cannot assign a changesetId > 0 to a new primitive

There were two problems:

  1. Using Number.intValue instead of Number.longValue
  2. Using >> instead of >>> (bit shift)
Location:
trunk/test/unit/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/protobuf/ProtobufParserTest.java

    r17867 r18826  
    44import static org.junit.jupiter.api.Assertions.assertEquals;
    55
     6import java.util.stream.Stream;
     7
    68import org.junit.jupiter.api.Test;
     9import org.junit.jupiter.params.ParameterizedTest;
     10import org.junit.jupiter.params.provider.Arguments;
     11import org.junit.jupiter.params.provider.MethodSource;
    712
    813/**
     
    4954        assertEquals(4_294_967_297L, ProtobufParser.encodeZigZag(Integer.MIN_VALUE - 1L).longValue());
    5055    }
     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    }
    5188}
  • trunk/test/unit/org/openstreetmap/josm/gui/io/importexport/OsmPbfImporterTest.java

    r18695 r18826  
    55import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    66import static org.junit.jupiter.api.Assertions.assertEquals;
     7import static org.junit.jupiter.api.Assertions.assertNotNull;
    78import static org.junit.jupiter.api.Assertions.assertSame;
    89import static org.junit.jupiter.api.Assertions.assertThrows;
     
    1819import org.junit.jupiter.api.BeforeAll;
    1920import org.junit.jupiter.api.Test;
     21import org.junit.jupiter.params.ParameterizedTest;
     22import org.junit.jupiter.params.provider.ValueSource;
    2023import org.openstreetmap.josm.TestUtils;
    2124import org.openstreetmap.josm.data.coor.ILatLon;
     
    2326import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    2427import org.openstreetmap.josm.data.osm.DataSet;
     28import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    2529import org.openstreetmap.josm.data.osm.Relation;
    2630import org.openstreetmap.josm.data.osm.Way;
     
    130134        }
    131135    }
     136
     137    @Test
     138    void testIdParsing() throws IOException, IllegalDataException {
     139        final DataSet dataSet;
     140        try (InputStream inputStream = TestUtils.getRegressionDataStream(23165, "largeIds.osm.pbf")) {
     141            dataSet = importer.parseDataSet(inputStream, NullProgressMonitor.INSTANCE);
     142        }
     143        assertNotNull(dataSet.getPrimitiveById(9223372036854775806L, OsmPrimitiveType.NODE));
     144        assertNotNull(dataSet.getPrimitiveById(9223372036854775806L, OsmPrimitiveType.WAY));
     145        assertNotNull(dataSet.getPrimitiveById(9223372036854775806L, OsmPrimitiveType.RELATION));
     146    }
     147
     148    @ParameterizedTest
     149    @ValueSource(strings = {"Downloads/24165.osm.pbf", "workspace/tasking-manager/frontend/24165.osmosis.osm.pbf",
     150    "workspace/tasking-manager/frontend/24165.osmium.osm.pbf"})
     151    void test23165(String path) throws IOException {
     152        try (InputStream is = Files.newInputStream(Paths.get("/Users/tsmock", path))) {
     153            DataSet ds = assertDoesNotThrow(() -> importer.parseDataSet(is, NullProgressMonitor.INSTANCE));
     154            assertNotNull(ds.getPrimitiveById(22319993769L, OsmPrimitiveType.NODE));
     155            assertNotNull(ds.getPrimitiveById(32920002105L, OsmPrimitiveType.NODE));
     156            assertNotNull(ds.getPrimitiveById(29706529395L, OsmPrimitiveType.NODE));
     157            assertNotNull(ds.getPrimitiveById(23842321089L, OsmPrimitiveType.NODE));
     158            assertNotNull(ds.getPrimitiveById(31341235510L, OsmPrimitiveType.NODE));
     159            assertNotNull(ds.getPrimitiveById(30053292843L, OsmPrimitiveType.NODE));
     160            assertNotNull(ds.getPrimitiveById(28917983832L, OsmPrimitiveType.NODE));
     161            assertNotNull(ds.getPrimitiveById(29875275836L, OsmPrimitiveType.NODE));
     162            assertNotNull(ds.getPrimitiveById(32694472600L, OsmPrimitiveType.NODE));
     163            assertNotNull(ds.getPrimitiveById(22545520445L, OsmPrimitiveType.NODE));
     164            assertNotNull(ds.getPrimitiveById(23222110547L, OsmPrimitiveType.NODE));
     165            assertNotNull(ds.getPrimitiveById(2147640293L, OsmPrimitiveType.WAY));
     166        }
     167    }
    132168}
Note: See TracChangeset for help on using the changeset viewer.