Changeset 14338 in josm for trunk/test


Ignore:
Timestamp:
2018-10-16T00:32:46+02:00 (14 months ago)
Author:
Don-vip
Message:

fix #16755 - Cut overlapping GPX layers when merging (patch by Bjoeni, modified)

Location:
trunk/test
Files:
6 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxDataTest.java

    r14120 r14338  
    88import static org.junit.Assert.assertTrue;
    99
     10import java.io.IOException;
    1011import java.util.ArrayList;
    1112import java.util.Arrays;
     
    2829import org.openstreetmap.josm.data.gpx.GpxData.GpxDataChangeListener;
    2930import org.openstreetmap.josm.data.projection.ProjectionRegistry;
     31import org.openstreetmap.josm.io.GpxReaderTest;
    3032import org.openstreetmap.josm.testutils.JOSMTestRules;
    3133import org.openstreetmap.josm.tools.ListenerList;
     34import org.xml.sax.SAXException;
    3235
    3336import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    5558        data = new GpxData();
    5659    }
    57 
    5860
    5961    /**
     
    8385        assertTrue(data.getWaypoints().contains(newWP));
    8486        assertTrue(data.getWaypoints().contains(existingWP));
     87    }
     88
     89    /**
     90     * Test method for {@link GpxData#mergeFrom(GpxData, boolean, boolean)} including cutting/connecting tracks using actual files.
     91     * @throws Exception if the track cannot be parsed
     92     */
     93    @Test
     94    public void testMergeFromFiles() throws Exception {
     95        testMerge(false, false, "Merged-all"); // regular merging
     96        testMerge(true, false, "Merged-cut"); // cut overlapping tracks, but do not connect them
     97        testMerge(true, true, "Merged-cut-connect"); // cut overlapping tracks and connect them
     98    }
     99
     100    private static void testMerge(boolean cut, boolean connect, String exp) throws IOException, SAXException {
     101        final GpxData own = getGpx("Layer1");
     102        final GpxData other = getGpx("Layer2");
     103        final GpxData expected = getGpx(exp);
     104        own.mergeFrom(other, cut, connect);
     105        assertEquals(expected, own);
     106    }
     107
     108    private static GpxData getGpx(String file) throws IOException, SAXException {
     109        return GpxReaderTest.parseGpxData(TestUtils.getTestDataRoot() + "mergelayers/" + file + ".gpx");
    85110    }
    86111
     
    449474        TestUtils.assumeWorkingEqualsVerifier();
    450475        EqualsVerifier.forClass(GpxData.class).usingGetClass()
    451             .withIgnoredFields("attr", "creator", "fromServer", "storageFile", "listeners", "tracks", "routes", "waypoints", "proxy")
     476            .withIgnoredFields("attr", "creator", "fromServer", "storageFile", "listeners", "tracks", "routes", "waypoints", "proxy", "segSpans")
    452477            .withPrefabValues(WayPoint.class, new WayPoint(LatLon.NORTH_POLE), new WayPoint(LatLon.SOUTH_POLE))
    453478            .withPrefabValues(ListenerList.class, ListenerList.create(), ListenerList.create())
Note: See TracChangeset for help on using the changeset viewer.