mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-12 02:45:49 +01:00
Add GPX Import test
This commit is contained in:
parent
95c35deb90
commit
a382032021
@ -0,0 +1,33 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.test;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GpxParser;
|
||||
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class GPXParserTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void shouldReadGPXCorrectly() throws IOException {
|
||||
try (final InputStream inputStream = getClass().getResourceAsStream("/gpx-exporter-test-SampleTrack.gpx")) {
|
||||
GpxParser gpxParser = new GpxParser(inputStream);
|
||||
List<GPSCoordinate> trackPoints = gpxParser.getPoints();
|
||||
Assert.assertEquals(trackPoints.size(), 14);
|
||||
DecimalFormat df = new DecimalFormat("###.##");
|
||||
for (GPSCoordinate tp : trackPoints) {
|
||||
Assert.assertEquals(df.format(tp.getLongitude()), "44.15");
|
||||
Assert.assertEquals(df.format(tp.getLatitude()), "-68.2");
|
||||
Assert.assertThat(df.format(tp.getAltitude()), anyOf(is("40"), is("46")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
70
app/src/test/resources/gpx-exporter-test-SampleTrack.gpx
Normal file
70
app/src/test/resources/gpx-exporter-test-SampleTrack.gpx
Normal file
@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="Gadgetbridge Test" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
|
||||
<metadata>
|
||||
<name>Test Track</name>
|
||||
<author>
|
||||
<name>Test User</name>
|
||||
</author>
|
||||
<time>2020-10-25T14:44:45+01:00</time>
|
||||
</metadata>
|
||||
<trk>
|
||||
<trkseg>
|
||||
<trkpt lon="-68.200293" lat="44.152462">
|
||||
<ele>40.000000</ele>
|
||||
<time>2019-01-01T00:00:00Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200270" lat="44.152460">
|
||||
<ele>40.000000</ele>
|
||||
<time>2019-01-01T00:00:01Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200260" lat="44.152462">
|
||||
<ele>40.000000</ele>
|
||||
<time>2019-01-01T00:00:02Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200242" lat="44.152493">
|
||||
<ele>40.000000</ele>
|
||||
<time>2019-01-01T00:00:03Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200237" lat="44.152528">
|
||||
<ele>40.000000</ele>
|
||||
<time>2019-01-01T00:00:04Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200232" lat="44.152567">
|
||||
<ele>40.000000</ele>
|
||||
<time>2019-01-01T00:00:05Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200248" lat="44.152612">
|
||||
<ele>40.000000</ele>
|
||||
<time>2019-01-01T00:00:06Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200253" lat="44.152657">
|
||||
<ele>40.000000</ele>
|
||||
<time>2019-01-01T00:00:07Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200245" lat="44.152675">
|
||||
<ele>46.000000</ele>
|
||||
<time>2019-01-01T00:00:08Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200232" lat="44.152695">
|
||||
<ele>46.000000</ele>
|
||||
<time>2019-01-01T00:00:09Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200215" lat="44.152720">
|
||||
<ele>46.000000</ele>
|
||||
<time>2019-01-01T00:00:10Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200205" lat="44.152753">
|
||||
<ele>46.000000</ele>
|
||||
<time>2019-01-01T00:00:11Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200197" lat="44.152808">
|
||||
<ele>46.000000</ele>
|
||||
<time>2019-01-01T00:00:12Z</time>
|
||||
</trkpt>
|
||||
<trkpt lon="-68.200203" lat="44.152877">
|
||||
<ele>46.000000</ele>
|
||||
<time>2019-01-01T00:00:13Z</time>
|
||||
</trkpt>
|
||||
</trkseg>
|
||||
</trk>
|
||||
</gpx>
|
Loading…
Reference in New Issue
Block a user