1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.io.FileInputStream;
|
---|
7 | import java.text.SimpleDateFormat;
|
---|
8 | import java.util.ArrayList;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.junit.Test;
|
---|
12 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
13 | import org.openstreetmap.josm.data.gpx.GpxConstants;
|
---|
14 | import org.openstreetmap.josm.data.gpx.WayPoint;
|
---|
15 | import org.openstreetmap.josm.io.NmeaReader.NMEA_TYPE;
|
---|
16 |
|
---|
17 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Unit tests of {@link NmeaReader} class.
|
---|
21 | */
|
---|
22 | public class NmeaReaderTest {
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Unit test of methods {@link NMEA_TYPE#equals} and {@link NMEA_TYPE#hashCode}.
|
---|
26 | */
|
---|
27 | @Test
|
---|
28 | public void equalsContract() {
|
---|
29 | EqualsVerifier.forClass(NMEA_TYPE.class).verify();
|
---|
30 | }
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Tests reading a nmea file.
|
---|
34 | * @throws Exception if any error occurs
|
---|
35 | */
|
---|
36 | @Test
|
---|
37 | public void testReader() throws Exception {
|
---|
38 | final NmeaReader in = new NmeaReader(new FileInputStream("data_nodist/btnmeatrack_2016-01-25.nmea"));
|
---|
39 | assertEquals(30, in.getNumberOfCoordinates());
|
---|
40 | assertEquals(0, in.getParserMalformed());
|
---|
41 |
|
---|
42 | final List<WayPoint> wayPoints = new ArrayList<>(in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints());
|
---|
43 | assertEquals("2016-01-25T04:05:09.200Z", wayPoints.get(0).get(GpxConstants.PT_TIME));
|
---|
44 | assertEquals("2016-01-25T04:05:09.400Z", wayPoints.get(1).get(GpxConstants.PT_TIME));
|
---|
45 | assertEquals("2016-01-25T04:05:09.600Z", wayPoints.get(2).get(GpxConstants.PT_TIME));
|
---|
46 |
|
---|
47 | final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
|
---|
48 | assertEquals("2016-01-25T05:05:09.200+01", iso8601.format(wayPoints.get(0).getTime()));
|
---|
49 | assertEquals("2016-01-25T05:05:09.400+01", iso8601.format(wayPoints.get(1).getTime()));
|
---|
50 | assertEquals("2016-01-25T05:05:09.600+01", iso8601.format(wayPoints.get(2).getTime()));
|
---|
51 |
|
---|
52 | assertEquals(new LatLon(46.98807, -1.400525), wayPoints.get(0).getCoor());
|
---|
53 | assertEquals("38.9", wayPoints.get(0).get(GpxConstants.PT_ELE));
|
---|
54 | assertEquals("16", wayPoints.get(0).get(GpxConstants.PT_SAT));
|
---|
55 | assertEquals("3d", wayPoints.get(0).get(GpxConstants.PT_FIX));
|
---|
56 | assertEquals("0.7", wayPoints.get(0).get(GpxConstants.PT_HDOP).toString().trim());
|
---|
57 | assertEquals(null, wayPoints.get(0).get(GpxConstants.PT_VDOP));
|
---|
58 | assertEquals(null, wayPoints.get(0).get(GpxConstants.PT_PDOP));
|
---|
59 | }
|
---|
60 | }
|
---|