| 1 | // License: GPL. For details, see LICENSE file. |
| 2 | package org.openstreetmap.josm.tools; |
| 3 | |
| 4 | import org.junit.Assert; |
| 5 | import org.junit.Test; |
| 6 | import org.openstreetmap.josm.data.Bounds; |
| 7 | |
| 8 | /** |
| 9 | * Unit tests of {@link OsmUrlToBounds} class. |
| 10 | */ |
| 11 | public class OsmUrlToBoundsTest { |
| 12 | /** |
| 13 | * data for {@link #testParse} |
| 14 | */ |
| 15 | private static ParseTestItem[] parseTestData = { |
| 16 | new ParseTestItem("http://www.openstreetmap.org", null), |
| 17 | new ParseTestItem("http://www.openstreetmap.org/?bbox=-0.489,51.28,0.236,51.686", new Bounds(51.28, -0.489, 51.686, 0.236)), |
| 18 | new ParseTestItem("http://www.openstreetmap.org/?minlon=-0.489&minlat=51.28&maxlon=0.236&maxlat=51.686", new Bounds(51.28, -0.489, 51.686, 0.236)), |
| 19 | new ParseTestItem("http://www.openstreetmap.org/?maxlat=51.686&maxlon=0.236&minlat=51.28&minlon=-0.489", new Bounds(51.28, -0.489, 51.686, 0.236)), |
| 20 | new ParseTestItem("http://www.openstreetmap.org/?zoom=17&lat=51.71873&lon=8.76164", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)), |
| 21 | new ParseTestItem("http://www.openstreetmap.org/?lon=8.76164&lat=51.71873&zoom=17", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)), |
| 22 | new ParseTestItem("http://osm.org/go/euulwp", OsmUrlToBounds.positionToBounds(51.48262023925781, -0.29937744140625, 8)), |
| 23 | new ParseTestItem("http://www.openstreetmap.org/#map=17/51.71873/8.76164", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)), |
| 24 | new ParseTestItem("http://www.openstreetmap.org/#map=17/51.71873/8.76164&layers=CN", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)), |
| 25 | new ParseTestItem("http%3A%2F%2Fwww.openstreetmap.org%2F%23map%3D16%2F51.71873%2F8.76164", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 16)), |
| 26 | new ParseTestItem("http%3A%2F%2Fwww.openstreetmap.org%2F%23map%3D16%2F51.71873%2F8.76164%26layers%3DCN", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 16)), |
| 27 | new ParseTestItem("http://www.openstreetmap.org/?note=26325#map=18/40.86215/-75.75020", OsmUrlToBounds.positionToBounds(40.86215, -75.75020, 18)), |
| 28 | new ParseTestItem("http://www.openstreetmap.org/?note=26325#map=18/40.86215/-75.75020&layers=N", OsmUrlToBounds.positionToBounds(40.86215, -75.75020, 18)), |
| 29 | new ParseTestItem("http://www.openstreetmap.org/?mlat=51.5&mlon=-0.01#map=10/51.4831/-0.1270", OsmUrlToBounds.positionToBounds(51.4831, -0.1270, 10)), |
| 30 | new ParseTestItem("http://www.openstreetmap.org/?mlat=51.5&mlon=-0.01#map=10/51.4831/-0.3509&layers=T", OsmUrlToBounds.positionToBounds(51.4831, -0.1270, 10)) |
| 31 | }; |
| 32 | |
| 33 | private static class ParseTestItem { |
| 34 | public String url; |
| 35 | public Bounds bounds; |
| 36 | |
| 37 | public ParseTestItem(String url, Bounds bounds) { |
| 38 | this.url = url; |
| 39 | this.bounds = bounds; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Test URL parsing |
| 45 | */ |
| 46 | @Test |
| 47 | public void testParse() { |
| 48 | for (ParseTestItem item : parseTestData) { |
| 49 | Bounds bounds = OsmUrlToBounds.parse(item.url); |
| 50 | Assert.assertEquals(item.url, item.bounds, bounds); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | } |