Changeset 19033 in josm for trunk/test


Ignore:
Timestamp:
2024-04-05T14:58:43+02:00 (10 months ago)
Author:
GerdP
Message:

fix #23599: Error opening osm.pbf if way has negative ID or incomplete metadata
This fixes

  • handling of visible flag as proposed by *Martin*
  • handling of completely missing denseinfo (ids are always delta encoded), upload is discouraged
  • handling of denseinfo which only contains version data
Location:
trunk/test
Files:
6 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/io/importexport/OsmPbfImporterTest.java

    r19024 r19033  
    2424import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    2525import org.openstreetmap.josm.data.osm.DataSet;
     26import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2627import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    2728import org.openstreetmap.josm.data.osm.Relation;
     29import org.openstreetmap.josm.data.osm.UploadPolicy;
    2830import org.openstreetmap.josm.data.osm.Way;
    2931import org.openstreetmap.josm.data.protobuf.ProtobufTest;
     
    159161        assertDoesNotThrow(() -> importer.parseDataSet(new ByteArrayInputStream(badData), NullProgressMonitor.INSTANCE));
    160162    }
     163
     164    @Test
     165    void testNonRegression23599a() throws IOException, IllegalDataException {
     166        final DataSet dataSet;
     167        try (InputStream inputStream = TestUtils.getRegressionDataStream(23599, "visible.osm.pbf")) {
     168            dataSet = importer.parseDataSet(inputStream, NullProgressMonitor.INSTANCE);
     169        }
     170        assertTrue(dataSet.getNodes().stream().allMatch(OsmPrimitive::isVisible));
     171        assertTrue(dataSet.getWays().stream().allMatch(OsmPrimitive::isVisible));
     172        assertTrue(dataSet.getRelations().stream().allMatch(OsmPrimitive::isVisible));
     173
     174    }
     175
     176    @Test
     177    void testNonRegression23599b() throws IOException, IllegalDataException {
     178        final DataSet dataSet;
     179        // osmconvert w1194668585.orig.osm -o=w1194668585.full.osm.pbf
     180        try (InputStream inputStream = TestUtils.getRegressionDataStream(23599, "w1194668585.full.osm.pbf")) {
     181            dataSet = importer.parseDataSet(inputStream, NullProgressMonitor.INSTANCE);
     182        }
     183        assertNotNull(dataSet.getPrimitiveById(1194668585L, OsmPrimitiveType.WAY));
     184        assertEquals(145987123, dataSet.getPrimitiveById(1194668585L, OsmPrimitiveType.WAY).getChangesetId());
     185        assertEquals(4, dataSet.getPrimitiveById(1194668585L, OsmPrimitiveType.WAY).getVersion());
     186        assertEquals(UploadPolicy.NORMAL, dataSet.getUploadPolicy());
     187    }
     188
     189    @Test
     190    void testNonRegression23599c() throws IOException, IllegalDataException {
     191        final DataSet dataSet;
     192        // osmconvert --drop-author w1194668585.orig.osm -o=w1194668585.full.osm.pbf
     193        try (InputStream inputStream = TestUtils.getRegressionDataStream(23599, "w1194668585.drop-author.osm.pbf")) {
     194            dataSet = importer.parseDataSet(inputStream, NullProgressMonitor.INSTANCE);
     195        }
     196        assertNotNull(dataSet.getPrimitiveById(1194668585L, OsmPrimitiveType.WAY));
     197        assertEquals(0, dataSet.getPrimitiveById(1194668585L, OsmPrimitiveType.WAY).getChangesetId());
     198        assertEquals(4, dataSet.getPrimitiveById(1194668585L, OsmPrimitiveType.WAY).getVersion());
     199        assertEquals(UploadPolicy.NORMAL, dataSet.getUploadPolicy());
     200    }
     201
     202    @Test
     203    void testNonRegression23599d() throws IOException, IllegalDataException {
     204        final DataSet dataSet;
     205        // osmconvert --drop-version w1194668585.orig.osm -o=w1194668585.full.osm.pbf
     206        try (InputStream inputStream = TestUtils.getRegressionDataStream(23599, "w1194668585.drop-version.osm.pbf")) {
     207            dataSet = importer.parseDataSet(inputStream, NullProgressMonitor.INSTANCE);
     208        }
     209        assertNotNull(dataSet.getPrimitiveById(1194668585L, OsmPrimitiveType.WAY));
     210        assertEquals(0, dataSet.getPrimitiveById(1194668585L, OsmPrimitiveType.WAY).getChangesetId());
     211        assertEquals(0, dataSet.getPrimitiveById(1194668585L, OsmPrimitiveType.WAY).getVersion());
     212        assertEquals(UploadPolicy.DISCOURAGED, dataSet.getUploadPolicy());
     213    }
     214
    161215}
Note: See TracChangeset for help on using the changeset viewer.