Changeset 12002 in josm


Ignore:
Timestamp:
2017-04-25T19:33:21+02:00 (2 years ago)
Author:
stoecker
Message:

fix #14692 - relatation checker test broken

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java

    r11998 r12002  
    88import java.util.EnumSet;
    99import java.util.HashMap;
     10import java.util.LinkedHashMap;
    1011import java.util.LinkedList;
    1112import java.util.List;
     
    101102    @Override
    102103    public void visit(Relation n) {
    103         List<Role> allroles = buildAllRoles(n);
     104        Map<Role, String> allroles = buildAllRoles(n);
    104105        if (allroles.isEmpty() && n.hasTag("type", "route")
    105106                && n.hasTag("route", "train", "subway", "monorail", "tram", "bus", "trolleybus", "aerialway", "ferry")) {
     
    141142
    142143    // return Roles grouped by key
    143     private static List<Role> buildAllRoles(Relation n) {
    144         List<Role> allroles = new LinkedList<>();
     144    private static Map<Role, String> buildAllRoles(Relation n) {
     145        Map<Role, String> allroles = new LinkedHashMap<>();
    145146
    146147        for (TaggingPreset p : relationpresets) {
     
    148149            final Roles r = Utils.find(p.data, Roles.class);
    149150            if (matches && r != null) {
    150                 allroles.addAll(r.roles);
     151                for (Role role: r.roles) {
     152                    allroles.put(role, p.name);
     153                }
    151154            }
    152155        }
     
    185188     *
    186189     */
    187     private boolean checkMemberExpressionAndType(List<Role> allroles, RelationMember member, Relation n) {
     190    private boolean checkMemberExpressionAndType(Map<Role, String> allroles, RelationMember member, Relation n) {
    188191        String role = member.getRole();
    189192        String name = null;
     
    193196        // iterate through all of the role definition within preset
    194197        // and look for any matching definition
    195         for (Role r: allroles) {
     198        for (Map.Entry<Role, String> e : allroles.entrySet()) {
     199            Role r = e.getKey();
    196200            if (!r.isRole(role)) {
    197201                continue;
    198202            }
    199             name = r.key;
     203            name = e.getValue();
    200204            types.addAll(r.types);
    201205            if (checkMemberType(r, member)) {
     
    266270     * @param map contains statistics of occurances of specified role types in relation
    267271     */
    268     private void checkRoles(Relation n, List<Role> allroles, Map<String, RoleInfo> map) {
     272    private void checkRoles(Relation n, Map<Role, String> allroles, Map<String, RoleInfo> map) {
    269273        // go through all members of relation
    270274        for (RelationMember member: n.getMembers()) {
     
    274278
    275279        // verify role counts based on whole role sets
    276         for (Role r: allroles) {
     280        for (Role r: allroles.keySet()) {
    277281            String keyname = r.key;
    278282            if (keyname.isEmpty()) {
     
    287291        for (String key : map.keySet()) {
    288292            boolean found = false;
    289             for (Role r: allroles) {
     293            for (Role r: allroles.keySet()) {
    290294                if (r.isRole(key)) {
    291295                    found = true;
     
    295299
    296300            if (!found) {
    297                 String templates = allroles.stream().map(r -> r.key).collect(Collectors.joining("/"));
     301                String templates = allroles.keySet().stream().map(r -> r.key).collect(Collectors.joining("/"));
    298302
    299303                if (!key.isEmpty()) {
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/RelationCheckerTest.java

    r11479 r12002  
    139139
    140140    @Test
     141    public void testBuildingMemberExpression() {
     142        Relation r = createRelation("type=building");
     143        r.addMember(new RelationMember("outline", new Way()));
     144        r.addMember(new RelationMember("part", new Way()));
     145        r.addMember(new RelationMember("level_-12", new Relation()));
     146        r.addMember(new RelationMember("level_0", new Relation()));
     147        r.addMember(new RelationMember("level_12", new Relation()));
     148        r.addMember(new RelationMember("level_x", new Relation())); // fails
     149
     150        List<TestError> errors = testRelation(r);
     151        assertEquals(1, errors.size());
     152        assertEquals("Role 'level_x' unknown in templates 'outline/part/ridge/edge/entrance/level_-?\\d+'", errors.get(0).getDescription());
     153    }
     154
     155    @Test
    141156    public void testRouteMemberExpression() {
    142157        Relation r = createRelation("type=route route=tram public_transport:version=2");
Note: See TracChangeset for help on using the changeset viewer.