1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.geoimage;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.util.Arrays;
|
---|
7 | import java.util.Collections;
|
---|
8 | import java.util.TimeZone;
|
---|
9 |
|
---|
10 | import org.junit.BeforeClass;
|
---|
11 | import org.junit.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.data.coor.CachedLatLon;
|
---|
14 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
15 | import org.openstreetmap.josm.io.GpxReaderTest;
|
---|
16 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
17 | import org.openstreetmap.josm.tools.Pair;
|
---|
18 | import org.openstreetmap.josm.tools.date.DateUtils;
|
---|
19 | import org.openstreetmap.josm.tools.date.DateUtilsTest;
|
---|
20 |
|
---|
21 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Unit tests of {@link CorrelateGpxWithImages} class.
|
---|
25 | */
|
---|
26 | public class CorrelateGpxWithImagesTest {
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Setup test.
|
---|
30 | */
|
---|
31 | @Rule
|
---|
32 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
33 | public JOSMTestRules test = new JOSMTestRules();
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Setup test.
|
---|
37 | */
|
---|
38 | @BeforeClass
|
---|
39 | public static void setUp() {
|
---|
40 | DateUtilsTest.setTimeZone(TimeZone.getTimeZone("UTC"));
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Tests matching of images to a GPX track.
|
---|
45 | * @throws Exception if the track cannot be parsed
|
---|
46 | */
|
---|
47 | @Test
|
---|
48 | public void testMatchGpxTrack() throws Exception {
|
---|
49 | final GpxData gpx = GpxReaderTest.parseGpxData("data_nodist/2094047.gpx");
|
---|
50 | assertEquals(4, gpx.tracks.size());
|
---|
51 | assertEquals(1, gpx.tracks.iterator().next().getSegments().size());
|
---|
52 | assertEquals(185, gpx.tracks.iterator().next().getSegments().iterator().next().getWayPoints().size());
|
---|
53 |
|
---|
54 | final ImageEntry i0 = new ImageEntry();
|
---|
55 | i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
|
---|
56 | i0.createTmp();
|
---|
57 | final ImageEntry i1 = new ImageEntry();
|
---|
58 | i1.setExifTime(DateUtils.fromString("2016:01:03 12:04:01"));
|
---|
59 | i1.createTmp();
|
---|
60 | final ImageEntry i2 = new ImageEntry();
|
---|
61 | i2.setExifTime(DateUtils.fromString("2016:01:03 12:04:57"));
|
---|
62 | i2.createTmp();
|
---|
63 | final ImageEntry i3 = new ImageEntry();
|
---|
64 | i3.setExifTime(DateUtils.fromString("2016:01:03 12:05:05"));
|
---|
65 | i3.createTmp();
|
---|
66 |
|
---|
67 | assertEquals(4, CorrelateGpxWithImages.matchGpxTrack(Arrays.asList(i0, i1, i2, i3), gpx, 0));
|
---|
68 | assertEquals(new CachedLatLon(47.19286847859621, 8.79732714034617), i0.getPos()); // start of track
|
---|
69 | assertEquals(new CachedLatLon(47.196979885920882, 8.79541271366179), i1.getPos()); // exact match
|
---|
70 | assertEquals(new CachedLatLon(47.197319911792874, 8.792139580473304), i3.getPos()); // exact match
|
---|
71 | assertEquals(new CachedLatLon((47.197131179273129 + 47.197186248376966) / 2, (8.792974585667253 + 8.792809881269932) / 2),
|
---|
72 | i2.getPos()); // interpolated
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Tests automatic guessing of timezone/offset
|
---|
77 | * @throws Exception if an error occurs
|
---|
78 | */
|
---|
79 | @Test
|
---|
80 | public void testAutoGuess() throws Exception {
|
---|
81 | final GpxData gpx = GpxReaderTest.parseGpxData("data_nodist/2094047.gpx");
|
---|
82 | final ImageEntry i0 = new ImageEntry();
|
---|
83 | i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
|
---|
84 | i0.createTmp();
|
---|
85 | assertEquals(Pair.create(Timezone.ZERO, Offset.seconds(-4)),
|
---|
86 | CorrelateGpxWithImages.autoGuess(Collections.singletonList(i0), gpx));
|
---|
87 | }
|
---|
88 | }
|
---|