[4069] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui.mappaint.mapcss;
|
---|
| 3 |
|
---|
| 4 | import static org.junit.Assert.*
|
---|
| 5 |
|
---|
| 6 | import org.junit.*
|
---|
| 7 | import org.openstreetmap.josm.data.coor.LatLon
|
---|
| 8 | import org.openstreetmap.josm.data.osm.DataSet
|
---|
| 9 | import org.openstreetmap.josm.data.osm.Node
|
---|
| 10 | import org.openstreetmap.josm.data.osm.Relation
|
---|
| 11 | import org.openstreetmap.josm.data.osm.RelationMember
|
---|
| 12 | import org.openstreetmap.josm.fixtures.JOSMFixture
|
---|
| 13 | import org.openstreetmap.josm.gui.mappaint.Environment
|
---|
| 14 | import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context
|
---|
| 15 | import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Op
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | class KeyValueConditionTest {
|
---|
| 19 |
|
---|
| 20 | def shouldFail = new GroovyTestCase().&shouldFail
|
---|
| 21 |
|
---|
| 22 | def DataSet ds;
|
---|
| 23 |
|
---|
| 24 | @BeforeClass
|
---|
| 25 | public static void createJOSMFixture(){
|
---|
| 26 | JOSMFixture.createUnitTestFixture().init()
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | @Before
|
---|
| 30 | public void setUp() {
|
---|
| 31 | ds = new DataSet()
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | def relation(id) {
|
---|
| 35 | def r = new Relation(id,1)
|
---|
| 36 | ds.addPrimitive(r)
|
---|
| 37 | return r
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | def node(id) {
|
---|
| 41 | def n = new Node(id,1)
|
---|
| 42 | n.setCoor(new LatLon(0,0))
|
---|
| 43 | ds.addPrimitive(n)
|
---|
| 44 | return n
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | @Test
|
---|
| 48 | public void create() {
|
---|
| 49 | Condition c = Condition.create("a key", "a value", Op.EQ, Context.PRIMITIVE)
|
---|
| 50 |
|
---|
| 51 | c = Condition.create("role", "a role", Op.EQ, Context.LINK)
|
---|
| 52 | c = Condition.create("RoLe", "a role", Op.EQ, Context.LINK)
|
---|
| 53 |
|
---|
| 54 | shouldFail(MapCSSException) {
|
---|
| 55 | c = Condition.create("an arbitry tag", "a role", Op.EQ, Context.LINK)
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | @Test
|
---|
| 60 | public void applies_1() {
|
---|
| 61 | Relation r = relation(1)
|
---|
| 62 | Node n = node(1)
|
---|
| 63 | r.addMember(new RelationMember("my_role", n))
|
---|
| 64 |
|
---|
| 65 | Environment e = new Environment().withPrimitive(n).withParent(r).withLinkContext().withIndex(0)
|
---|
| 66 |
|
---|
| 67 | Condition cond = new Condition.RoleCondition("my_role", Op.EQ)
|
---|
| 68 | assert cond.applies(e)
|
---|
| 69 |
|
---|
| 70 | cond = new Condition.RoleCondition("another_role", Op.EQ)
|
---|
| 71 | assert !cond.applies(e)
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | @Test
|
---|
| 75 | public void applies_2() {
|
---|
| 76 | Relation r = relation(1)
|
---|
| 77 | Node n = node(1)
|
---|
| 78 | r.addMember(new RelationMember("my_role", n))
|
---|
| 79 |
|
---|
| 80 | Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0).withLinkContext()
|
---|
| 81 |
|
---|
| 82 | Condition cond = Condition.create("role", "my_role", Op.NEQ, Context.LINK)
|
---|
| 83 | assert !cond.applies(e)
|
---|
| 84 |
|
---|
| 85 | cond = Condition.create("role", "another_role", Op.NEQ, Context.LINK)
|
---|
| 86 | assert cond.applies(e)
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | }
|
---|
[4074] | 92 |
|
---|