Changeset 9740 in josm


Ignore:
Timestamp:
2016-02-04T22:18:54+01:00 (3 years ago)
Author:
simon04
Message:

see #12485 - Add unit test for nmea reading

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/NmeaReader.java

    r9703 r9740  
    2020import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack;
    2121import org.openstreetmap.josm.data.gpx.WayPoint;
    22 import org.openstreetmap.josm.tools.date.DateUtils;
    2322
    2423/**
     
    287286                    // As this sentence has no complete time only use it
    288287                    // if there is no time so far
    289                     currentwp.put(GpxConstants.PT_TIME, DateUtils.fromDate(d));
     288                    currentwp.setTime(d);
    290289                }
    291290                // elevation
     
    398397                }
    399398                // time: this sentence has complete time so always use it.
    400                 currentwp.put(GpxConstants.PT_TIME, DateUtils.fromDate(d));
     399                currentwp.setTime(d);
    401400                // speed
    402401                accu = e[GPRMC.SPEED.position];
  • trunk/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java

    r9666 r9740  
    22package org.openstreetmap.josm.io;
    33
    4 import org.junit.Test;
    5 import org.openstreetmap.josm.io.NmeaReader.NMEA_TYPE;
     4import static junit.framework.Assert.assertEquals;
     5
     6import java.io.FileInputStream;
     7import java.text.SimpleDateFormat;
     8import java.util.ArrayList;
     9import java.util.List;
    610
    711import nl.jqno.equalsverifier.EqualsVerifier;
     12import org.junit.Test;
     13import org.openstreetmap.josm.data.coor.LatLon;
     14import org.openstreetmap.josm.data.gpx.GpxConstants;
     15import org.openstreetmap.josm.data.gpx.WayPoint;
     16import org.openstreetmap.josm.io.NmeaReader.NMEA_TYPE;
    817
    918/**
     
    1928        EqualsVerifier.forClass(NMEA_TYPE.class).verify();
    2029    }
     30
     31    /**
     32     * Tests reading a nmea file.
     33     * @throws Exception if any error occurs
     34     */
     35    @Test
     36    public void testReader() throws Exception {
     37        final NmeaReader in = new NmeaReader(new FileInputStream("data_nodist/btnmeatrack_2016-01-25.nmea"));
     38        assertEquals(30, in.getNumberOfCoordinates());
     39        assertEquals(0, in.getParserMalformed());
     40
     41        final List<WayPoint> wayPoints = new ArrayList<>(in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints());
     42        assertEquals("2016-01-25T04:05:09.200Z", wayPoints.get(0).get(GpxConstants.PT_TIME));
     43        assertEquals("2016-01-25T04:05:09.400Z", wayPoints.get(1).get(GpxConstants.PT_TIME));
     44        assertEquals("2016-01-25T04:05:09.600Z", wayPoints.get(2).get(GpxConstants.PT_TIME));
     45
     46        final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
     47        assertEquals("2016-01-25T05:05:09.200+01", iso8601.format(wayPoints.get(0).getTime()));
     48        assertEquals("2016-01-25T05:05:09.400+01", iso8601.format(wayPoints.get(1).getTime()));
     49        assertEquals("2016-01-25T05:05:09.600+01", iso8601.format(wayPoints.get(2).getTime()));
     50
     51        assertEquals(new LatLon(46.98807, -1.400525), wayPoints.get(0).getCoor());
     52        assertEquals("38.9", wayPoints.get(0).get(GpxConstants.PT_ELE));
     53        assertEquals("16", wayPoints.get(0).get(GpxConstants.PT_SAT));
     54        assertEquals("3d", wayPoints.get(0).get(GpxConstants.PT_FIX));
     55        assertEquals("0.7", wayPoints.get(0).get(GpxConstants.PT_HDOP).toString().trim());
     56        assertEquals(null, wayPoints.get(0).get(GpxConstants.PT_VDOP));
     57        assertEquals(null, wayPoints.get(0).get(GpxConstants.PT_PDOP));
     58    }
    2159}
Note: See TracChangeset for help on using the changeset viewer.