Changeset 6568 in josm


Ignore:
Timestamp:
2013-12-30T23:57:06+01:00 (7 years ago)
Author:
simon04
Message:

fix #9462 - fix preset values for opening_hour/… such that the OpeningHourTest does not yield warnings, add unit test that validates all preset values

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/defaultpresets.xml

    r6562 r6568  
    237237        <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    238238    </chunk>
     239    <chunk id="service_times">
     240        <combo key="service_times" text="Service Times" delimiter="|" values="18:00|sunset,sunrise|Su 09:30,11:00|Sa,Su,PH 09:00|Sa 18:00; Su 10:45|Fr 08:00-18:00; Apr 10-15 off; Jun 07:00-20:00; Aug off; Dec 24 08:00-24:00|Sa 10:00+|week 1-53/2 Fr 09:00-12:00; week 2-52/2 We 09:00-12:00" />
     241    </chunk>
    239242    <chunk id="oh">
    240         <combo key="opening_hours" text="Opening Hours" delimiter="|" values="24/7|08:30-12:30,15:30-20:00|Sa-Su 00:00-24:00|Mo-Fr 08:30-20:00; Sa,Su 08:00-15:00; PH off|Mo-Fr 08:30-20:00,Tu-Su 08:00-15:00; Sa 08:00-12:00|Mo-Su 08:00-18:00; Apr 10-15 off; Jun 08:00-14:00; Aug off; Dec 25 off|sunrise-sunset|Su 10:00+|week 1-53/2 Fr 09:00-12:00; week 2-52/2 We 09:00-12:00" />
     243        <combo key="opening_hours" text="Opening Hours" delimiter="|" values="24/7|08:30-12:30,15:30-20:00|Sa-Su 00:00-24:00|Mo-Fr 08:30-20:00; Sa,Su 08:00-15:00; PH off|Mo-Fr 08:30-20:00, Tu-Su 08:00-15:00; Sa 08:00-12:00|Mo-Su 08:00-18:00; Apr 10-15 off; Jun 08:00-14:00; Aug off; Dec 25 off|sunrise-sunset|Su 10:00+|week 1-53/2 Fr 09:00-12:00; week 2-52/2 We 09:00-12:00" />
    241244    </chunk>
    242245    <chunk id="name_oh">
     
    36123615            <combo key="building" text="Building type" values="basilica,cathedral,chapel,church,temple" values_searchable="true" />
    36133616            <combo key="denomination" text="Denomination" values="anglican,baptist,catholic,evangelical,greek_catholic,greek_orthodox,jehovahs_witness,lutheran,methodist,mormon,new_apostolic,orthodox,pentecostal,presbyterian,protestant,quaker,roman_catholic,russian_orthodox,seventh_day_adventist" values_searchable="true" />
    3614             <combo key="service_times" text="Service Times" delimiter="|" values="18:00|sunset,sunrise|Su 9:30,11:00|Sa,Su,PH 9:00|Sa 18:00; Su 10:45|Fr 08:00-18:00; Apr 10-15 off; Jun 07:00-20:00; Aug off; Dec 24 08:00-24:00|Sa 10:00+|week 1-53/2 Fr 09:00-12:00; week 2-52/2 We 09:00-12:00" />
     3617            <reference ref="service_times" />
    36153618            <reference ref="oh" />
    36163619        </item>
     
    36363639            <combo key="building" text="Building type" values="mosque" values_searchable="true" />
    36373640            <combo key="denomination" text="Denomination" values="ibadi,shia,sunni" values_searchable="true" />
    3638             <combo key="service_times" text="Service Times" delimiter="|" values="18:00|sunset,sunrise|Su 9:30,11:00|Sa,Su,PH 9:00|Sa 18:00; Su 10:45|Fr 08:00-18:00; Apr 10-15 off; Jun 07:00-20:00; Aug off; Dec 24 08:00-24:00|Sa 10:00+|week 1-53/2 Fr 09:00-12:00; week 2-52/2 We 09:00-12:00" />
     3641            <reference ref="service_times" />
    36393642            <reference ref="oh" />
    36403643        </item>
     
    36603663            <combo key="building" text="Building type" values="synagogue" values_searchable="true" />
    36613664            <combo key="denomination" text="Denomination" values="orthodox,conservative,reform" values_searchable="true" />
    3662             <combo key="service_times" text="Service Times" delimiter="|" values="18:00|sunset,sunrise|Su 9:30,11:00|Sa,Su,PH 9:00|Sa 18:00; Su 10:45|Fr 08:00-18:00; Apr 10-15 off; Jun 07:00-20:00; Aug off; Dec 24 08:00-24:00|Sa 10:00+|week 1-53/2 Fr 09:00-12:00; week 2-52/2 We 09:00-12:00" />
     3665            <reference ref="service_times" />
    36633666            <reference ref="oh" />
    36643667        </item>
     
    36833686            <text key="name" text="Name" />
    36843687            <combo key="denomination" text="Denomination" values="theravada,mahayana,vajrayana" values_searchable="true" />
    3685             <combo key="service_times" text="Service Times" delimiter="|" values="18:00|sunset,sunrise|Su 9:30,11:00|Sa,Su,PH 9:00|Sa 18:00; Su 10:45|Fr 08:00-18:00; Apr 10-15 off; Jun 07:00-20:00; Aug off; Dec 24 08:00-24:00|Sa 10:00+|week 1-53/2 Fr 09:00-12:00; week 2-52/2 We 09:00-12:00" />
     3688            <reference ref="service_times" />
    36863689            <reference ref="oh" />
    36873690        </item>
     
    37063709            <text key="name" text="Name" />
    37073710            <combo key="denomination" text="Denomination" values="vaishnavism,shaivism,shaktism,smartism" values_searchable="true" />
    3708             <combo key="service_times" text="Service Times" delimiter="|" values="18:00|sunset,sunrise|Su 9:30,11:00|Sa,Su,PH 9:00|Sa 18:00; Su 10:45|Fr 08:00-18:00; Apr 10-15 off; Jun 07:00-20:00; Aug off; Dec 24 08:00-24:00|Sa 10:00+|week 1-53/2 Fr 09:00-12:00; week 2-52/2 We 09:00-12:00" />
     3711            <reference ref="service_times" />
    37093712            <reference ref="oh" />
    37103713        </item>
     
    37283731            <key key="religion" value="shinto" />
    37293732            <text key="name" text="Name" />
    3730             <combo key="service_times" text="Service Times" delimiter="|" values="18:00|sunset,sunrise|Su 9:30,11:00|Sa,Su,PH 9:00|Sa 18:00; Su 10:45|Fr 08:00-18:00; Apr 10-15 off; Jun 07:00-20:00; Aug off; Dec 24 08:00-24:00|Sa 10:00+|week 1-53/2 Fr 09:00-12:00; week 2-52/2 We 09:00-12:00" />
     3733            <reference ref="service_times" />
    37313734            <reference ref="oh" />
    37323735        </item>
     
    37503753            <text key="name" text="Name" />
    37513754            <combo key="religion" text="Religion" values="bahai,jain,sikh,spiritualist,taoist,unitarian,zoroastrian" match="keyvalue" values_searchable="true" />
    3752             <combo key="service_times" text="Service Times" delimiter="|" values="18:00|sunset,sunrise|Su 9:30,11:00|Sa,Su,PH 9:00|Sa 18:00; Su 10:45|Fr 08:00-18:00; Apr 10-15 off; Jun 07:00-20:00; Aug off; Dec 24 08:00-24:00|Sa 10:00+|week 1-53/2 Fr 09:00-12:00; week 2-52/2 We 09:00-12:00" />
     3755            <reference ref="service_times" />
    37533756            <reference ref="oh" />
    37543757        </item>
     
    41004103            <text key="operator" text="Operator" />
    41014104            <text key="ref" text="Reference number" />
    4102             <combo key="collection_times" text="Collection times" delimiter="|" values="11:30|Mo-Fr 15:00,17:45,19:00,23:00; Sa 15:10; Su 10:30,23:00|Mo-Fr 09:00-12:00,17:15; Sa 14:00; So,PH off" />
     4105            <combo key="collection_times" text="Collection times" delimiter="|" values="11:30|Mo-Fr 15:00,17:45,19:00,23:00; Sa 15:10; Su 10:30,23:00|Mo-Fr 09:00-12:00,17:15; Sa 14:00; Su,PH off" />
    41034106            <check key="drive_through" text="Drive through" />
    41044107        </item>
     
    41494152            <space />
    41504153            <key key="emergency" value="aed" />
    4151             <combo key="opening_hours" text="Opening Hours" values="24/7,limited" />
     4154            <reference ref="oh" />
    41524155            <text  key="operator" text="Operator" />
    41534156            <check key="indoor" text="Located inside a building?" />
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java

    r6552 r6568  
    123123
    124124        /**
    125          * Constructs a new {@code OpeningHoursTestError}.
    126          * @param message The error message
    127          * @param severity The error severity
    128          */
    129         public OpeningHoursTestError(String message, Severity severity) {
    130             this(message, severity, null);
    131         }
    132 
    133         /**
    134125         * Returns the real test error given to JOSM validator.
    135126         * @param p The incriminated OSM primitive.
     
    168159        public Severity getSeverity() {
    169160            return severity;
     161        }
     162
     163        @Override
     164        public String toString() {
     165            return getMessage() + " => " + getPrettifiedValue();
    170166        }
    171167    }
     
    217213     */
    218214    public List<OpeningHoursTestError> checkOpeningHourSyntax(final String key, final String value) {
    219         return checkOpeningHourSyntax(key, value, CheckMode.TIME_RANGE);
     215        return checkOpeningHourSyntax(key, value, "opening_hours".equals(key) ? CheckMode.TIME_RANGE : CheckMode.BOTH);
    220216    }
    221217
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java

    r6533 r6568  
    55import org.junit.Test;
    66import org.openstreetmap.josm.Main;
     7import org.openstreetmap.josm.data.osm.Tag;
    78import org.openstreetmap.josm.data.validation.Severity;
     9import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;
     10import org.openstreetmap.josm.gui.tagging.TaggingPreset;
     11import org.openstreetmap.josm.gui.tagging.TaggingPresetItem;
     12import org.openstreetmap.josm.gui.tagging.TaggingPresetItems;
     13import org.openstreetmap.josm.gui.tagging.TaggingPresetReader;
     14import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction;
    815
     16import java.util.Arrays;
     17import java.util.Collection;
     18import java.util.LinkedHashSet;
    919import java.util.List;
     20import java.util.Set;
    1021
    1122import static org.CustomMatchers.hasSize;
     
    128139        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00"));
    129140    }
     141
     142    @Test
     143    public void testPresetValues() throws Exception {
     144        final Collection<TaggingPreset> presets = TaggingPresetReader.readFromPreferences(false);
     145        final Set<Tag> values = new LinkedHashSet<Tag>();
     146        for (final TaggingPreset p : presets) {
     147            for (final TaggingPresetItem i : p.data) {
     148                if (i instanceof TaggingPresetItems.KeyedItem &&
     149                        Arrays.asList("opening_hours", "service_times", "collection_times").contains(((TaggingPresetItems.KeyedItem) i).key)) {
     150                    for (final String v : ((TaggingPresetItems.KeyedItem) i).getValues()) {
     151                        values.add(new Tag(((TaggingPresetItems.KeyedItem) i).key, v));
     152                    }
     153                }
     154            }
     155        }
     156        for (final Tag t : values) {
     157            final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(t.getKey(), t.getValue());
     158            assertThat(t + " is valid", errors, isEmpty());
     159        }
     160    }
    130161}
Note: See TracChangeset for help on using the changeset viewer.