Changeset 14067 in josm for trunk/test


Ignore:
Timestamp:
2018-07-30T21:57:20+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16496 - fix invalid parsing of NMEA time (decimal-fraction of seconds)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/io/nmea/NmeaReaderTest.java

    r14010 r14067  
    66import static org.junit.Assert.assertTrue;
    77
     8import java.io.ByteArrayInputStream;
    89import java.io.FileInputStream;
    910import java.io.IOException;
     11import java.nio.charset.StandardCharsets;
    1012import java.text.SimpleDateFormat;
    1113import java.util.ArrayList;
     14import java.util.Date;
    1215import java.util.List;
    1316import java.util.TimeZone;
    1417
     18import org.junit.Before;
    1519import org.junit.Rule;
    1620import org.junit.Test;
     
    4044    public JOSMTestRules test = new JOSMTestRules();
    4145
     46    private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
     47
     48    /**
     49     * Forces the timezone.
     50     */
     51    @Before
     52    public void setUp() {
     53        iso8601.setTimeZone(TimeZone.getTimeZone("UTC"));
     54    }
     55
    4256    /**
    4357     * Tests reading a nmea file.
     
    5872        assertEquals(wayPoints.get(0).getTime(), DateUtils.fromString(wayPoints.get(0).get(GpxConstants.PT_TIME).toString()));
    5973
    60         final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
    61         assertEquals("2016-01-25T06:05:09.200+01", iso8601.format(wayPoints.get(0).getTime()));
    62         assertEquals("2016-01-25T06:05:09.400+01", iso8601.format(wayPoints.get(1).getTime()));
    63         assertEquals("2016-01-25T06:05:09.600+01", iso8601.format(wayPoints.get(2).getTime()));
     74        assertEquals("2016-01-25T05:05:09.200Z", iso8601.format(wayPoints.get(0).getTime()));
     75        assertEquals("2016-01-25T05:05:09.400Z", iso8601.format(wayPoints.get(1).getTime()));
     76        assertEquals("2016-01-25T05:05:09.600Z", iso8601.format(wayPoints.get(2).getTime()));
    6477
    6578        assertEquals(new LatLon(46.98807, -1.400525), wayPoints.get(0).getCoor());
     
    146159        compareWithReference(14924, "input", 0);
    147160    }
     161
     162    private static Date readDate(String nmeaLine) throws IOException, SAXException {
     163        NmeaReader in = new NmeaReader(new ByteArrayInputStream(nmeaLine.getBytes(StandardCharsets.UTF_8)));
     164        in.parse(true);
     165        return in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints().iterator().next().getTime();
     166    }
     167
     168    /**
     169     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/16496">Bug #16496</a>.
     170     * @throws Exception if an error occurs
     171     */
     172    @Test
     173    public void testTicket16496() throws Exception {
     174        assertEquals("2018-05-30T16:28:59.400Z", iso8601.format(readDate("$GNRMC,162859.400,A,4543.03388,N,00058.19870,W,45.252,209.07,300518,,,D,V*13")));
     175        assertEquals("2018-05-30T16:28:59.400Z", iso8601.format(readDate("$GNRMC,162859.40,A,4543.03388,N,00058.19870,W,45.252,209.07,300518,,,D,V*23")));
     176        assertEquals("2018-05-30T16:28:59.400Z", iso8601.format(readDate("$GNRMC,162859.4,A,4543.03388,N,00058.19870,W,45.252,209.07,300518,,,D,V*13")));
     177    }
    148178}
Note: See TracChangeset for help on using the changeset viewer.