1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.rtklib;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 |
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.nio.file.Files;
|
---|
8 | import java.nio.file.Paths;
|
---|
9 | import java.text.SimpleDateFormat;
|
---|
10 | import java.util.ArrayList;
|
---|
11 | import java.util.List;
|
---|
12 | import java.util.TimeZone;
|
---|
13 |
|
---|
14 | import org.junit.jupiter.api.BeforeEach;
|
---|
15 | import org.junit.jupiter.api.Test;
|
---|
16 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
17 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
18 | import org.openstreetmap.josm.data.gpx.GpxConstants;
|
---|
19 | import org.openstreetmap.josm.data.gpx.WayPoint;
|
---|
20 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
21 | import org.openstreetmap.josm.tools.date.DateUtils;
|
---|
22 | import org.xml.sax.SAXException;
|
---|
23 |
|
---|
24 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Unit tests of {@link RtkLibPosReader} class.
|
---|
28 | */
|
---|
29 | class RtkLibPosReaderTest {
|
---|
30 | /**
|
---|
31 | * Set the timezone and timeout.
|
---|
32 | */
|
---|
33 | @RegisterExtension
|
---|
34 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
35 | public JOSMTestRules test = new JOSMTestRules();
|
---|
36 |
|
---|
37 | private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Forces the timezone.
|
---|
41 | */
|
---|
42 | @BeforeEach
|
---|
43 | public void setUp() {
|
---|
44 | iso8601.setTimeZone(DateUtils.UTC);
|
---|
45 | }
|
---|
46 |
|
---|
47 | private static RtkLibPosReader read(String path) throws IOException, SAXException {
|
---|
48 | TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
|
---|
49 | RtkLibPosReader in = new RtkLibPosReader(Files.newInputStream(Paths.get(path)));
|
---|
50 | in.parse(true);
|
---|
51 | return in;
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Tests reading a RTKLib pos file.
|
---|
56 | * @throws Exception if any error occurs
|
---|
57 | */
|
---|
58 | @Test
|
---|
59 | void testReader() throws Exception {
|
---|
60 | RtkLibPosReader in = read("nodist/data/rtklib_example.pos");
|
---|
61 | assertEquals(137, in.getNumberOfCoordinates());
|
---|
62 |
|
---|
63 | List<WayPoint> wayPoints = new ArrayList<>(in.getGpxData().tracks.iterator().next().getSegments().iterator().next().getWayPoints());
|
---|
64 | assertEquals(DateUtils.fromString("2019-06-08T08:23:12.000Z"), wayPoints.get(0).get(GpxConstants.PT_TIME));
|
---|
65 | assertEquals(DateUtils.fromString("2019-06-08T08:23:12.300Z"), wayPoints.get(1).get(GpxConstants.PT_TIME));
|
---|
66 | assertEquals(DateUtils.fromString("2019-06-08T08:23:12.600Z"), wayPoints.get(2).get(GpxConstants.PT_TIME));
|
---|
67 | assertEquals(wayPoints.get(0).getDate(), wayPoints.get(0).get(GpxConstants.PT_TIME));
|
---|
68 |
|
---|
69 | assertEquals("2019-06-08T08:23:12.000Z", iso8601.format(wayPoints.get(0).getDate()));
|
---|
70 | assertEquals("2019-06-08T08:23:12.300Z", iso8601.format(wayPoints.get(1).getDate()));
|
---|
71 | assertEquals("2019-06-08T08:23:12.600Z", iso8601.format(wayPoints.get(2).getDate()));
|
---|
72 |
|
---|
73 | assertEquals(new LatLon(46.948881673, -1.484757046), wayPoints.get(0).getCoor());
|
---|
74 | assertEquals(5, wayPoints.get(0).get(GpxConstants.RTKLIB_Q));
|
---|
75 | assertEquals("92.3955", wayPoints.get(0).get(GpxConstants.PT_ELE));
|
---|
76 | assertEquals("2", wayPoints.get(0).get(GpxConstants.PT_SAT));
|
---|
77 | assertEquals("2.2090015", wayPoints.get(0).get(GpxConstants.PT_HDOP).toString().trim());
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Tests reading another RTKLib pos file with different date format.
|
---|
82 | * @throws Exception if any error occurs
|
---|
83 | */
|
---|
84 | @Test
|
---|
85 | void testReader2() throws Exception {
|
---|
86 | RtkLibPosReader in = read("nodist/data/rtklib_example2.pos");
|
---|
87 | assertEquals(6, in.getNumberOfCoordinates());
|
---|
88 | }
|
---|
89 | }
|
---|