Changeset 14075 in josm for trunk/test


Ignore:
Timestamp:
2018-08-02T22:48:59+02:00 (12 months ago)
Author:
Don-vip
Message:

fix #16550 - fix regressions in OSM -> GPX conversion

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/OsmDataLayerTest.java

    r13174 r14075  
    77import static org.junit.Assert.assertTrue;
    88
     9import java.io.ByteArrayInputStream;
    910import java.io.File;
     11import java.nio.charset.StandardCharsets;
     12import java.text.DateFormat;
     13import java.util.Collection;
     14import java.util.Iterator;
    1015
    1116import org.junit.Before;
     
    1621import org.openstreetmap.josm.data.Bounds;
    1722import org.openstreetmap.josm.data.coor.LatLon;
     23import org.openstreetmap.josm.data.gpx.GpxConstants;
     24import org.openstreetmap.josm.data.gpx.GpxData;
     25import org.openstreetmap.josm.data.gpx.GpxTrack;
     26import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
     27import org.openstreetmap.josm.data.gpx.WayPoint;
    1828import org.openstreetmap.josm.data.osm.DataSet;
    1929import org.openstreetmap.josm.data.osm.Node;
     
    2232import org.openstreetmap.josm.data.osm.Way;
    2333import org.openstreetmap.josm.gui.MainApplication;
     34import org.openstreetmap.josm.io.IllegalDataException;
     35import org.openstreetmap.josm.io.OsmReader;
    2436import org.openstreetmap.josm.testutils.JOSMTestRules;
     37import org.openstreetmap.josm.tools.date.DateUtils;
    2538
    2639import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    190203    /**
    191204     * Unit test of {@link OsmDataLayer#toGpxData}.
    192      */
    193     @Test
    194     public void testToGpxData() {
    195         fillDataSet(ds);
    196         assertNotNull(layer.toGpxData());
     205     * @throws IllegalDataException never
     206     */
     207    @Test
     208    public void testToGpxData() throws IllegalDataException {
     209        ds.mergeFrom(OsmReader.parseDataSet(new ByteArrayInputStream((
     210                "<?xml version='1.0' encoding='UTF-8'?>\n" +
     211                "<osm version='0.6' upload='false' generator='JOSM'>\n" +
     212                "  <node id='-546306' timestamp='2018-08-01T10:00:00Z' lat='47.0' lon='9.0'>\n" +
     213                "    <tag k='ele' v='123' />\n" +
     214                "    <tag k='time' v='2018-08-01T10:00:00Z' />\n" +
     215                "  </node>\n" +
     216                "  <node id='-546307' timestamp='2018-08-01T10:01:00Z' lat='47.1' lon='9.1'>\n" +
     217                "    <tag k='ele' v='456' />\n" +
     218                "    <tag k='time' v='2018-08-01T10:01:00Z' />\n" +
     219                "  </node>\n" +
     220                "  <way id='-546308'>\n" +
     221                "    <nd ref='-546306' />\n" +
     222                "    <nd ref='-546307' />\n" +
     223                "  </way>\r\n" +
     224                "</osm>").getBytes(StandardCharsets.UTF_8)), null));
     225        GpxData gpx = layer.toGpxData();
     226        assertNotNull(gpx);
     227        // Check metadata
     228        assertEquals(new Bounds(47.0, 9.0, 47.1, 9.1), gpx.recalculateBounds());
     229        // Check there is no waypoint
     230        assertTrue(gpx.getWaypoints().isEmpty());
     231        // Check that track is correct
     232        assertEquals(1, gpx.getTrackCount());
     233        GpxTrack track = gpx.getTracks().iterator().next();
     234        Collection<GpxTrackSegment> segments = track.getSegments();
     235        assertEquals(1, segments.size());
     236        Collection<WayPoint> trackpoints = segments.iterator().next().getWayPoints();
     237        assertEquals(2, trackpoints.size());
     238        Iterator<WayPoint> it = trackpoints.iterator();
     239        DateFormat gpxFormat = DateUtils.getGpxFormat();
     240        WayPoint p1 = it.next();
     241        assertEquals(new LatLon(47.0, 9.0), p1.getCoor());
     242        assertEquals("123", p1.get(GpxConstants.PT_ELE));
     243        assertEquals("2018-08-01T10:00:00.000Z", gpxFormat.format(p1.get(GpxConstants.PT_TIME)));
     244        WayPoint p2 = it.next();
     245        assertEquals(new LatLon(47.1, 9.1), p2.getCoor());
     246        assertEquals("456", p2.get(GpxConstants.PT_ELE));
     247        assertEquals("2018-08-01T10:01:00.000Z", gpxFormat.format(p2.get(GpxConstants.PT_TIME)));
    197248    }
    198249
Note: See TracChangeset for help on using the changeset viewer.