Changeset 15496 in josm for trunk/test/unit
- Timestamp:
- 2019-11-02T15:11:34+01:00 (5 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 3 added
- 3 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxDataTest.java
r14338 r15496 36 36 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 37 37 import nl.jqno.equalsverifier.EqualsVerifier; 38 import nl.jqno.equalsverifier.Warning; 38 39 39 40 /** … … 64 65 @Test 65 66 public void testMergeFrom() { 66 ImmutableGpxTrack track = singleWaypointGpxTrack();67 GpxTrack track = singleWaypointGpxTrack(); 67 68 GpxRoute route = singleWaypointRoute(); 68 69 WayPoint newWP = new WayPoint(LatLon.NORTH_POLE); … … 103 104 final GpxData expected = getGpx(exp); 104 105 own.mergeFrom(other, cut, connect); 105 assertEquals(expected, own); 106 own.put(GpxConstants.META_BOUNDS, null); 107 expected.put(GpxConstants.META_BOUNDS, null); //they are only updated by GpxWriter 108 assertEquals(exp + " didn't match!", expected, own); 106 109 } 107 110 … … 117 120 assertEquals(0, data.getTracks().size()); 118 121 119 ImmutableGpxTrack track1 = emptyGpxTrack();120 ImmutableGpxTrack track2 = singleWaypointGpxTrack();122 GpxTrack track1 = emptyGpxTrack(); 123 GpxTrack track2 = singleWaypointGpxTrack(); 121 124 data.addTrack(track1); 122 125 assertEquals(1, data.getTracks().size()); … … 137 140 @Test(expected = IllegalArgumentException.class) 138 141 public void testAddTrackFails() { 139 ImmutableGpxTrack track1 = emptyGpxTrack();142 GpxTrack track1 = emptyGpxTrack(); 140 143 data.addTrack(track1); 141 144 data.addTrack(track1); … … 147 150 @Test(expected = IllegalArgumentException.class) 148 151 public void testRemoveTrackFails() { 149 ImmutableGpxTrack track1 = emptyGpxTrack();152 GpxTrack track1 = emptyGpxTrack(); 150 153 data.addTrack(track1); 151 154 data.removeTrack(track1); … … 246 249 public void testHasTrackPoints() { 247 250 assertFalse(data.hasTrackPoints()); 248 ImmutableGpxTrack track1 = emptyGpxTrack();251 GpxTrack track1 = emptyGpxTrack(); 249 252 data.addTrack(track1); 250 253 assertFalse(data.hasTrackPoints()); 251 ImmutableGpxTrack track2 = singleWaypointGpxTrack();254 GpxTrack track2 = singleWaypointGpxTrack(); 252 255 data.addTrack(track2); 253 256 assertTrue(data.hasTrackPoints()); … … 260 263 public void testGetTrackPoints() { 261 264 assertEquals(0, data.getTrackPoints().count()); 262 ImmutableGpxTrack track1 = singleWaypointGpxTrack();265 GpxTrack track1 = singleWaypointGpxTrack(); 263 266 data.addTrack(track1); 264 267 assertEquals(1, data.getTrackPoints().count()); 265 ImmutableGpxTrack track2 = singleWaypointGpxTrack();268 GpxTrack track2 = singleWaypointGpxTrack(); 266 269 data.addTrack(track2); 267 270 assertEquals(2, data.getTrackPoints().count()); … … 281 284 @Test 282 285 public void testIsEmpty() { 283 ImmutableGpxTrack track1 = singleWaypointGpxTrack();286 GpxTrack track1 = singleWaypointGpxTrack(); 284 287 WayPoint waypoint = new WayPoint(LatLon.ZERO); 285 288 GpxRoute route = singleWaypointRoute(); … … 308 311 @Test 309 312 public void testLength() { 310 ImmutableGpxTrack track1 = waypointGpxTrack(313 GpxTrack track1 = waypointGpxTrack( 311 314 new WayPoint(new LatLon(0, 0)), 312 315 new WayPoint(new LatLon(1, 1)), 313 316 new WayPoint(new LatLon(0, 2))); 314 ImmutableGpxTrack track2 = waypointGpxTrack(317 GpxTrack track2 = waypointGpxTrack( 315 318 new WayPoint(new LatLon(0, 0)), 316 319 new WayPoint(new LatLon(-1, 1))); … … 336 339 p2.setTime(new Date(100020)); 337 340 p4.setTime(new Date(500020)); 338 data.addTrack(new ImmutableGpxTrack(Arrays.asList(Arrays.asList(p1, p2)), Collections.emptyMap()));339 data.addTrack(new ImmutableGpxTrack(Arrays.asList(Arrays.asList(p3, p4, p5)), Collections.emptyMap()));341 data.addTrack(new GpxTrack(Arrays.asList(Arrays.asList(p1, p2)), Collections.emptyMap())); 342 data.addTrack(new GpxTrack(Arrays.asList(Arrays.asList(p3, p4, p5)), Collections.emptyMap())); 340 343 341 344 Date[] times = data.getMinMaxTimeForAllTracks(); … … 355 358 .map(WayPoint::new) 356 359 .collect(Collectors.toList()); 357 data.addTrack(new ImmutableGpxTrack(Arrays.asList(points), Collections.emptyMap()));360 data.addTrack(new GpxTrack(Arrays.asList(points), Collections.emptyMap())); 358 361 359 362 WayPoint closeToMiddle = data.nearestPointOnTrack(new EastNorth(10, 0), 10); … … 449 452 } 450 453 451 private static ImmutableGpxTrack emptyGpxTrack() {452 return new ImmutableGpxTrack(Collections.<Collection<WayPoint>>emptyList(), Collections.emptyMap());453 } 454 455 private static ImmutableGpxTrack singleWaypointGpxTrack() {456 return new ImmutableGpxTrack(Collections.singleton(Collections.singleton(new WayPoint(LatLon.ZERO))), Collections.emptyMap());457 } 458 459 private static ImmutableGpxTrack waypointGpxTrack(WayPoint... wps) {460 return new ImmutableGpxTrack(Collections.singleton(Arrays.asList(wps)), Collections.emptyMap());454 private static GpxTrack emptyGpxTrack() { 455 return new GpxTrack(Collections.<Collection<WayPoint>>emptyList(), Collections.emptyMap()); 456 } 457 458 private static GpxTrack singleWaypointGpxTrack() { 459 return new GpxTrack(Collections.singleton(Collections.singleton(new WayPoint(LatLon.ZERO))), Collections.emptyMap()); 460 } 461 462 private static GpxTrack waypointGpxTrack(WayPoint... wps) { 463 return new GpxTrack(Collections.singleton(Arrays.asList(wps)), Collections.emptyMap()); 461 464 } 462 465 … … 473 476 public void testEqualsContract() { 474 477 TestUtils.assumeWorkingEqualsVerifier(); 478 GpxExtensionCollection col = new GpxExtensionCollection(); 479 col.add("josm", "from-server", "true"); 475 480 EqualsVerifier.forClass(GpxData.class).usingGetClass() 476 .withIgnoredFields("attr", "creator", "fromServer", "storageFile", "listeners", "tracks", "routes", "waypoints", "proxy", "segSpans") 481 .suppress(Warning.NONFINAL_FIELDS) 482 .withIgnoredFields("creator", "fromServer", "storageFile", "initializing", "updating", "suppressedInvalidate", "listeners", "tracks", "routes", "waypoints", "proxy", "segSpans", "modified") 477 483 .withPrefabValues(WayPoint.class, new WayPoint(LatLon.NORTH_POLE), new WayPoint(LatLon.SOUTH_POLE)) 478 484 .withPrefabValues(ListenerList.class, ListenerList.create(), ListenerList.create()) 485 .withPrefabValues(GpxExtensionCollection.class, new GpxExtensionCollection(), col) 479 486 .verify(); 480 487 } -
trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxRouteTest.java
r13079 r15496 30 30 public void testEqualsContract() { 31 31 TestUtils.assumeWorkingEqualsVerifier(); 32 GpxExtensionCollection col = new GpxExtensionCollection(); 33 col.add("josm", "from-server", "true"); 32 34 EqualsVerifier.forClass(GpxRoute.class).usingGetClass() 33 35 .suppress(Warning.NONFINAL_FIELDS) 34 36 .withPrefabValues(WayPoint.class, new WayPoint(LatLon.NORTH_POLE), new WayPoint(LatLon.SOUTH_POLE)) 37 .withPrefabValues(GpxExtensionCollection.class, new GpxExtensionCollection(), col) 35 38 .verify(); 36 39 } -
trunk/test/unit/org/openstreetmap/josm/data/gpx/WayPointTest.java
r13342 r15496 29 29 public void testEqualsContract() { 30 30 TestUtils.assumeWorkingEqualsVerifier(); 31 GpxExtensionCollection col = new GpxExtensionCollection(); 32 col.add("josm", "from-server", "true"); 31 33 EqualsVerifier.forClass(WayPoint.class).usingGetClass() 32 34 .suppress(Warning.NONFINAL_FIELDS) 33 35 .withIgnoredFields("customColoring", "dir", "drawLine", "east", "north", "eastNorthCacheKey") 36 .withPrefabValues(GpxExtensionCollection.class, new GpxExtensionCollection(), col) 34 37 .verify(); 35 38 } -
trunk/test/unit/org/openstreetmap/josm/data/gpx/WithAttributesTest.java
r13079 r15496 29 29 public void testEqualsContract() { 30 30 TestUtils.assumeWorkingEqualsVerifier(); 31 GpxExtensionCollection col = new GpxExtensionCollection(); 32 col.add("josm", "from-server", "true"); 31 33 EqualsVerifier.forClass(WithAttributes.class).usingGetClass() 32 34 .suppress(Warning.NONFINAL_FIELDS) 35 .withPrefabValues(GpxExtensionCollection.class, new GpxExtensionCollection(), col) 33 36 .verify(); 34 37 } -
trunk/test/unit/org/openstreetmap/josm/gui/layer/GpxLayerTest.java
r15425 r15496 4 4 import static org.junit.Assert.assertEquals; 5 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertNull; 6 7 import static org.junit.Assert.assertTrue; 7 8 … … 19 20 import org.openstreetmap.josm.TestUtils; 20 21 import org.openstreetmap.josm.data.gpx.GpxData; 21 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack; 22 import org.openstreetmap.josm.data.gpx.GpxTrack; 23 import org.openstreetmap.josm.data.gpx.IGpxTrackSegment; 22 24 import org.openstreetmap.josm.data.gpx.WayPoint; 23 25 import org.openstreetmap.josm.data.osm.DataSet; … … 74 76 public void testGpxLayer() throws Exception { 75 77 GpxLayer layer = new GpxLayer(new GpxData(), "foo", false); 78 GpxTrack trk = new GpxTrack(new ArrayList<IGpxTrackSegment>(), new HashMap<>()); 79 trk.getExtensions().add("gpxd", "color", "#FF0000"); 80 layer.data.addTrack(trk); 81 76 82 assertEquals("foo", layer.getName()); 77 83 assertFalse(layer.isLocalFile()); 78 assertEquals( Color.MAGENTA, layer.getColorProperty().get());79 assertEquals("<html> 0 tracks(0 segments), 0 routes, 0 waypoints<br>Length: < 0.01 m<br></html>", layer.getToolTipText());84 assertEquals(layer.getColor(), Color.RED); 85 assertEquals("<html>1 track (0 segments), 0 routes, 0 waypoints<br>Length: < 0.01 m<br></html>", layer.getToolTipText()); 80 86 81 87 GpxLayer layer2 = new GpxLayer(new GpxData(), "bar", true); 82 88 assertEquals("bar", layer2.getName()); 83 89 assertTrue(layer2.isLocalFile()); 84 assert Equals(Color.MAGENTA, layer2.getColorProperty().get());90 assertNull(layer2.getColor()); 85 91 assertEquals("<html>0 tracks (0 segments), 0 routes, 0 waypoints<br>Length: < 0.01 m<br></html>", layer2.getToolTipText()); 86 92 … … 188 194 public void testGetTimespanForTrack() throws Exception { 189 195 assertEquals("", GpxLayer.getTimespanForTrack( 190 new ImmutableGpxTrack(new ArrayList<Collection<WayPoint>>(), new HashMap<String, Object>())));196 new GpxTrack(new ArrayList<Collection<WayPoint>>(), new HashMap<String, Object>()))); 191 197 192 198 assertEquals("1/3/16 11:59 AM - 12:00 PM (0:00)", GpxLayer.getTimespanForTrack(getMinimalGpxData().tracks.iterator().next())); -
trunk/test/unit/org/openstreetmap/josm/gui/layer/LayerTest.java
r14120 r15496 8 8 import static org.junit.Assert.assertTrue; 9 9 10 import java.awt.Color;11 10 import java.io.File; 12 11 … … 14 13 import org.junit.Rule; 15 14 import org.junit.Test; 16 import org.openstreetmap.josm.data.preferences.AbstractProperty;17 import org.openstreetmap.josm.data.preferences.NamedColorProperty;18 15 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 19 16 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 41 38 public void setUp() { 42 39 testLayer = new LayerManagerTest.TestLayer(); 43 }44 45 /**46 * Test {@link Layer#getColorProperty()}47 */48 @Test49 public void testGetColorProperty() {50 assertEquals(null, testLayer.getColorProperty());51 52 AbstractProperty<Color> color = new LayerManagerTest.TestLayer() {53 @Override54 protected NamedColorProperty getBaseColorProperty() {55 return new NamedColorProperty("x", Color.BLACK);56 }57 }.getColorProperty();58 59 assertEquals(Color.BLACK, color.get());60 assertEquals(Color.BLACK, color.getDefaultValue());61 assertEquals("clr.layer.Test Layer.x", color.getKey());62 40 } 63 41 … … 98 76 assertEquals("Test Layer2", testLayer.getName()); 99 77 100 testLayer = new LayerManagerTest.TestLayer() { 101 @Override 102 public AbstractProperty<Color> getColorProperty() { 103 return new NamedColorProperty("test", Color.RED); 104 } 105 }; 78 testLayer = new LayerManagerTest.TestLayer(); 106 79 107 80 testLayer.setName("Test Layer2"); -
trunk/test/unit/org/openstreetmap/josm/gui/layer/OsmDataLayerTest.java
r15419 r15496 24 24 import org.openstreetmap.josm.data.gpx.GpxData; 25 25 import org.openstreetmap.josm.data.gpx.GpxTrack; 26 import org.openstreetmap.josm.data.gpx. GpxTrackSegment;26 import org.openstreetmap.josm.data.gpx.IGpxTrackSegment; 27 27 import org.openstreetmap.josm.data.gpx.WayPoint; 28 28 import org.openstreetmap.josm.data.osm.DataSet; … … 241 241 assertEquals(1, gpx.getTrackCount()); 242 242 GpxTrack track = gpx.getTracks().iterator().next(); 243 Collection< GpxTrackSegment> segments = track.getSegments();243 Collection<IGpxTrackSegment> segments = track.getSegments(); 244 244 assertEquals(1, segments.size()); 245 245 Collection<WayPoint> trackpoints = segments.iterator().next().getWayPoints(); -
trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityActionTest.java
r14349 r15496 39 39 @Override 40 40 protected String getString(final ExtendedDialog instance) { 41 return ((JLabel) ((JPanel) this.getContent(instance)).getComponent(2)).getText();41 return ((JLabel) ((JPanel) instance.getContentPane().getComponent(0)).getComponent(2)).getText(); 42 42 } 43 43 }; 44 44 edMocker.getMockResultMap().put( 45 "<html>Select all tracks that you want to be displayed. You can drag select a range of" +46 "tracks or use CTRL+Click to select specific ones. The map is updated live in the" +47 "background. Open the URLs by double clicking them.</html>",48 "Show all"49 );45 "<html>Select all tracks that you want to be displayed. " + 46 "You can drag select a range of tracks or use CTRL+Click to select specific ones. " + 47 "The map is updated live in the background. Open the URLs by double clicking them, edit name and description by double clicking the cell.</html>", 48 "Show all" 49 ); 50 50 51 51 new ChooseTrackVisibilityAction(GpxLayerTest.getMinimalGpxLayer()).actionPerformed(null); … … 53 53 assertEquals(1, edMocker.getInvocationLog().size()); 54 54 Object[] invocationLogEntry = edMocker.getInvocationLog().get(0); 55 assertEquals( 1, (int) invocationLogEntry[0]);55 assertEquals(2, (int) invocationLogEntry[0]); 56 56 assertEquals("Set track visibility for Bananas", invocationLogEntry[2]); 57 57 } -
trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerActionTest.java
r15432 r15496 67 67 public void testFromTrack() throws Exception { 68 68 Config.getPref().put("gpx.convert-tags", "no"); 69 testFromTrack("tracks ");69 testFromTrack("tracks.gpx", "tracks.osm"); 70 70 71 71 Config.getPref().put("gpx.convert-tags", "yes"); 72 testFromTrack("tracks -ele-time");72 testFromTrack("tracks.gpx", "tracks-ele-time.osm"); 73 73 74 74 Config.getPref().put("gpx.convert-tags", "list"); 75 75 Config.getPref().putList("gpx.convert-tags.list.yes", Arrays.asList("ele")); 76 76 Config.getPref().putList("gpx.convert-tags.list.no", Arrays.asList("time")); 77 testFromTrack("tracks-ele"); 78 77 testFromTrack("tracks.gpx", "tracks-ele.osm"); 79 78 80 79 Config.getPref().putList("gpx.convert-tags.list.yes", Arrays.asList("time")); 81 80 Config.getPref().putList("gpx.convert-tags.list.no", Arrays.asList("ele")); 82 testFromTrack("tracks-time"); 81 testFromTrack("tracks.gpx", "tracks-time.osm"); 82 83 //Extension tests: 84 Config.getPref().put("gpx.convert-tags", "yes"); 85 testFromTrack("tracks-extensions.gpx", "tracks-extensions.osm"); 86 87 Config.getPref().put("gpx.convert-tags", "list"); 88 Config.getPref().putList("gpx.convert-tags.list.yes", Arrays.asList("time", "ele")); 89 Config.getPref().putList("gpx.convert-tags.list.no", Arrays.asList( 90 "gpxx:DisplayColor", 91 "gpxd:color", 92 "gpx:extension:test:tag", 93 "gpx:extension:test:segment:tag")); 94 testFromTrack("tracks-extensions.gpx", "tracks-ele-time.osm"); 95 83 96 } 84 97 … … 107 120 } 108 121 109 private void testFromTrack(String expected) throws IOException, SAXException, IllegalDataException {110 final GpxData data = GpxReaderTest.parseGpxData(TestUtils.getTestDataRoot() + "tracks/ tracks.gpx");122 private void testFromTrack(String originalGpx, String expectedOsm) throws IOException, SAXException, IllegalDataException { 123 final GpxData data = GpxReaderTest.parseGpxData(TestUtils.getTestDataRoot() + "tracks/" + originalGpx); 111 124 final DataSet osmExpected = OsmReader.parseDataSet(Files.newInputStream( 112 Paths.get(TestUtils.getTestDataRoot(), "tracks/" + expected + ".osm")), null);125 Paths.get(TestUtils.getTestDataRoot(), "tracks/" + expectedOsm)), null); 113 126 final GpxLayer layer = new GpxLayer(data); 114 127 final DataSet osm = new ConvertFromGpxLayerAction(layer).convert(); 115 //compare sorted coordinates/tags and total amount of primitives, because IDs and order will vary after reload128 //compare sorted nodes/ways, tags and total amount of primitives, because IDs and order will vary after reload 116 129 117 130 List<GenericNode> nodes = osm.getNodes().stream() … … 125 138 .collect(Collectors.toList()); 126 139 127 assertEquals(nodesExpected, nodes); 128 assertEquals(osmExpected.allPrimitives().size(), osm.allPrimitives().size()); 140 assertEquals("Conversion " + originalGpx + " -> " + expectedOsm + " didn't match!", nodesExpected, nodes); 141 142 List<String> ways = osm.getWays().stream() 143 .map(w -> Integer.toString(w.getNodes().size()) + ":" + w.getKeys().entrySet().stream().sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())).collect(Collectors.toList()).toString()) 144 .sorted() 145 .collect(Collectors.toList()); 146 147 List<String> waysExpected = osmExpected.getWays().stream() 148 .map(w -> Integer.toString(w.getNodes().size()) + ":" + w.getKeys().entrySet().stream().sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())).collect(Collectors.toList()).toString()) 149 .sorted() 150 .collect(Collectors.toList()); 151 152 assertEquals("Conversion " + originalGpx + " -> " + expectedOsm + " didn't match!", waysExpected, ways); 153 154 assertEquals("Conversion " + originalGpx + " -> " + expectedOsm + " didn't match!", osmExpected.allPrimitives().size(), osm.allPrimitives().size()); 129 155 } 130 156 -
trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelperTest.java
r12849 r15496 7 7 import java.io.IOException; 8 8 import java.util.List; 9 import java.util.Map; 9 10 import java.util.stream.Collectors; 10 11 … … 14 15 import org.openstreetmap.josm.data.gpx.GpxData; 15 16 import org.openstreetmap.josm.gui.layer.GpxLayer; 17 import org.openstreetmap.josm.gui.layer.gpx.GpxDrawHelper.ColorMode; 16 18 import org.openstreetmap.josm.io.GpxReaderTest; 17 import org.openstreetmap.josm.spi.preferences.Config;18 19 import org.openstreetmap.josm.testutils.JOSMTestRules; 19 20 import org.openstreetmap.josm.tools.ColorHelper; 20 21 import org.xml.sax.SAXException; 22 23 import com.google.common.collect.ImmutableMap; 21 24 22 25 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 42 45 @Test 43 46 public void testTicket12312() throws FileNotFoundException, IOException, SAXException { 44 Config.getPref().putBoolean("draw.rawgps.colors.dynamic.layer 12312", true); 45 Config.getPref().putInt("draw.rawgps.colors.layer 12312", GpxDrawHelper.ColorMode.VELOCITY.toIndex()); 46 final List<String> colors = calculateColors(TestUtils.getRegressionDataFile(12312, "single_trackpoint.gpx"), "12312", 1); 47 assertEquals("[#FF00FF]", colors.toString()); 47 final List<String> colors = calculateColors(TestUtils.getRegressionDataFile(12312, "single_trackpoint.gpx"), 48 ImmutableMap.of("colormode.dynamic-range", "true", 49 "colormode", Integer.toString(ColorMode.VELOCITY.toIndex())), 50 1); 51 assertEquals("[null]", colors.toString()); 48 52 } 49 53 … … 56 60 @Test 57 61 public void testNone() throws IOException, SAXException { 58 final List<String> colors = calculateColors("data_nodist/2094047.gpx", "000", 10);59 assertEquals("[# FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF, #FF00FF]", colors.toString());62 final List<String> colors = calculateColors("data_nodist/2094047.gpx", ImmutableMap.of(), 10); 63 assertEquals("[#000000, #000000, #000000, #000000, #000000, #000000, #000000, #000000, #000000, #000000]", colors.toString()); 60 64 } 61 65 … … 68 72 @Test 69 73 public void testVelocity() throws IOException, SAXException { 70 Config.getPref().putInt("draw.rawgps.colors.layer 001", GpxDrawHelper.ColorMode.VELOCITY.toIndex()); 71 final List<String> colors = calculateColors("data_nodist/2094047.gpx", "001", 10); 72 assertEquals("[#FF00FF, #FFAD00, #FFA800, #FFA800, #FF9E00, #FF9400, #FF7000, #FF7000, #FF8000, #FF9400]", colors.toString()); 74 final List<String> colors = calculateColors("data_nodist/2094047.gpx", ImmutableMap.of("colormode", Integer.toString(ColorMode.VELOCITY.toIndex())), 10); 75 assertEquals("[#000000, #FFAD00, #FFA800, #FFA800, #FF9E00, #FF9400, #FF7000, #FF7000, #FF8000, #FF9400]", colors.toString()); 73 76 } 74 77 … … 81 84 @Test 82 85 public void testVelocityDynamic() throws IOException, SAXException { 83 Config.getPref().putInt("draw.rawgps.colors.layer 002", GpxDrawHelper.ColorMode.VELOCITY.toIndex()); 84 Config.getPref().putBoolean("draw.rawgps.colors.dynamic.layer 002", true); 85 final List<String> colors = calculateColors("data_nodist/2094047.gpx", "002", 10); 86 assertEquals("[#FF00FF, #00FFE0, #00FFC2, #00FFC2, #00FF75, #00FF3D, #99FF00, #94FF00, #38FF00, #00FF38]", colors.toString()); 86 final List<String> colors = calculateColors("data_nodist/2094047.gpx", 87 ImmutableMap.of("colormode.dynamic-range", "true", 88 "colormode", Integer.toString(ColorMode.VELOCITY.toIndex())), 89 10); 90 assertEquals("[#000000, #00FFE0, #00FFC2, #00FFC2, #00FF75, #00FF3D, #99FF00, #94FF00, #38FF00, #00FF38]", colors.toString()); 87 91 } 88 92 … … 95 99 @Test 96 100 public void testDirection() throws IOException, SAXException { 97 Config.getPref().putInt("draw.rawgps.colors.layer 003", GpxDrawHelper.ColorMode.DIRECTION.toIndex()); 98 final List<String> colors = calculateColors("data_nodist/2094047.gpx", "003", 10); 99 assertEquals("[#FF00FF, #EAEC25, #EDEA26, #EDE525, #ECD322, #EBB81D, #E85A0D, #E73708, #E84D0B, #EA8A15]", colors.toString()); 101 final List<String> colors = calculateColors("data_nodist/2094047.gpx", ImmutableMap.of("colormode", Integer.toString(ColorMode.DIRECTION.toIndex())), 10); 102 assertEquals("[#000000, #EAEC25, #EDEA26, #EDE525, #ECD322, #EBB81D, #E85A0D, #E73708, #E84D0B, #EA8A15]", colors.toString()); 100 103 } 101 104 … … 108 111 @Test 109 112 public void testTime() throws IOException, SAXException { 110 Config.getPref().putInt("draw.rawgps.colors.layer 003", GpxDrawHelper.ColorMode.TIME.toIndex()); 111 final List<String> colors = calculateColors("data_nodist/2094047.gpx", "003", 10); 112 assertEquals("[#FF00FF, #FF0000, #FF0000, #FF0500, #FF0500, #FF0A00, #FF0A00, #FF1F00, #FF2E00, #FF3300]", colors.toString()); 113 final List<String> colors = calculateColors("data_nodist/2094047.gpx", ImmutableMap.of("colormode", Integer.toString(ColorMode.TIME.toIndex())), 10); 114 assertEquals("[#000000, #FF0000, #FF0000, #FF0500, #FF0500, #FF0A00, #FF0A00, #FF1F00, #FF2E00, #FF3300]", colors.toString()); 113 115 } 114 116 … … 116 118 * 117 119 * @param fileName the GPX filename to parse 118 * @param layer Name the layer name used to fetch the color settings, see {@link GpxDrawHelper#readPreferences(java.lang.String)}120 * @param layerPrefs a HashMap representing the layer specific preferences 119 121 * @param n the number of waypoints of the first track/segment to analyze 120 122 * @return the HTML color codes for the first {@code n} points … … 123 125 * @throws SAXException if any SAX error occurs 124 126 */ 125 static List<String> calculateColors(String fileName, String layerName, int n) throws IOException, SAXException {127 static List<String> calculateColors(String fileName, Map<String, String> layerPrefs, int n) throws IOException, SAXException { 126 128 final GpxData data = GpxReaderTest.parseGpxData(fileName); 129 data.getLayerPrefs().putAll(layerPrefs); 127 130 final GpxLayer layer = new GpxLayer(data); 128 131 final GpxDrawHelper gdh = new GpxDrawHelper(layer); 129 gdh.readPreferences( layerName);132 gdh.readPreferences(); 130 133 gdh.calculateColors(); 131 134 return data.getTrackPoints().limit(n).map(p -> ColorHelper.color2html(p.customColoring)).collect(Collectors.toList()); -
trunk/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/AudioMarkerTest.java
r9814 r15496 11 11 import org.openstreetmap.josm.JOSMFixture; 12 12 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.openstreetmap.josm.data.gpx.Extensions;14 import org.openstreetmap.josm.data.gpx.GpxConstants;15 13 import org.openstreetmap.josm.data.gpx.GpxData; 16 14 import org.openstreetmap.josm.data.gpx.WayPoint; … … 46 44 WayPoint wpt = marker.convertToWayPoint(); 47 45 assertEquals(LatLon.ZERO, wpt.getCoor()); 48 Extensions ext = (Extensions) wpt.get(GpxConstants.META_EXTENSIONS); 49 assertEquals("2.0", ext.get("offset")); 46 assertEquals("2.0", wpt.getExtensions().get("josm", "offset").getValue()); 50 47 } 51 48 } -
trunk/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java
r14138 r15496 4 4 import static org.junit.Assert.assertEquals; 5 5 import static org.junit.Assert.assertNotNull; 6 import static org.junit.Assert.assertNull; 6 7 import static org.junit.Assert.assertTrue; 7 8 8 import java.awt.Color;9 9 import java.util.Arrays; 10 10 … … 17 17 import org.openstreetmap.josm.data.gpx.GpxLink; 18 18 import org.openstreetmap.josm.data.gpx.WayPoint; 19 import org.openstreetmap.josm.data.osm.DataSet; 19 20 import org.openstreetmap.josm.gui.MainApplication; 21 import org.openstreetmap.josm.gui.MapFrame; 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 20 23 import org.openstreetmap.josm.spi.preferences.Config; 21 24 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 29 32 30 33 /** 31 * Setup tests34 * For creating layers 32 35 */ 33 36 @Rule … … 48 51 @Test 49 52 public void testMarkerLayer() { 50 assertEquals(Color.magenta, MarkerLayer.getGenericColor());51 53 MarkerLayer layer = new MarkerLayer(new GpxData(), "foo", null, null); 52 54 MainApplication.getLayerManager().addLayer(layer); 53 55 54 56 assertEquals("foo", layer.getName()); 55 assert Equals(Color.magenta, layer.getColorProperty().get());57 assertNull(layer.getColor()); 56 58 assertNotNull(layer.getIcon()); 57 59 assertEquals("0 markers", layer.getToolTipText()); … … 62 64 WayPoint wpt = new WayPoint(LatLon.ZERO); 63 65 wpt.attr.put(GpxConstants.META_LINKS, Arrays.asList(new GpxLink("https://josm.openstreetmap.de"))); 64 wpt. addExtension("offset", "1.0");66 wpt.getExtensions().add("josm", "offset", "1.0"); 65 67 gpx.waypoints.add(wpt); 66 68 wpt = new WayPoint(LatLon.ZERO); 67 wpt. addExtension("offset", "NaN");69 wpt.getExtensions().add("josm", "offset", "NaN"); 68 70 gpx.waypoints.add(wpt); 69 71 layer = new MarkerLayer(gpx, "bar", null, null); 70 72 71 73 assertEquals("bar", layer.getName()); 72 assert Equals(Color.magenta, layer.getColorProperty().get());74 assertNull(layer.getColor()); 73 75 assertNotNull(layer.getIcon()); 74 76 assertEquals("3 markers", layer.getToolTipText()); … … 76 78 assertTrue(layer.getMenuEntries().length > 10); 77 79 } 80 81 /** 82 * Unit test of {@code Main.map.mapView.playHeadMarker}. 83 */ 84 @Test 85 public void testPlayHeadMarker() { 86 try { 87 MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(), "", null)); 88 MapFrame map = MainApplication.getMap(); 89 MarkerLayer layer = new MarkerLayer(new GpxData(), null, null, null); 90 assertNull(map.mapView.playHeadMarker); 91 MainApplication.getLayerManager().addLayer(layer); 92 assertNotNull(map.mapView.playHeadMarker); 93 MainApplication.getLayerManager().removeLayer(layer); 94 } finally { 95 if (MainApplication.isDisplayingMapView()) { 96 MainApplication.getMap().mapView.playHeadMarker = null; 97 } 98 } 99 } 78 100 } -
trunk/test/unit/org/openstreetmap/josm/io/GpxReaderTest.java
r14077 r15496 11 11 import java.nio.charset.StandardCharsets; 12 12 import java.util.ArrayList; 13 import java.util.HashMap; 14 import java.util.Map; 13 15 14 16 import org.junit.Rule; … … 70 72 71 73 /** 74 * Tests if layer preferences can be read 75 * @throws Exception if track can't be parsed 76 */ 77 @Test 78 public void testLayerPrefs() throws Exception { 79 final GpxData data = parseGpxData(TestUtils.getTestDataRoot() + "tracks/tracks-layerprefs.gpx"); 80 Map<String, String> e = new HashMap<>(); 81 e.put("colormode.velocity.tune", "10"); 82 e.put("lines.arrows.min-distance", "20"); 83 e.put("colormode", "1"); 84 e.put("lines", "1"); 85 e.put("lines.arrows", "true"); 86 e.put("colormode.dynamic-range", "true"); 87 e.put("colors", "0"); 88 assertEquals(data.getLayerPrefs(), e); 89 } 90 91 /** 72 92 * Tests invalid data. 73 93 * @throws Exception always SAXException -
trunk/test/unit/org/openstreetmap/josm/io/GpxWriterTest.java
r14453 r15496 4 4 import static org.junit.Assert.assertEquals; 5 5 6 import java.awt.Color; 6 7 import java.io.ByteArrayOutputStream; 7 8 import java.io.IOException; … … 10 11 import java.time.Month; 11 12 import java.time.ZoneOffset; 13 import java.util.Arrays; 12 14 import java.util.Date; 15 import java.util.HashMap; 13 16 import java.util.function.Consumer; 14 17 … … 18 21 import org.openstreetmap.josm.data.gpx.GpxConstants; 19 22 import org.openstreetmap.josm.data.gpx.GpxData; 23 import org.openstreetmap.josm.data.gpx.GpxData.XMLNamespace; 24 import org.openstreetmap.josm.data.gpx.GpxExtensionCollection; 25 import org.openstreetmap.josm.data.gpx.GpxTrack; 26 import org.openstreetmap.josm.data.gpx.GpxTrackSegment; 20 27 import org.openstreetmap.josm.data.gpx.WayPoint; 21 28 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 88 95 " <pdop>1.2</pdop>%n"); 89 96 } 97 98 /** 99 * Tests if extensions are written correctly. 100 * @throws IOException 101 */ 102 @Test 103 public void testExtensions() throws IOException { 104 GpxData data = new GpxData(); 105 data.getNamespaces().add(new XMLNamespace("test", "http://example.com/testURI")); //only namespace, no location printed 106 data.getNamespaces().add(new XMLNamespace("knownprefix", "http://example.com/URI", "http://example.com/location.xsd")); //printed 107 data.getNamespaces().add(new XMLNamespace("notpresent", "http://example.com/notpresent", "http://example.com/notpresent.xsd")); //NOT printed 108 109 GpxExtensionCollection exts = data.getExtensions(); 110 data.fromServer = true; //printed 111 data.getLayerPrefs().put("foo", "bar"); //printed depending on writer config 112 exts.add("knownprefix", "foo", "bar"); //printed 113 exts.add("unknownprefix", "foo", "bar"); //NOT printed 114 115 WayPoint wpt = new WayPoint(LatLon.ZERO); 116 wpt.getExtensions().add("test", "foo", "extension of a waypoint"); //printed 117 118 GpxTrackSegment seg = new GpxTrackSegment(Arrays.asList(wpt)); 119 seg.getExtensions().add("test", "foo", "extension of a segment"); //printed 120 121 GpxTrack trk = new GpxTrack(Arrays.asList(seg), new HashMap<>()); 122 123 trk.setColor(Color.RED); //printed depending on writer configuration 124 125 data.addTrack(trk); 126 127 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 128 GpxWriter writer = new GpxWriter(baos); 129 130 writer.write(data); 131 assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + 132 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 133 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 134 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 135 " xmlns:gpxd=\"http://josm.openstreetmap.de/gpx-drawing-extensions-1.0\"\n" + 136 " xmlns:test=\"http://example.com/testURI\"\n" + 137 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 138 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd http://josm.openstreetmap.de/gpx-drawing-extensions-1.0 http://josm.openstreetmap.de/gpx-drawing-extensions-1.0.xsd\">\n" + 139 " <metadata>\n" + 140 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 141 " <extensions>\n" + 142 " <knownprefix:foo>bar</knownprefix:foo>\n" + 143 " <josm:from-server>true</josm:from-server>\n" + 144 " <josm:layerPreferences>\n" + 145 " <josm:entry key=\"foo\" value=\"bar\"/>\n" + 146 " </josm:layerPreferences>\n" + 147 " </extensions>\n" + 148 " </metadata>\n" + 149 " <trk>\n" + 150 " <extensions>\n" + 151 " <gpxd:color>#FF0000</gpxd:color>\n" + 152 " </extensions>\n" + 153 " <trkseg>\n" + 154 " <extensions>\n" + 155 " <test:foo>extension of a segment</test:foo>\n" + 156 " </extensions>\n" + 157 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 158 " <extensions>\n" + 159 " <test:foo>extension of a waypoint</test:foo>\n" + 160 " </extensions>\n" + 161 " </trkpt>\n" + 162 " </trkseg>\n" + 163 " </trk>\n" + 164 "</gpx>", baos.toString()); 165 166 baos.reset(); 167 writer.write(data, GpxConstants.ColorFormat.GPXX, true); 168 assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + 169 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 170 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 171 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 172 " xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\"\n" + 173 " xmlns:test=\"http://example.com/testURI\"\n" + 174 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 175 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd\">\n" + 176 " <metadata>\n" + 177 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 178 " <extensions>\n" + 179 " <knownprefix:foo>bar</knownprefix:foo>\n" + 180 " <josm:from-server>true</josm:from-server>\n" + 181 " <josm:layerPreferences>\n" + 182 " <josm:entry key=\"foo\" value=\"bar\"/>\n" + 183 " </josm:layerPreferences>\n" + 184 " </extensions>\n" + 185 " </metadata>\n" + 186 " <trk>\n" + 187 " <extensions>\n" + 188 " <gpxx:TrackExtensions>\n" + 189 " <gpxx:DisplayColor>Red</gpxx:DisplayColor>\n" + 190 " </gpxx:TrackExtensions>\n" + 191 " </extensions>\n" + 192 " <trkseg>\n" + 193 " <extensions>\n" + 194 " <test:foo>extension of a segment</test:foo>\n" + 195 " </extensions>\n" + 196 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 197 " <extensions>\n" + 198 " <test:foo>extension of a waypoint</test:foo>\n" + 199 " </extensions>\n" + 200 " </trkpt>\n" + 201 " </trkseg>\n" + 202 " </trk>\n" + 203 "</gpx>", baos.toString()); 204 205 baos.reset(); 206 writer.write(data, null, false); 207 assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + 208 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 209 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 210 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 211 " xmlns:test=\"http://example.com/testURI\"\n" + 212 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 213 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd\">\n" + 214 " <metadata>\n" + 215 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 216 " <extensions>\n" + 217 " <knownprefix:foo>bar</knownprefix:foo>\n" + 218 " <josm:from-server>true</josm:from-server>\n" + 219 " </extensions>\n" + 220 " </metadata>\n" + 221 " <trk>\n" + 222 " <trkseg>\n" + 223 " <extensions>\n" + 224 " <test:foo>extension of a segment</test:foo>\n" + 225 " </extensions>\n" + 226 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 227 " <extensions>\n" + 228 " <test:foo>extension of a waypoint</test:foo>\n" + 229 " </extensions>\n" + 230 " </trkpt>\n" + 231 " </trkseg>\n" + 232 " </trk>\n" + 233 "</gpx>", baos.toString()); 234 235 baos.reset(); 236 writer.write(data, GpxConstants.ColorFormat.GPXX, true); 237 // checked again to make sure that extensions are shown again after 238 // being hidden, even if they don't actually have to be converted 239 // (GPXD -> convertColor() -> GPXX -> hide() -> null -> show() -> GPXX) 240 assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + 241 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 242 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 243 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 244 " xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\"\n" + 245 " xmlns:test=\"http://example.com/testURI\"\n" + 246 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 247 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd\">\n" + 248 " <metadata>\n" + 249 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 250 " <extensions>\n" + 251 " <knownprefix:foo>bar</knownprefix:foo>\n" + 252 " <josm:from-server>true</josm:from-server>\n" + 253 " <josm:layerPreferences>\n" + 254 " <josm:entry key=\"foo\" value=\"bar\"/>\n" + 255 " </josm:layerPreferences>\n" + 256 " </extensions>\n" + 257 " </metadata>\n" + 258 " <trk>\n" + 259 " <extensions>\n" + 260 " <gpxx:TrackExtensions>\n" + 261 " <gpxx:DisplayColor>Red</gpxx:DisplayColor>\n" + 262 " </gpxx:TrackExtensions>\n" + 263 " </extensions>\n" + 264 " <trkseg>\n" + 265 " <extensions>\n" + 266 " <test:foo>extension of a segment</test:foo>\n" + 267 " </extensions>\n" + 268 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 269 " <extensions>\n" + 270 " <test:foo>extension of a waypoint</test:foo>\n" + 271 " </extensions>\n" + 272 " </trkpt>\n" + 273 " </trkseg>\n" + 274 " </trk>\n" + 275 "</gpx>", baos.toString()); 276 277 writer.close(); 278 } 90 279 } -
trunk/test/unit/org/openstreetmap/josm/io/nmea/NmeaReaderTest.java
r15034 r15496 25 25 import org.openstreetmap.josm.data.gpx.GpxData; 26 26 import org.openstreetmap.josm.data.gpx.GpxTrack; 27 import org.openstreetmap.josm.data.gpx. GpxTrackSegment;27 import org.openstreetmap.josm.data.gpx.IGpxTrackSegment; 28 28 import org.openstreetmap.josm.data.gpx.WayPoint; 29 29 import org.openstreetmap.josm.io.GpxReaderTest; … … 101 101 assertEquals(nTracks, nmeaTrack.getSegments().size()); 102 102 if (nTracks > 0) { 103 GpxTrackSegment gpxSeg = gpxTrack.getSegments().iterator().next();104 GpxTrackSegment nmeaSeg = nmeaTrack.getSegments().iterator().next();103 IGpxTrackSegment gpxSeg = gpxTrack.getSegments().iterator().next(); 104 IGpxTrackSegment nmeaSeg = nmeaTrack.getSegments().iterator().next(); 105 105 assertEquals(gpxSeg.getBounds(), nmeaSeg.getBounds()); 106 106 assertEquals(numCoor, gpxSeg.getWayPoints().size());
Note:
See TracChangeset
for help on using the changeset viewer.