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

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

test cleanup

  • Property svn:eol-style set to native
File size: 4.7 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 assert source.rules[0].selectors.size() == 1
60 return source.rules[0].selectors[0]
61 }
62
63 @Test
64 @Ignore
65 public void matches_1() {
66 def css = """
67 relation >[role="my_role"] node {}
68 """
69 ChildOrParentSelector selector = parse(css)
70
71 Relation r = relation(1)
72 Node n = node(1)
73 r.addMember(new RelationMember("my_role", n))
74 Environment e = new Environment().withChild(n)
75
76 assert selector.matches(e)
77 }
78
79 @Test
80 @Ignore
81 public void matches_2() {
82 def css = """
83 relation >["my_role"] node {}
84 """
85 ChildOrParentSelector selector = parse(css)
86
87 Relation r = relation(1)
88 Node n = node(1)
89 r.addMember(new RelationMember("my_role", n))
90 Environment e = new Environment().withChild(n)
91
92 assert selector.matches(e)
93 }
94
95 @Test
96 @Ignore
97 public void matches_3() {
98 def css = """
99 relation >[!"my_role"] node {}
100 """
101 ChildOrParentSelector selector = parse(css)
102
103 Relation r = relation(1)
104 Node n = node(1)
105 r.addMember(new RelationMember("my_role", n))
106 Environment e = new Environment().withChild(n)
107
108 assert !selector.matches(e)
109 }
110
111 @Test
112 @Ignore
113 public void matches_4() {
114 def css = """
115 way < relation {}
116 """
117 ChildOrParentSelector selector = parse(css)
118 assert selector.parentSelector
119
120 }
121 @Test
122 public void matches_5() {
123 def css = """
124 way <[role != "my_role"] relation {}
125 """
126 ChildOrParentSelector selector = parse(css)
127 assert selector.parentSelector
128
129 Relation r = relation(1)
130 Way w1 = way(1)
131 w1.setNodes([node(11), node(12)])
132
133 Way w2 = way(2)
134 w2.setNodes([node(21), node(22)])
135
136 Way w3 = way(3)
137 w3.setNodes([node(31), node(32)])
138
139 r.addMember(new RelationMember("my_role", w1))
140 r.addMember(new RelationMember("my_role", w2))
141 r.addMember(new RelationMember("another role", w3))
142
143 Environment e = new Environment().withPrimitive(r)
144 assert selector.matches(e)
145 }
146
147 @Test
148 public void matches_6() {
149 def css = """
150 relation >[role != "my_role"] way {}
151 """
152 ChildOrParentSelector selector = parse(css)
153
154 Relation r = relation(1)
155 Way w1 = way(1)
156 w1.setNodes([node(11), node(12)])
157
158 Way w2 = way(2)
159 w2.setNodes([node(21), node(22)])
160
161 Way w3 = way(3)
162 w3.setNodes([node(31), node(32)])
163
164 r.addMember(new RelationMember("my_role", w1))
165 r.addMember(new RelationMember("my_role", w2))
166 r.addMember(new RelationMember("another role", w3))
167
168 Environment e = new Environment().withPrimitive(w1)
169 assert !selector.matches(e)
170
171 e = new Environment().withPrimitive(w2)
172 assert !selector.matches(e)
173
174 e = new Environment().withPrimitive(w3)
175 assert selector.matches(e)
176 }
177}
Note: See TracBrowser for help on using the repository browser.