1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.io.FileInputStream;
|
---|
5 | import java.io.InputStream;
|
---|
6 | import java.util.ArrayList;
|
---|
7 | import java.util.Collection;
|
---|
8 | import java.util.Iterator;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.fest.reflect.core.Reflection;
|
---|
12 | import org.fest.reflect.reference.TypeRef;
|
---|
13 | import org.junit.Assert;
|
---|
14 | import org.junit.BeforeClass;
|
---|
15 | import org.junit.Test;
|
---|
16 | import org.openstreetmap.josm.JOSMFixture;
|
---|
17 | import org.openstreetmap.josm.Main;
|
---|
18 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
19 | import org.openstreetmap.josm.data.projection.Projections;
|
---|
20 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
21 | import org.openstreetmap.josm.io.OsmReader;
|
---|
22 |
|
---|
23 | public class QuadBucketsTest {
|
---|
24 |
|
---|
25 | @BeforeClass
|
---|
26 | public static void init() {
|
---|
27 | JOSMFixture.createUnitTestFixture().init();
|
---|
28 | }
|
---|
29 |
|
---|
30 | private void removeAllTest(DataSet ds) {
|
---|
31 | List<Node> allNodes = new ArrayList<>(ds.getNodes());
|
---|
32 | List<Way> allWays = new ArrayList<>(ds.getWays());
|
---|
33 | List<Relation> allRelations = new ArrayList<>(ds.getRelations());
|
---|
34 |
|
---|
35 | QuadBuckets<Node> nodes = Reflection.field("nodes").ofType(new TypeRef<QuadBuckets<Node>>() {}).in(ds).get();
|
---|
36 | QuadBuckets<Way> ways = Reflection.field("ways").ofType(new TypeRef<QuadBuckets<Way>>() {}).in(ds).get();
|
---|
37 | Collection<Relation> relations = Reflection.field("relations").ofType(new TypeRef<Collection<Relation>>() {}).in(ds).get();
|
---|
38 |
|
---|
39 | int expectedCount = allNodes.size();
|
---|
40 | for (OsmPrimitive o: allNodes) {
|
---|
41 | ds.removePrimitive(o);
|
---|
42 | checkIterator(nodes, --expectedCount);
|
---|
43 | }
|
---|
44 | expectedCount = allWays.size();
|
---|
45 | for (OsmPrimitive o: allWays) {
|
---|
46 | ds.removePrimitive(o);
|
---|
47 | checkIterator(ways, --expectedCount);
|
---|
48 | }
|
---|
49 | for (OsmPrimitive o: allRelations) {
|
---|
50 | ds.removePrimitive(o);
|
---|
51 | }
|
---|
52 | Assert.assertTrue(nodes.isEmpty());
|
---|
53 | Assert.assertTrue(ways.isEmpty());
|
---|
54 | Assert.assertTrue(relations.isEmpty());
|
---|
55 | }
|
---|
56 |
|
---|
57 | private void checkIterator(Collection<? extends OsmPrimitive> col, int expectedCount) {
|
---|
58 | int count = 0;
|
---|
59 | Iterator<? extends OsmPrimitive> it = col.iterator();
|
---|
60 | while (it.hasNext()) {
|
---|
61 | count++;
|
---|
62 | it.next();
|
---|
63 | }
|
---|
64 | Assert.assertEquals(expectedCount, count);
|
---|
65 | }
|
---|
66 |
|
---|
67 | @Test
|
---|
68 | public void testRemove() throws Exception {
|
---|
69 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
|
---|
70 | try (InputStream fis = new FileInputStream("data_nodist/restriction.osm")) {
|
---|
71 | DataSet ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
|
---|
72 | removeAllTest(ds);
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Test
|
---|
77 | public void testMove() throws Exception {
|
---|
78 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
|
---|
79 | try (InputStream fis = new FileInputStream("data_nodist/restriction.osm")) {
|
---|
80 | DataSet ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
|
---|
81 |
|
---|
82 | for (Node n: ds.getNodes()) {
|
---|
83 | n.setCoor(new LatLon(10, 10));
|
---|
84 | }
|
---|
85 |
|
---|
86 | removeAllTest(ds);
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|