![JAR search and dependency download from the Maven repository](/logo.png)
test.java.de.k3b.geo.io.gpx.GpxReaderTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of k3b-geoHelper Show documentation
Show all versions of k3b-geoHelper Show documentation
A j2se geo support library that is compatible with Android.
/*
* Copyright (c) 2015-2016 by k3b.
*
* This file is part of k3b-geoHelper library.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.k3b.geo.io.gpx;
import org.junit.Assert;
import org.junit.Test;
import org.xml.sax.InputSource;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.List;
import de.k3b.geo.api.GeoPointDto;
import de.k3b.geo.api.IGeoPointInfo;
/**
* Created by k3b on 14.06.2014.
*/
public class GpxReaderTest {
/** format for gpx v1.0 */
String xmlMinimal_gpx_v10 = "262:3:562:54989 type: cell, accuracy: 1640, confidence: 75 geo:0,0?q=12.34,56.78(name) \n";
/** format for gpx v1.1 */
String xmlMinimal_gpx_v11 = "262:3:562:54989 type: cell, accuracy: 1640, confidence: 75 \n";
String xmlFull_gpx_v11 = ""+
"" + xmlMinimal_gpx_v11 + " ";
/** format for gpx v1.1 using xml namespace g: */
String xmlMinimal_gpx_v11_withNS = "2014-12-19T21:13:21Z 262:3:562:54989 type: cell, accuracy: 1640, confidence: 75 geo:0,0?q=12.34,56.78(name) \n";
String xmlFull_gpx_v11withNS = ""+
"" + xmlMinimal_gpx_v11_withNS + " ";
/** illegal kml format but containing the essential fields understood by the parser */
String xmlMinimal_kml = "262:3:562:54989 type: cell, accuracy: 1640, confidence: 75 8.7178206,53.1099972,0 2014-12-19T21:13:21Z \n";
@Test
public void parseFormatGpx11ShortTest() throws IOException {
GpxReader reader = new GpxReader(null);
IGeoPointInfo location = reader.getTracks(new InputSource(new StringReader(xmlMinimal_gpx_v11))).get(0);
String formatted = GpxFormatter.toGpx(new StringBuffer(), location, location.getDescription(), location.getLink()).toString();
Assert.assertEquals(xmlMinimal_gpx_v11, formatted);
}
@Test
public void parseFormatGpx11FullTest() throws IOException {
GpxReader reader = new GpxReader(null);
IGeoPointInfo location = reader.getTracks(new InputSource(new StringReader(xmlFull_gpx_v11))).get(0);
String formatted = GpxFormatter.toGpx(new StringBuffer(), location, location.getDescription(), location.getLink()).toString();
Assert.assertEquals(xmlMinimal_gpx_v11, formatted);
}
@Test
public void parseFormatGpx11WithNamespaceTest() throws IOException {
GpxReader reader = new GpxReader(null);
IGeoPointInfo location = reader.getTracks(new InputSource(new StringReader(xmlFull_gpx_v11withNS))).get(0);
String formatted = GpxFormatter.toGpx(new StringBuffer(), location, location.getDescription(), location.getLink()).toString();
Assert.assertEquals(xmlMinimal_gpx_v11, formatted);
}
@Test
public void parseFormatGpx10ShortTest() throws IOException {
GpxReader reader = new GpxReader(null);
IGeoPointInfo location = reader.getTracks(new InputSource(new StringReader(xmlMinimal_gpx_v10))).get(0);
String formatted = GpxFormatter.toGpx(new StringBuffer(), location, location.getDescription(), location.getLink()).toString();
Assert.assertEquals(xmlMinimal_gpx_v11, formatted);
}
@Test
public void parseFormatKmlShortTest() throws IOException {
GpxReader reader = new GpxReader(new GeoPointDto());
GeoPointDto location = (GeoPointDto) reader.getTracks(new InputSource(new StringReader(xmlMinimal_kml))).get(0);
// uri not supported by kml
location.setLink("geo:0,0?q=12.34,56.78(name)");
String formatted = GpxFormatter.toGpx(new StringBuffer(), location, location.getDescription(), location.getLink()).toString();
Assert.assertEquals(xmlMinimal_gpx_v11, formatted);
}
// used to test files that do not work
// @Test
public void parseFormatFileTest() throws IOException {
// from android-s MyTracks
final String fullPathToParserInputFile = "D:\\prj\\eve\\android\\prj\\LocationMapViewer.wrk\\download\\Hotel-Conrad-10_02_2015 09_01.kml";
if (fullPathToParserInputFile != null) {
GpxReader reader = new GpxReader(null);
List locations = reader.getTracks(new InputSource(new FileReader(fullPathToParserInputFile)));
final StringBuffer result = new StringBuffer();
for (IGeoPointInfo location : locations) {
GpxFormatter.toGpx(result, location, location.getDescription(), location.getLink());
}
System.out.print(result.toString());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy