Ignore:
Timestamp:
2016-01-10T13:04:11+01:00 (6 years ago)
Author:
simon04
Message:

Add unit test for CorrelateGpxWithImages

File:
1 edited

Legend:

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

    r9383 r9384  
    22package org.openstreetmap.josm.gui.layer.geoimage;
    33
    4 import static org.junit.Assert.*;
     4import static org.junit.Assert.assertEquals;
    55
     6import java.util.Arrays;
     7import java.util.TimeZone;
     8
     9import org.junit.BeforeClass;
    610import org.junit.Test;
     11import org.openstreetmap.josm.data.coor.LatLon;
    712import org.openstreetmap.josm.data.gpx.GpxData;
    813import org.openstreetmap.josm.io.GpxReaderTest;
     14import org.openstreetmap.josm.tools.date.DateUtils;
    915
     16/**
     17 * Unit tests of {@link CorrelateGpxWithImagesTest} class.
     18 */
    1019public class CorrelateGpxWithImagesTest {
    1120
     21    /**
     22     * Setup test.
     23     */
     24    @BeforeClass
     25    public static void setUp() {
     26        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
     27    }
     28
     29    /**
     30     * Tests matching of images to a GPX track.
     31     * @throws Exception if the track cannot be parsed
     32     */
    1233    @Test
    1334    public void testMatchGpxTrack() throws Exception {
    14         final GpxData munich = GpxReaderTest.parseGpxData("data_nodist/munich.gpx");
     35        final GpxData gpx = GpxReaderTest.parseGpxData("data_nodist/2094047.gpx");
     36        assertEquals(4, gpx.tracks.size());
     37        assertEquals(1, gpx.tracks.iterator().next().getSegments().size());
     38        assertEquals(185, gpx.tracks.iterator().next().getSegments().iterator().next().getWayPoints().size());
     39
     40        final ImageEntry i0 = new ImageEntry();
     41        i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
     42        i0.createTmp();
    1543        final ImageEntry i1 = new ImageEntry();
    16         i1.setExifGpsTime();
    17         CorrelateGpxWithImages.matchGpxTrack(null, munich, 0);
     44        i1.setExifTime(DateUtils.fromString("2016:01:03 12:04:01"));
     45        i1.createTmp();
     46        final ImageEntry i2 = new ImageEntry();
     47        i2.setExifTime(DateUtils.fromString("2016:01:03 12:04:57"));
     48        i2.createTmp();
     49        final ImageEntry i3 = new ImageEntry();
     50        i3.setExifTime(DateUtils.fromString("2016:01:03 12:05:05"));
     51        i3.createTmp();
     52
     53        assertEquals(4, CorrelateGpxWithImages.matchGpxTrack(Arrays.asList(i0, i1, i2, i3), gpx, 0));
     54        assertEquals(new LatLon(47.19286847859621, 8.79732714034617), i0.getPos()); // start of track
     55        assertEquals(new LatLon(47.196979885920882, 8.79541271366179), i1.getPos()); // exact match
     56        assertEquals(new LatLon(47.197319911792874, 8.792139580473304), i3.getPos()); // exact match
     57        assertEquals(new LatLon((47.197131179273129 + 47.197186248376966) / 2, (8.792974585667253 + 8.792809881269932) / 2),
     58                i2.getPos()); // interpolated
    1859    }
    1960}
Note: See TracChangeset for help on using the changeset viewer.