Changeset 9384 in josm


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

Add unit test for CorrelateGpxWithImages

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r9375 r9384  
    435435    public boolean equals(Object obj) {
    436436        if (this == obj) return true;
    437         if (obj == null || getClass() != obj.getClass()) return false;
     437        if (!(obj instanceof LatLon)) return false;
    438438        LatLon that = (LatLon) obj;
    439439        return Double.compare(that.x, x) == 0 &&
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r9383 r9384  
    11461146     * @return number of matched points
    11471147     */
    1148     private int matchGpxTrack(List<ImageEntry> images, GpxData selectedGpx, long offset) {
     1148    static int matchGpxTrack(List<ImageEntry> images, GpxData selectedGpx, long offset) {
    11491149        int ret = 0;
    11501150
     
    11891189    }
    11901190
    1191     private int matchPoints(List<ImageEntry> images, WayPoint prevWp, long prevWpTime,
     1191    static int matchPoints(List<ImageEntry> images, WayPoint prevWp, long prevWpTime,
    11921192            WayPoint curWp, long curWpTime, long offset) {
    11931193        // Time between the track point and the previous one, 5 sec if first point, i.e. photos take
  • 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}
  • trunk/test/unit/org/openstreetmap/josm/io/GpxReaderTest.java

    r9380 r9384  
    88import java.io.File;
    99import java.io.FileInputStream;
     10import java.io.IOException;
    1011import java.nio.charset.StandardCharsets;
    1112import java.util.List;
     
    2324
    2425    /**
     26     * Parses a GPX file and returns the parsed data
     27     * @param filename the GPX file to parse
     28     * @return the parsed GPX data
     29     * @throws IOException if an error occurs during reading.
     30     * @throws SAXException if a SAX error occurs
     31     */
     32    public static GpxData parseGpxData(String filename) throws IOException, SAXException {
     33        final GpxData result;
     34        try (final FileInputStream in = new FileInputStream(new File(filename))) {
     35            final GpxReader reader = new GpxReader(in);
     36            assertTrue(reader.parse(false));
     37            result = reader.getGpxData();
     38        }
     39        return result;
     40    }
     41
     42    /**
    2543     * Tests the {@code munich.gpx} test file.
    2644     * @throws Exception if something goes wrong
     
    2846    @Test
    2947    public void testMunich() throws Exception {
    30         final GpxData result;
    31         try (final FileInputStream in = new FileInputStream(new File("data_nodist/munich.gpx"))) {
    32             final GpxReader reader = new GpxReader(in);
    33             assertTrue(reader.parse(false));
    34             result = reader.getGpxData();
    35         }
     48        final GpxData result = parseGpxData("data_nodist/munich.gpx");
    3649        assertEquals(2762, result.tracks.size());
    3750        assertEquals(0, result.routes.size());
Note: See TracChangeset for help on using the changeset viewer.