Changeset 11493 in josm


Ignore:
Timestamp:
2017-01-25T14:12:07+01:00 (2 years ago)
Author:
Don-vip
Message:

see #12627, see #14289 - add non regression unit tests

Location:
trunk
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r11386 r11493  
    463463
    464464    /**
     465     * remove a style source; only accessed from MapPaintStyles
     466     * @param style style source to remove
     467     * @return {@code true} if this list contained the specified element
     468     */
     469    boolean remove(StyleSource style) {
     470        return styleSources.remove(style);
     471    }
     472
     473    /**
    465474     * set the style sources; only accessed from MapPaintStyles
    466475     * @param sources new style sources
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r11401 r11493  
    290290
    291291    private static StyleSource fromSourceEntry(SourceEntry entry) {
     292        if (entry.url == null && entry instanceof MapCSSStyleSource) {
     293            return (MapCSSStyleSource) entry;
     294        }
    292295        Set<String> mimes = new HashSet<>(Arrays.asList(MapCSSStyleSource.MAPCSS_STYLE_MIME_TYPES.split(", ")));
    293296        try (CachedFile cf = new CachedFile(entry.url).setHttpAccept(Utils.join(", ", mimes))) {
     
    419422        styles.add(source);
    420423        loadStyleForFirstTime(source);
     424        refreshStyles();
     425        return source;
     426    }
     427
     428    /**
     429     * Remove a map paint style.
     430     * @param entry map paint style
     431     * @since 11493
     432     */
     433    public static void removeStyle(SourceEntry entry) {
     434        StyleSource source = fromSourceEntry(entry);
     435        if (styles.remove(source)) {
     436            refreshStyles();
     437        }
     438    }
     439
     440    private static void refreshStyles() {
    421441        MapPaintPrefHelper.INSTANCE.put(styles.getStyleSources());
    422442        fireMapPaintSylesUpdated();
     
    425445            Main.map.mapView.repaint();
    426446        }
    427         return source;
    428447    }
    429448
  • trunk/src/org/openstreetmap/josm/gui/preferences/map/MapPaintPreference.java

    r10611 r11493  
    272272        public Map<String, String> serialize(SourceEntry entry) {
    273273            Map<String, String> res = new HashMap<>();
    274             res.put("url", entry.url);
     274            res.put("url", entry.url == null ? "" : entry.url);
    275275            res.put("title", entry.title == null ? "" : entry.title);
    276276            res.put("active", Boolean.toString(entry.active));
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r11386 r11493  
    207207        File file = getFile();
    208208        if (file == null) {
    209             if (name.startsWith("resource://")) {
     209            if (name != null && name.startsWith("resource://")) {
    210210                InputStream is = getClass().getResourceAsStream(
    211211                        name.substring("resource:/".length()));
     
    273273            }
    274274        } catch (MalformedURLException e) {
    275             if (name.startsWith("resource://")) {
     275            if (name == null || name.startsWith("resource://")) {
    276276                return null;
    277277            } else if (name.startsWith("josmdir://")) {
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r11435 r11493  
    11661166     */
    11671167    public static boolean isLocalUrl(String url) {
    1168         if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("resource://"))
     1168        if (url == null || url.startsWith("http://") || url.startsWith("https://") || url.startsWith("resource://"))
    11691169            return false;
    11701170        return true;
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r11491 r11493  
    1010import java.io.StringReader;
    1111import java.util.Collection;
     12import java.util.HashSet;
    1213import java.util.Iterator;
    1314import java.util.LinkedHashSet;
     
    3233import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.ParseResult;
    3334import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.TagCheck;
     35import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
     36import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    3437import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
    3538import org.openstreetmap.josm.io.OsmReader;
     
    4851    @Rule
    4952    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    50     public JOSMTestRules test = new JOSMTestRules().projection();
     53    public JOSMTestRules test = new JOSMTestRules().projection().platform();
    5154
    5255    static MapCSSTagChecker buildTagChecker(String css) throws ParseException {
     
    216219        }
    217220    }
     221
     222    private void doTestNaturalWood(int ticket, String filename, int errorsCount, int setsCount) throws Exception {
     223        final MapCSSTagChecker test = buildTagChecker(
     224                "area:closed:areaStyle[tag(\"natural\") = parent_tag(\"natural\")] ⧉ area:closed:areaStyle[natural] {" +
     225                "  throwWarning: tr(\"Overlapping Identical Natural Areas\");" +
     226                "}");
     227        final MapCSSStyleSource style = new MapCSSStyleSource(
     228                "area[natural=wood] {" +
     229                "    fill-color: woodarea#008000;" +
     230                "}");
     231        MapPaintStyles.addStyle(style);
     232        try (InputStream is = TestUtils.getRegressionDataStream(ticket, filename)) {
     233            test.visit(OsmReader.parseDataSet(is, null).allPrimitives());
     234            List<TestError> errors = test.getErrors();
     235            assertEquals(errorsCount, errors.size());
     236            Set<Set<OsmPrimitive>> primitives = new HashSet<>();
     237            for (TestError e : errors) {
     238                primitives.add(new HashSet<>(e.getPrimitives()));
     239            }
     240            assertEquals(setsCount, primitives.size());
     241        } finally {
     242            MapPaintStyles.removeStyle(style);
     243        }
     244    }
     245
     246    /**
     247     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/12627">Bug #12627</a>.
     248     * @throws Exception if an error occurs
     249     */
     250    @Test
     251    @Ignore("not fixed yet")
     252    public void testTicket12627() throws Exception {
     253        doTestNaturalWood(12627, "overlapping.osm", 1, 1);
     254    }
     255
     256    /**
     257     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/14289">Bug #14289</a>.
     258     * @throws Exception if an error occurs
     259     */
     260    @Test
     261    @Ignore("not fixed yet")
     262    public void testTicket14289() throws Exception {
     263        doTestNaturalWood(14289, "example2.osm", 3, 3);
     264    }
    218265}
Note: See TracChangeset for help on using the changeset viewer.