source: josm/trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/ChildOrParentSelectorTest.groovy@ 7081

Last change on this file since 7081 was 7081, checked in by Don-vip, 10 years ago

fixes for unit tests

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.mapcss;
3
4import static org.junit.Assert.*
5
6import java.util.logging.Logger
7
8import org.junit.*
9import org.openstreetmap.josm.JOSMFixture
10import org.openstreetmap.josm.data.coor.LatLon
11import org.openstreetmap.josm.data.osm.DataSet
12import org.openstreetmap.josm.data.osm.Node
13import org.openstreetmap.josm.data.osm.Relation
14import org.openstreetmap.josm.data.osm.RelationMember
15import org.openstreetmap.josm.data.osm.Way
16import org.openstreetmap.josm.gui.mappaint.Environment
17import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector
18
19class ChildOrParentSelectorTest {
20 static private Logger logger = Logger.getLogger(ChildOrParentSelectorTest.class.getName());
21
22 def shouldFail = new GroovyTestCase().&shouldFail
23
24 def DataSet ds;
25
26 @BeforeClass
27 public static void createJOSMFixture(){
28 JOSMFixture.createUnitTestFixture().init()
29 }
30
31 @Before
32 public void setUp() {
33 ds = new DataSet()
34 }
35
36 def relation(id) {
37 def r = new Relation(id,1)
38 ds.addPrimitive(r)
39 return r
40 }
41
42 def node(id) {
43 def n = new Node(id,1)
44 n.setCoor(new LatLon(0,0))
45 ds.addPrimitive(n)
46 return n
47 }
48
49 def way(id){
50 def w = new Way(id,1)
51 ds.addPrimitive(w)
52 return w
53 }
54
55 def ChildOrParentSelector parse(css){
56 MapCSSStyleSource source = new MapCSSStyleSource(css)
57 source.loadStyleSource()
58 assert source.rules.size() == 1
59 return source.rules[0].selector
60 }
61
62 @Test
63 @Ignore
64 public void matches_1() {
65 def css = """
66 relation >[role="my_role"] node {}
67 """
68 ChildOrParentSelector selector = parse(css)
69
70 Relation r = relation(1)
71 Node n = node(1)
72 r.addMember(new RelationMember("my_role", n))
73 Environment e = new Environment().withChild(n)
74
75 assert selector.matches(e)
76 }
77
78 @Test
79 @Ignore
80 public void matches_2() {
81 def css = """
82 relation >["my_role"] node {}
83 """
84 ChildOrParentSelector selector = parse(css)
85
86 Relation r = relation(1)
87 Node n = node(1)
88 r.addMember(new RelationMember("my_role", n))
89 Environment e = new Environment().withChild(n)
90
91 assert selector.matches(e)
92 }
93
94 @Test
95 @Ignore
96 public void matches_3() {
97 def css = """
98 relation >[!"my_role"] node {}
99 """
100 ChildOrParentSelector selector = parse(css)
101
102 Relation r = relation(1)
103 Node n = node(1)
104 r.addMember(new RelationMember("my_role", n))
105 Environment e = new Environment().withChild(n)
106
107 assert !selector.matches(e)
108 }
109
110 @Test
111 @Ignore
112 public void matches_4() {
113 def css = """
114 way < relation {}
115 """
116 ChildOrParentSelector selector = parse(css)
117 assert selector.type == Selector.ChildOrParentSelectorType.PARENT
118
119 }
120 @Test
121 public void matches_5() {
122 def css = """
123 way <[role != "my_role"] relation {}
124 """
125 ChildOrParentSelector selector = parse(css)
126 assert selector.type == Selector.ChildOrParentSelectorType.PARENT
127
128 Relation r = relation(1)
129 Way w1 = way(1)
130 w1.setNodes([node(11), node(12)])
131
132 Way w2 = way(2)
133 w2.setNodes([node(21), node(22)])
134
135 Way w3 = way(3)
136 w3.setNodes([node(31), node(32)])
137
138 r.addMember(new RelationMember("my_role", w1))
139 r.addMember(new RelationMember("my_role", w2))
140 r.addMember(new RelationMember("another role", w3))
141
142 Environment e = new Environment().withPrimitive(r)
143 assert selector.matches(e)
144 }
145
146 @Test
147 public void matches_6() {
148 def css = """
149 relation >[role != "my_role"] way {}
150 """
151 ChildOrParentSelector selector = parse(css)
152
153 Relation r = relation(1)
154 Way w1 = way(1)
155 w1.setNodes([node(11), node(12)])
156
157 Way w2 = way(2)
158 w2.setNodes([node(21), node(22)])
159
160 Way w3 = way(3)
161 w3.setNodes([node(31), node(32)])
162
163 r.addMember(new RelationMember("my_role", w1))
164 r.addMember(new RelationMember("my_role", w2))
165 r.addMember(new RelationMember("another role", w3))
166
167 Environment e = new Environment().withPrimitive(w1)
168 assert !selector.matches(e)
169
170 e = new Environment().withPrimitive(w2)
171 assert !selector.matches(e)
172
173 e = new Environment().withPrimitive(w3)
174 assert selector.matches(e)
175 }
176}
Note: See TracBrowser for help on using the repository browser.