Ignore:
Timestamp:
2019-06-29T23:07:03+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #17845 - Add a MapCSS method to check for roles in relations (patch by taylor.smock)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java

    r14796 r15196  
    1414import org.junit.Rule;
    1515import org.junit.Test;
     16import org.openstreetmap.josm.TestUtils;
    1617import org.openstreetmap.josm.data.coor.LatLon;
    1718import org.openstreetmap.josm.data.osm.DataSet;
    1819import org.openstreetmap.josm.data.osm.Node;
    1920import org.openstreetmap.josm.data.osm.OsmUtils;
     21import org.openstreetmap.josm.data.osm.Relation;
     22import org.openstreetmap.josm.data.osm.RelationMember;
    2023import org.openstreetmap.josm.data.osm.Way;
    2124import org.openstreetmap.josm.gui.mappaint.Environment;
     
    405408
    406409    @Test
     410    public void testCountRoles() throws Exception {
     411        DataSet ds = new DataSet();
     412        Way way1 = TestUtils.newWay("highway=residential name=1",
     413                new Node(new LatLon(0, 0)), new Node((new LatLon(0.001, 0.001))));
     414        for (Node node : way1.getNodes()) {
     415            ds.addPrimitive(node);
     416        }
     417        ds.addPrimitive(way1);
     418
     419        Relation rel1 = TestUtils.newRelation("type=destination_sign", new RelationMember("", way1));
     420        ds.addPrimitive(rel1);
     421
     422        /* Check with empty role and one object */
     423        Environment e = new Environment(rel1, new MultiCascade(), Environment.DEFAULT_LAYER, null);
     424        assertEquals(1, ExpressionFactory.Functions.count_roles(e, ""));
     425
     426        /* Check with non-empty role and one object */
     427        e = new Environment(rel1, new MultiCascade(), Environment.DEFAULT_LAYER, null);
     428        assertEquals(0, ExpressionFactory.Functions.count_roles(e, "from"));
     429
     430        /* Check with empty role and two objects */
     431        Way way2 = TestUtils.newWay("highway=residential name=2", way1.firstNode(), way1.lastNode());
     432        ds.addPrimitive(way2);
     433        rel1.addMember(new RelationMember("", way2));
     434        e = new Environment(rel1, new MultiCascade(), Environment.DEFAULT_LAYER, null);
     435        assertEquals(2, ExpressionFactory.Functions.count_roles(e, ""));
     436
     437        /* Check with non-empty role and two objects */
     438        rel1.setMember(0, new RelationMember("from", way1));
     439        e = new Environment(rel1, new MultiCascade(), Environment.DEFAULT_LAYER, null);
     440        assertEquals(1, ExpressionFactory.Functions.count_roles(e, "from"));
     441
     442        /* Check with multiple roles */
     443        assertEquals(1, ExpressionFactory.Functions.count_roles(e, "from", "to"));
     444
     445        /* Check with non-relation */
     446        e = new Environment(way1, new MultiCascade(), Environment.DEFAULT_LAYER, null);
     447        assertEquals(0, ExpressionFactory.Functions.count_roles(e, "from", "to"));
     448    }
     449
     450    @Test
    407451    public void testSiblingSelectorInterpolation() throws Exception {
    408452        ChildOrParentSelector s1 = (Selector.ChildOrParentSelector) getParser(
Note: See TracChangeset for help on using the changeset viewer.