1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | import java.util.Iterator;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.Main;
|
---|
5 | import org.openstreetmap.josm.data.osm.Node;
|
---|
6 | import org.openstreetmap.josm.data.osm.Segment;
|
---|
7 | import org.openstreetmap.josm.data.osm.Way;
|
---|
8 |
|
---|
9 | import framework.FunctionalTestCase;
|
---|
10 |
|
---|
11 | public class NodeTest extends FunctionalTestCase {
|
---|
12 |
|
---|
13 | public void test() throws Exception {
|
---|
14 | key("ctrl-n");
|
---|
15 | assertNotNull(Main.map);
|
---|
16 |
|
---|
17 | key("n");
|
---|
18 | click(100,500);
|
---|
19 | assertEquals(1, Main.ds.nodes.size());
|
---|
20 | assertEquals(1, Main.ds.getSelected().size());
|
---|
21 | assertEquals(Main.ds.nodes.iterator().next(), Main.ds.getSelected().iterator().next());
|
---|
22 |
|
---|
23 | key("d");
|
---|
24 | assertEquals(0, Main.ds.getSelected().size());
|
---|
25 | assertEquals(0, Main.ds.allNonDeletedPrimitives().size());
|
---|
26 |
|
---|
27 | key("ctrl-z", "n");
|
---|
28 | click(200,500);
|
---|
29 | key("g");
|
---|
30 | drag(200,500,100,500);
|
---|
31 | key("n","shift-n");
|
---|
32 | click(150,500);
|
---|
33 | assertEquals(3, Main.ds.nodes.size());
|
---|
34 | assertEquals(2, Main.ds.segments.size());
|
---|
35 | assertEquals(1, Main.ds.getSelected().size());
|
---|
36 |
|
---|
37 | Node n = (Node)Main.ds.getSelected().iterator().next();
|
---|
38 | Iterator<Segment> segIt = Main.ds.segments.iterator();
|
---|
39 | Segment s1 = segIt.next();
|
---|
40 | Segment s2 = segIt.next();
|
---|
41 | if (s1.from == n)
|
---|
42 | assertSame(n, s2.to);
|
---|
43 | else
|
---|
44 | assertSame(n, s2.from);
|
---|
45 |
|
---|
46 | key("shift-n");
|
---|
47 | click(150,550);
|
---|
48 | checkSegments(n);
|
---|
49 |
|
---|
50 | key("ctrl-z", "w");
|
---|
51 | click(125,500);
|
---|
52 | click(175,500);
|
---|
53 | assertEquals(1, Main.ds.ways.size());
|
---|
54 | key("s");
|
---|
55 | click(150,500);
|
---|
56 | key("n");
|
---|
57 | click(150,550);
|
---|
58 | assertEquals(1, Main.ds.ways.size());
|
---|
59 | Way way = Main.ds.ways.iterator().next();
|
---|
60 | assertEquals("segment not added to middle of way", 2, way.segments.size());
|
---|
61 | checkSegments(n);
|
---|
62 |
|
---|
63 | key("ctrl-z", "s");
|
---|
64 | assertEquals(2, Main.ds.segments.size());
|
---|
65 | segIt = Main.ds.segments.iterator();
|
---|
66 | s1 = segIt.next();
|
---|
67 | s2 = segIt.next();
|
---|
68 | click(100,500);
|
---|
69 | key("n");
|
---|
70 | click(100,550);
|
---|
71 | assertEquals(1, Main.ds.ways.size());
|
---|
72 | assertSame(way, Main.ds.ways.iterator().next());
|
---|
73 | assertEquals(3, way.segments.size());
|
---|
74 | segIt = way.segments.iterator();
|
---|
75 | assertSame(s1, segIt.next());
|
---|
76 | assertSame(s2, segIt.next());
|
---|
77 | assertSame(s2.to, segIt.next().from);
|
---|
78 |
|
---|
79 | key("ctrl-z", "s");
|
---|
80 | click(200,500);
|
---|
81 | key("n");
|
---|
82 | click(200,550);
|
---|
83 | assertEquals(1, Main.ds.ways.size());
|
---|
84 | assertSame(way, Main.ds.ways.iterator().next());
|
---|
85 | segIt = way.segments.iterator();
|
---|
86 | assertSame(s1.from, segIt.next().to);
|
---|
87 | assertSame(s1, segIt.next());
|
---|
88 | assertSame(s2, segIt.next());
|
---|
89 | }
|
---|
90 |
|
---|
91 | private void checkSegments(Node n) {
|
---|
92 | assertEquals(3, Main.ds.segments.size());
|
---|
93 | assertEquals(4, Main.ds.nodes.size());
|
---|
94 |
|
---|
95 | Iterator<Segment> segIt = Main.ds.segments.iterator();
|
---|
96 | Segment s1 = segIt.next();
|
---|
97 | Segment s2 = segIt.next();
|
---|
98 | Segment s3 = segIt.next();
|
---|
99 | if (s1.to == n) {
|
---|
100 | assertSame(n, s2.from);
|
---|
101 | assertSame(n, s3.from);
|
---|
102 | } else if (s2.to == n) {
|
---|
103 | assertSame(n, s1.from);
|
---|
104 | assertSame(n, s3.from);
|
---|
105 | } else {
|
---|
106 | assertSame(n, s1.from);
|
---|
107 | assertSame(n, s2.from);
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|