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 final ParseTestItem[] parseTestData = {
|
---|
16 | new ParseTestItem("https://www.openstreetmap.org", null),
|
---|
17 | new ParseTestItem("https://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("https://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("https://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("https://www.openstreetmap.org/?zoom=17&lat=51.71873&lon=8.76164", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
|
---|
21 | new ParseTestItem("https://www.openstreetmap.org/?lon=8.76164&lat=51.71873&zoom=17&foo", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
|
---|
22 | new ParseTestItem("https://www.openstreetmap.org/?mlon=8.76164&mlat=51.71873", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 18)),
|
---|
23 | new ParseTestItem("http://osm.org/go/euulwp", OsmUrlToBounds.positionToBounds(51.48262023925781, -0.29937744140625, 8)),
|
---|
24 | new ParseTestItem("https://www.openstreetmap.org/#map=17/51.71873/8.76164", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
|
---|
25 | new ParseTestItem("https://www.openstreetmap.org/#map=17/51.71873/8.76164&layers=CN", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
|
---|
26 | new ParseTestItem("https%3A%2F%2Fwww.openstreetmap.org%2F%23map%3D16%2F51.71873%2F8.76164", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 16)),
|
---|
27 | new ParseTestItem("https%3A%2F%2Fwww.openstreetmap.org%2F%23map%3D16%2F51.71873%2F8.76164%26layers%3DCN", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 16)),
|
---|
28 | new ParseTestItem("https://www.openstreetmap.org/?note=26325#map=18/40.86215/-75.75020", OsmUrlToBounds.positionToBounds(40.86215, -75.75020, 18)),
|
---|
29 | new ParseTestItem("https://www.openstreetmap.org/?note=26325#map=18/40.86215/-75.75020&layers=N", OsmUrlToBounds.positionToBounds(40.86215, -75.75020, 18)),
|
---|
30 | new ParseTestItem("https://www.openstreetmap.org/?mlat=51.5&mlon=-0.01#map=10/51.4831/-0.1270", OsmUrlToBounds.positionToBounds(51.4831, -0.1270, 10)),
|
---|
31 | new ParseTestItem("https://www.openstreetmap.org/?mlat=51.5&mlon=-0.01#map=10/51.4831/-0.3509&layers=T", OsmUrlToBounds.positionToBounds(51.4831, -0.3509, 10)),
|
---|
32 | new ParseTestItem("https://www.openstreetmap.org/#map", null),
|
---|
33 | new ParseTestItem("https://www.openstreetmap.org/#map=foo", null),
|
---|
34 | new ParseTestItem("https://www.openstreetmap.org/#map=fooz/foolat/foolon", null)
|
---|
35 | };
|
---|
36 |
|
---|
37 | private static class ParseTestItem {
|
---|
38 | public String url;
|
---|
39 | public Bounds bounds;
|
---|
40 |
|
---|
41 | public ParseTestItem(String url, Bounds bounds) {
|
---|
42 | this.url = url;
|
---|
43 | this.bounds = bounds;
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Test URL parsing
|
---|
49 | */
|
---|
50 | @Test
|
---|
51 | public void testParse() {
|
---|
52 | for (ParseTestItem item : parseTestData) {
|
---|
53 | Bounds bounds = null;
|
---|
54 | try {
|
---|
55 | bounds = OsmUrlToBounds.parse(item.url);
|
---|
56 | } catch (IllegalArgumentException e) {
|
---|
57 | // Ignore. check if bounds is null after
|
---|
58 | }
|
---|
59 | Assert.assertEquals(item.url, item.bounds, bounds);
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | }
|
---|