source: josm/trunk/test/unit/org/openstreetmap/josm/io/GpxReaderTest.java@ 9749

Last change on this file since 9749 was 9384, checked in by simon04, 8 years ago

Add unit test for CorrelateGpxWithImages

File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.io.ByteArrayInputStream;
8import java.io.File;
9import java.io.FileInputStream;
10import java.io.IOException;
11import java.nio.charset.StandardCharsets;
12import java.util.List;
13
14import org.junit.Test;
15import org.openstreetmap.josm.data.coor.LatLon;
16import org.openstreetmap.josm.data.gpx.GpxData;
17import org.openstreetmap.josm.data.gpx.WayPoint;
18import org.xml.sax.SAXException;
19
20/**
21 * Tests the {@link GpxReader}.
22 */
23public class GpxReaderTest {
24
25 /**
26 * Parses a GPX file and returns the parsed data
27 * @param filename the GPX file to parse
28 * @return the parsed GPX data
29 * @throws IOException if an error occurs during reading.
30 * @throws SAXException if a SAX error occurs
31 */
32 public static GpxData parseGpxData(String filename) throws IOException, SAXException {
33 final GpxData result;
34 try (final FileInputStream in = new FileInputStream(new File(filename))) {
35 final GpxReader reader = new GpxReader(in);
36 assertTrue(reader.parse(false));
37 result = reader.getGpxData();
38 }
39 return result;
40 }
41
42 /**
43 * Tests the {@code munich.gpx} test file.
44 * @throws Exception if something goes wrong
45 */
46 @Test
47 public void testMunich() throws Exception {
48 final GpxData result = parseGpxData("data_nodist/munich.gpx");
49 assertEquals(2762, result.tracks.size());
50 assertEquals(0, result.routes.size());
51 assertEquals(903, result.waypoints.size());
52
53 final WayPoint tenthWayPoint = ((List<WayPoint>) result.waypoints).get(10);
54 assertEquals("128970", tenthWayPoint.get(GpxData.GPX_NAME));
55 assertEquals(new LatLon(48.183956146240234, 11.43463134765625), tenthWayPoint.getCoor());
56 }
57
58 /**
59 * Tests invalid data.
60 * @throws Exception always SAXException
61 */
62 @Test(expected = SAXException.class)
63 public void testException() throws Exception {
64 new GpxReader(new ByteArrayInputStream("--foo--bar--".getBytes(StandardCharsets.UTF_8))).parse(true);
65 }
66}
Note: See TracBrowser for help on using the repository browser.