forked from upstream-mirrors/OpenTracks
59a05262a1
ImportAllTracks is essentially just a modification of ExportAllTracks that uses the existing GpxImporter to import all GPX files found in /sdcard/MyTracks/gpx. So that the import functionality can always be accessed, the MyTracks Activity's MenuManager is altered so that the Tracks button shows regardless of whether there are any tracks in the database (ImportAllTracks is launched by a button in the lower right of the MyTracksList activity). A Toast message shows if no GPX files are found; this serves as a hint to users on where to put GPX files for import so that this addition should be discoverable and useable without documentation. Im
71 lines
2.6 KiB
Java
71 lines
2.6 KiB
Java
// Copyright 2010 Google Inc. All Rights Reserved.
|
|
package com.google.android.apps.mytracks.io;
|
|
|
|
import com.google.android.apps.mytracks.content.Waypoint;
|
|
|
|
import android.location.Location;
|
|
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Tests for the GPX track exporter.
|
|
*
|
|
* @author Rodrigo Damazio
|
|
*/
|
|
public class GpxTrackWriterTest extends TrackFormatWriterTest {
|
|
|
|
public void testXmlOutput() throws Exception {
|
|
TrackFormatWriter writer = new GpxTrackWriter();
|
|
String result = writeTrack(writer);
|
|
Document doc = parseXmlDocument(result);
|
|
|
|
Element gpxTag = getChildElement(doc, "gpx");
|
|
Element trackTag = getChildElement(gpxTag, "trk");
|
|
assertEquals(TRACK_NAME, getChildTextValue(trackTag, "name"));
|
|
assertEquals(TRACK_DESCRIPTION, getChildTextValue(trackTag, "desc"));
|
|
assertEquals(Long.toString(TRACK_ID),
|
|
getChildTextValue(trackTag, "number"));
|
|
List<Element> segmentTags = getChildElements(trackTag, "trkseg", 2);
|
|
List<Element> segPointTags = getChildElements(segmentTags.get(0), "trkpt", 2);
|
|
assertTagMatchesLocation(segPointTags.get(0),
|
|
"0", "0", "1970-01-01T02:46:40Z", "0");
|
|
assertTagMatchesLocation(segPointTags.get(1),
|
|
"1", "-1", "1970-01-01T02:46:41Z", "5000000");
|
|
|
|
segPointTags = getChildElements(segmentTags.get(1), "trkpt", 2);
|
|
assertTagMatchesLocation(segPointTags.get(0),
|
|
"2", "-2", "1970-01-01T02:46:42Z", "10000000");
|
|
assertTagMatchesLocation(segPointTags.get(1),
|
|
"3", "-3", "1970-01-01T02:46:43Z", "15000000");
|
|
|
|
List<Element> waypointTags = getChildElements(gpxTag, "wpt", 2);
|
|
Element wptTag = waypointTags.get(0);
|
|
assertEquals(WAYPOINT1_NAME, getChildTextValue(wptTag, "name"));
|
|
assertEquals(WAYPOINT1_DESCRIPTION, getChildTextValue(wptTag, "desc"));
|
|
assertTagMatchesLocation(wptTag,
|
|
"1", "-1", "1970-01-01T02:46:41Z", "5000000");
|
|
|
|
wptTag = waypointTags.get(1);
|
|
assertEquals(WAYPOINT2_NAME, getChildTextValue(wptTag, "name"));
|
|
assertEquals(WAYPOINT2_DESCRIPTION, getChildTextValue(wptTag, "desc"));
|
|
assertTagMatchesLocation(wptTag,
|
|
"2", "-2", "1970-01-01T02:46:42Z", "10000000");
|
|
}
|
|
|
|
/**
|
|
* Asserts that the given tag describes the location given by the
|
|
* Strings lat, lon, time, and ele.
|
|
*/
|
|
private void assertTagMatchesLocation(Element tag, String lat,
|
|
String lon, String time, String ele) {
|
|
assertEquals(lat, tag.getAttribute("lat"));
|
|
assertEquals(lon, tag.getAttribute("lon"));
|
|
assertEquals(time, getChildTextValue(tag, "time"));
|
|
assertEquals(ele, getChildTextValue(tag, "ele"));
|
|
}
|
|
}
|