Changeset 18287 in josm for trunk/test


Ignore:
Timestamp:
2021-10-19T01:26:15+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #20913 - fix handling of GPX files in sessions (patch by Bjoeni)

  • revert r17659 (except for unit tests) - see #20233
    • don't save GPX track and marker colors in session file anymore, but in the GPX files as extensions (like before)
    • don't ask to save unmodified GPX file
    • don't override global color settings when individual track doesn't have a color
  • ask user to save changes to GPX file when any drawing settings or marker colors have changed (currently only happens for track colors)
  • save marker color values to session even when corresponding GPX layer has already been deleted
  • save alpha values for GPX marker colors
  • added explanation to the "overwrite GPX file" dialog
  • inform user if not all files referenced by the session file are saved yet
  • allow user to save all files that are not included in the *.jos/*.joz but are only referenced in the session file
  • display * next to GPX layers that need to be saved (move isDirty() logic from OsmDataLayer to AbstractModifiableLayer)
Location:
trunk/test
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/data/sessions/gpx_markers.jos

    r17659 r18287  
    1616            <file>layers/01/data.gpx</file>
    1717        </layer>
    18         <layer color="#34567812" index="2" name="Marker layer name" opacity="0.5" type="markers" version="0.1" visible="true">
     18        <layer index="2" name="Marker layer name" opacity="0.5" type="markers" version="0.1" visible="true">
    1919            <file>layers/02/data.gpx</file>
    2020        </layer>
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxDataTest.java

    r18207 r18287  
    504504        EqualsVerifier.forClass(GpxData.class).usingGetClass()
    505505            .suppress(Warning.NONFINAL_FIELDS)
    506             .withIgnoredFields("creator", "fromServer", "storageFile", "initializing", "updating",
     506            .withIgnoredFields("creator", "fromServer", "fromSession", "storageFile", "initializing", "updating",
    507507                    "suppressedInvalidate", "listeners", "tracks", "routes", "waypoints", "proxy", "segSpans", "modified")
    508508            .withPrefabValues(WayPoint.class, new WayPoint(LatLon.NORTH_POLE), new WayPoint(LatLon.SOUTH_POLE))
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxTrackTest.java

    r17275 r18287  
    99import java.util.HashMap;
    1010
     11import org.junit.jupiter.api.Test;
    1112import org.junit.jupiter.api.extension.RegisterExtension;
    12 import org.junit.jupiter.api.Test;
    1313import org.openstreetmap.josm.TestUtils;
    1414import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    3232
    3333    /**
    34      * Tests weather the track can read and write colors.
     34     * Tests whether the track can read and write colors.
    3535     */
    3636    @Test
  • trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java

    r17659 r18287  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.io.session;
     3
     4import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.fail;
    36
    47import java.awt.Color;
    58import java.io.File;
    69import java.io.IOException;
    7 import java.io.InputStream;
    810import java.nio.charset.StandardCharsets;
    911import java.nio.file.Files;
    1012import java.nio.file.Path;
    1113import java.nio.file.Paths;
     14import java.time.Instant;
    1215import java.util.Arrays;
    1316import java.util.Collections;
     
    1518import java.util.List;
    1619import java.util.Map;
     20import java.util.stream.Collectors;
     21import java.util.zip.ZipEntry;
    1722import java.util.zip.ZipFile;
    1823
     
    4348import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    4449
    45 import static org.junit.jupiter.api.Assertions.assertEquals;
    46 
    4750/**
    4851 * Unit tests for Session writing.
     
    109112    }
    110113
    111     private byte[] testWrite(List<Layer> layers, final boolean zip) throws IOException {
     114    private Map<String, byte[]> testWrite(List<Layer> layers, final boolean zip) throws IOException {
    112115        Map<Layer, SessionLayerExporter> exporters = new HashMap<>();
    113116        if (zip) {
     
    119122        }
    120123        for (final Layer l : layers) {
    121             exporters.put(l, SessionWriter.getSessionLayerExporter(l));
     124            SessionLayerExporter s = SessionWriter.getSessionLayerExporter(l);
     125            exporters.put(l, s);
     126            if (s instanceof GpxTracksSessionExporter) {
     127                ((GpxTracksSessionExporter) s).setMetaTime(Instant.parse("2021-10-16T18:27:12.351Z"));
     128            } else if (s instanceof MarkerSessionExporter) {
     129                ((MarkerSessionExporter) s).setMetaTime(Instant.parse("2021-10-16T18:27:12.351Z"));
     130            }
    122131        }
    123132        SessionWriter sw = new SessionWriter(layers, -1, exporters, new MultiMap<Layer, Layer>(), zip);
     
    128137                return null;
    129138            }
    130             try (ZipFile zipFile = new ZipFile(file);
    131                  InputStream input = zipFile.getInputStream(zipFile.getEntry("session.jos"))) {
    132                 return Utils.readBytesFromStream(input);
     139            try (ZipFile zipFile = new ZipFile(file)) {
     140                return Collections.list(zipFile.entries()).stream().collect(Collectors.toMap(ZipEntry::getName, e -> {
     141                    try {
     142                        return Utils.readBytesFromStream(zipFile.getInputStream(e));
     143                    } catch (IOException ex) {
     144                        fail(ex);
     145                    }
     146                    return null;
     147                }));
    133148            }
    134149        } finally {
     
    147162    private GpxLayer createGpxLayer() {
    148163        GpxData data = new GpxData();
    149         data.waypoints.add(new WayPoint(new LatLon(42.72665, -0.00747)));
     164        WayPoint wp = new WayPoint(new LatLon(42.72665, -0.00747));
     165        wp.setInstant(Instant.parse("2021-01-01T10:15:30.00Z"));
     166        data.waypoints.add(wp);
    150167        data.waypoints.add(new WayPoint(new LatLon(42.72659, -0.00749)));
    151168        GpxLayer layer = new GpxLayer(data, "GPX layer name");
     
    233250    void testWriteGpxAndMarkerJoz() throws IOException {
    234251        GpxLayer gpx = createGpxLayer();
    235         byte[] bytes = testWrite(Arrays.asList(gpx, createMarkerLayer(gpx)), true);
     252        Map<String, byte[]> bytes = testWrite(Arrays.asList(gpx, createMarkerLayer(gpx)), true);
     253
    236254        Path path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/gpx_markers.jos");
    237255        String expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
    238         String actual = new String(bytes, StandardCharsets.UTF_8).replace("\r", "");
     256        String actual = new String(bytes.get("session.jos"), StandardCharsets.UTF_8).replace("\r", "");
     257        assertEquals(expected, actual);
     258
     259        path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/data_export.gpx");
     260        expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
     261        actual = new String(bytes.get("layers/01/data.gpx"), StandardCharsets.UTF_8).replace("\r", "");
     262        assertEquals(expected, actual);
     263
     264        path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/markers.gpx");
     265        expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
     266        actual = new String(bytes.get("layers/02/data.gpx"), StandardCharsets.UTF_8).replace("\r", "");
    239267        assertEquals(expected, actual);
    240268    }
Note: See TracChangeset for help on using the changeset viewer.