forked from upstream-mirrors/OpenTracks
Rename TrackFormatWriter to TrackWriter
This commit is contained in:
@@ -48,7 +48,7 @@ import java.text.NumberFormat;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class CsvTrackWriter implements TrackFormatWriter {
|
public class CsvTrackWriter implements TrackWriter {
|
||||||
|
|
||||||
private static final NumberFormat SHORT_FORMAT = NumberFormat.getInstance();
|
private static final NumberFormat SHORT_FORMAT = NumberFormat.getInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import java.util.Locale;
|
|||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
*/
|
*/
|
||||||
public class GpxTrackWriter implements TrackFormatWriter {
|
public class GpxTrackWriter implements TrackWriter {
|
||||||
|
|
||||||
private static final NumberFormat ELEVATION_FORMAT = NumberFormat.getInstance(Locale.US);
|
private static final NumberFormat ELEVATION_FORMAT = NumberFormat.getInstance(Locale.US);
|
||||||
private static final NumberFormat COORDINATE_FORMAT = NumberFormat.getInstance(Locale.US);
|
private static final NumberFormat COORDINATE_FORMAT = NumberFormat.getInstance(Locale.US);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ import java.util.ArrayList;
|
|||||||
*
|
*
|
||||||
* @author Leif Hendrik Wilden
|
* @author Leif Hendrik Wilden
|
||||||
*/
|
*/
|
||||||
public class KmlTrackWriter implements TrackFormatWriter {
|
public class KmlTrackWriter implements TrackWriter {
|
||||||
|
|
||||||
private static final String WAYPOINT_STYLE = "waypoint";
|
private static final String WAYPOINT_STYLE = "waypoint";
|
||||||
private static final String STATISTICS_STYLE = "statistics";
|
private static final String STATISTICS_STYLE = "statistics";
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import java.util.Locale;
|
|||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
* @author Dominik Rttsches
|
* @author Dominik Rttsches
|
||||||
*/
|
*/
|
||||||
public class TcxTrackWriter implements TrackFormatWriter {
|
public class TcxTrackWriter implements TrackWriter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCX sport type. See the TCX spec.
|
* TCX sport type. See the TCX spec.
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class TrackExporter {
|
|||||||
|
|
||||||
private final MyTracksProviderUtils myTracksProviderUtils;
|
private final MyTracksProviderUtils myTracksProviderUtils;
|
||||||
private final Track[] tracks;
|
private final Track[] tracks;
|
||||||
private final TrackFormatWriter trackFormatWriter;
|
private final TrackWriter trackWriter;
|
||||||
private final OnWriteListener onWriteListener;
|
private final OnWriteListener onWriteListener;
|
||||||
|
|
||||||
private Thread writeThread;
|
private Thread writeThread;
|
||||||
@@ -76,15 +76,15 @@ public class TrackExporter {
|
|||||||
*/
|
*/
|
||||||
public TrackExporter(Context context, MyTracksProviderUtils myTracksProviderUtils, Track[] tracks,
|
public TrackExporter(Context context, MyTracksProviderUtils myTracksProviderUtils, Track[] tracks,
|
||||||
TrackFileFormat trackFileFormat, OnWriteListener onWriteListener) {
|
TrackFileFormat trackFileFormat, OnWriteListener onWriteListener) {
|
||||||
this(myTracksProviderUtils, tracks, trackFileFormat.newFormatWriter(context), onWriteListener);
|
this(myTracksProviderUtils, tracks, trackFileFormat.newTrackWriter(context), onWriteListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public TrackExporter(MyTracksProviderUtils myTracksProviderUtils, Track[] tracks,
|
public TrackExporter(MyTracksProviderUtils myTracksProviderUtils, Track[] tracks,
|
||||||
TrackFormatWriter trackFormatWriter, OnWriteListener onWriteListener) {
|
TrackWriter trackWriter, OnWriteListener onWriteListener) {
|
||||||
this.myTracksProviderUtils = myTracksProviderUtils;
|
this.myTracksProviderUtils = myTracksProviderUtils;
|
||||||
this.tracks = tracks;
|
this.tracks = tracks;
|
||||||
this.trackFormatWriter = trackFormatWriter;
|
this.trackWriter = trackWriter;
|
||||||
this.onWriteListener = onWriteListener;
|
this.onWriteListener = onWriteListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,16 +105,16 @@ public class TrackExporter {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
trackFormatWriter.prepare(outputStream);
|
trackWriter.prepare(outputStream);
|
||||||
trackFormatWriter.writeHeader(tracks[0]);
|
trackWriter.writeHeader(tracks[0]);
|
||||||
long startTime = tracks[0].getTripStatistics().getStartTime();
|
long startTime = tracks[0].getTripStatistics().getStartTime();
|
||||||
for (int i = 0; i < tracks.length; i++) {
|
for (int i = 0; i < tracks.length; i++) {
|
||||||
writeWaypoints(tracks[i]);
|
writeWaypoints(tracks[i]);
|
||||||
long offset = tracks[i].getTripStatistics().getStartTime() - startTime;
|
long offset = tracks[i].getTripStatistics().getStartTime() - startTime;
|
||||||
writeLocations(tracks[i], offset);
|
writeLocations(tracks[i], offset);
|
||||||
}
|
}
|
||||||
trackFormatWriter.writeFooter();
|
trackWriter.writeFooter();
|
||||||
trackFormatWriter.close();
|
trackWriter.close();
|
||||||
success = true;
|
success = true;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
success = false;
|
success = false;
|
||||||
@@ -169,11 +169,11 @@ public class TrackExporter {
|
|||||||
*/
|
*/
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
if (!hasWaypoints) {
|
if (!hasWaypoints) {
|
||||||
trackFormatWriter.writeBeginWaypoints();
|
trackWriter.writeBeginWaypoints();
|
||||||
hasWaypoints = true;
|
hasWaypoints = true;
|
||||||
}
|
}
|
||||||
Waypoint waypoint = myTracksProviderUtils.createWaypoint(cursor);
|
Waypoint waypoint = myTracksProviderUtils.createWaypoint(cursor);
|
||||||
trackFormatWriter.writeWaypoint(waypoint);
|
trackWriter.writeWaypoint(waypoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -182,7 +182,7 @@ public class TrackExporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasWaypoints) {
|
if (hasWaypoints) {
|
||||||
trackFormatWriter.writeEndWaypoints();
|
trackWriter.writeEndWaypoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,28 +211,28 @@ public class TrackExporter {
|
|||||||
boolean isSegmentValid = isLocationValid && isLastLocationValid;
|
boolean isSegmentValid = isLocationValid && isLastLocationValid;
|
||||||
if (!wroteTrack && isSegmentValid) {
|
if (!wroteTrack && isSegmentValid) {
|
||||||
// Found the first two consecutive locations that are valid
|
// Found the first two consecutive locations that are valid
|
||||||
trackFormatWriter.writeBeginTrack(track, locationFactory.lastLocation);
|
trackWriter.writeBeginTrack(track, locationFactory.lastLocation);
|
||||||
wroteTrack = true;
|
wroteTrack = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSegmentValid) {
|
if (isSegmentValid) {
|
||||||
if (!wroteSegment) {
|
if (!wroteSegment) {
|
||||||
// Start a segment
|
// Start a segment
|
||||||
trackFormatWriter.writeOpenSegment();
|
trackWriter.writeOpenSegment();
|
||||||
wroteSegment = true;
|
wroteSegment = true;
|
||||||
|
|
||||||
// Write the previous location, which we had previously skipped
|
// Write the previous location, which we had previously skipped
|
||||||
trackFormatWriter.writeLocation(locationFactory.lastLocation);
|
trackWriter.writeLocation(locationFactory.lastLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the current location
|
// Write the current location
|
||||||
trackFormatWriter.writeLocation(location);
|
trackWriter.writeLocation(location);
|
||||||
if (onWriteListener != null) {
|
if (onWriteListener != null) {
|
||||||
onWriteListener.onWrite(locationNumber, track.getNumberOfPoints());
|
onWriteListener.onWrite(locationNumber, track.getNumberOfPoints());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (wroteSegment) {
|
if (wroteSegment) {
|
||||||
trackFormatWriter.writeCloseSegment();
|
trackWriter.writeCloseSegment();
|
||||||
wroteSegment = false;
|
wroteSegment = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,17 +241,17 @@ public class TrackExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wroteSegment) {
|
if (wroteSegment) {
|
||||||
trackFormatWriter.writeCloseSegment();
|
trackWriter.writeCloseSegment();
|
||||||
wroteSegment = false;
|
wroteSegment = false;
|
||||||
}
|
}
|
||||||
if (wroteTrack) {
|
if (wroteTrack) {
|
||||||
Location lastValidTrackPoint = myTracksProviderUtils.getLastValidTrackPoint(track.getId());
|
Location lastValidTrackPoint = myTracksProviderUtils.getLastValidTrackPoint(track.getId());
|
||||||
setLocationTime(lastValidTrackPoint, offset);
|
setLocationTime(lastValidTrackPoint, offset);
|
||||||
trackFormatWriter.writeEndTrack(track, lastValidTrackPoint);
|
trackWriter.writeEndTrack(track, lastValidTrackPoint);
|
||||||
} else {
|
} else {
|
||||||
// Write an empty track
|
// Write an empty track
|
||||||
trackFormatWriter.writeBeginTrack(track, null);
|
trackWriter.writeBeginTrack(track, null);
|
||||||
trackFormatWriter.writeEndTrack(track, null);
|
trackWriter.writeEndTrack(track, null);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
iterator.close();
|
iterator.close();
|
||||||
|
|||||||
@@ -12,25 +12,25 @@ import java.util.Locale;
|
|||||||
public enum TrackFileFormat implements Parcelable {
|
public enum TrackFileFormat implements Parcelable {
|
||||||
KML {
|
KML {
|
||||||
@Override
|
@Override
|
||||||
TrackFormatWriter newFormatWriter(Context context) {
|
TrackWriter newTrackWriter(Context context) {
|
||||||
return new KmlTrackWriter(context);
|
return new KmlTrackWriter(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GPX {
|
GPX {
|
||||||
@Override
|
@Override
|
||||||
TrackFormatWriter newFormatWriter(Context context) {
|
TrackWriter newTrackWriter(Context context) {
|
||||||
return new GpxTrackWriter(context);
|
return new GpxTrackWriter(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
CSV {
|
CSV {
|
||||||
@Override
|
@Override
|
||||||
public TrackFormatWriter newFormatWriter(Context context) {
|
public TrackWriter newTrackWriter(Context context) {
|
||||||
return new CsvTrackWriter(context);
|
return new CsvTrackWriter(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TCX {
|
TCX {
|
||||||
@Override
|
@Override
|
||||||
public TrackFormatWriter newFormatWriter(Context context) {
|
public TrackWriter newTrackWriter(Context context) {
|
||||||
return new TcxTrackWriter(context);
|
return new TcxTrackWriter(context);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -58,9 +58,9 @@ public enum TrackFileFormat implements Parcelable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and returns a new format writer for each format.
|
* Creates a new track writer for the format.
|
||||||
*/
|
*/
|
||||||
abstract TrackFormatWriter newFormatWriter(Context context);
|
abstract TrackWriter newTrackWriter(Context context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the mime type for each format.
|
* Returns the mime type for each format.
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ import java.io.OutputStream;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public interface TrackFormatWriter {
|
public interface TrackWriter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the file extension (i.e. gpx, kml, ...)
|
* Gets the file extension (i.e. gpx, kml, ...)
|
||||||
@@ -21,7 +21,7 @@ package com.google.android.apps.mytracks.io.file;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class CsvTrackWriterTest extends TrackFormatWriterTest {
|
public class CsvTrackWriterTest extends TrackWriterTest {
|
||||||
|
|
||||||
private static final String BEGIN_TAG = "\"";
|
private static final String BEGIN_TAG = "\"";
|
||||||
private static final String END_TAG = "\"\n";
|
private static final String END_TAG = "\"\n";
|
||||||
@@ -62,8 +62,8 @@ public class CsvTrackWriterTest extends TrackFormatWriterTest {
|
|||||||
+ expectedMarkerHeader + expectedMarker1 + expectedMarker2 + "\n"
|
+ expectedMarkerHeader + expectedMarker1 + expectedMarker2 + "\n"
|
||||||
+ expectedPointHeader + expectedPoint1 + expectedPoint2 + expectedPoint3 + expectedPoint4;
|
+ expectedPointHeader + expectedPoint1 + expectedPoint2 + expectedPoint3 + expectedPoint4;
|
||||||
|
|
||||||
CsvTrackWriter writer = new CsvTrackWriter(getContext());
|
CsvTrackWriter csvTrackWriter = new CsvTrackWriter(getContext());
|
||||||
assertEquals(expected, writeTrack(writer));
|
assertEquals(expected, writeTrack(csvTrackWriter));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ import org.w3c.dom.Element;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class GpxTrackWriterTest extends TrackFormatWriterTest {
|
public class GpxTrackWriterTest extends TrackWriterTest {
|
||||||
|
|
||||||
public void testXmlOutput() throws Exception {
|
public void testXmlOutput() throws Exception {
|
||||||
TrackFormatWriter writer = new GpxTrackWriter(getContext());
|
GpxTrackWriter gpxTrackWriter = new GpxTrackWriter(getContext());
|
||||||
String result = writeTrack(writer);
|
String result = writeTrack(gpxTrackWriter);
|
||||||
Document doc = parseXmlDocument(result);
|
Document doc = parseXmlDocument(result);
|
||||||
|
|
||||||
Element gpxTag = getChildElement(doc, "gpx");
|
Element gpxTag = getChildElement(doc, "gpx");
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import org.w3c.dom.Element;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class KmlTrackWriterTest extends TrackFormatWriterTest {
|
public class KmlTrackWriterTest extends TrackWriterTest {
|
||||||
|
|
||||||
private static final String FULL_TRACK_DESCRIPTION = "full track description";
|
private static final String FULL_TRACK_DESCRIPTION = "full track description";
|
||||||
|
|
||||||
@@ -54,8 +54,8 @@ public class KmlTrackWriterTest extends TrackFormatWriterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testXmlOutput() throws Exception {
|
public void testXmlOutput() throws Exception {
|
||||||
KmlTrackWriter writer = new KmlTrackWriter(getContext(), new FakeDescriptionGenerator());
|
KmlTrackWriter kmlTrackWriter = new KmlTrackWriter(getContext(), new FakeDescriptionGenerator());
|
||||||
String result = writeTrack(writer);
|
String result = writeTrack(kmlTrackWriter);
|
||||||
Document doc = parseXmlDocument(result);
|
Document doc = parseXmlDocument(result);
|
||||||
|
|
||||||
Element kmlTag = getChildElement(doc, "kml");
|
Element kmlTag = getChildElement(doc, "kml");
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ import org.w3c.dom.Element;
|
|||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
*/
|
*/
|
||||||
public class TcxTrackWriterTest extends TrackFormatWriterTest {
|
public class TcxTrackWriterTest extends TrackWriterTest {
|
||||||
|
|
||||||
public void testXmlOutput() throws Exception {
|
public void testXmlOutput() throws Exception {
|
||||||
TrackFormatWriter writer = new TcxTrackWriter(getContext());
|
TcxTrackWriter tcxTrackWriter = new TcxTrackWriter(getContext());
|
||||||
String result = writeTrack(writer);
|
String result = writeTrack(tcxTrackWriter);
|
||||||
Document doc = parseXmlDocument(result);
|
Document doc = parseXmlDocument(result);
|
||||||
|
|
||||||
Element root = getChildElement(doc, "TrainingCenterDatabase");
|
Element root = getChildElement(doc, "TrainingCenterDatabase");
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class TrackExporterTest extends AndroidTestCase {
|
|||||||
|
|
||||||
private IMocksControl mocksControl;
|
private IMocksControl mocksControl;
|
||||||
|
|
||||||
private TrackFormatWriter trackFormatWriter;
|
private TrackWriter trackWriter;
|
||||||
private Track track;
|
private Track track;
|
||||||
private OutputStream outputStream;
|
private OutputStream outputStream;
|
||||||
private TrackExporter trackExporter;
|
private TrackExporter trackExporter;
|
||||||
@@ -61,7 +61,7 @@ public class TrackExporterTest extends AndroidTestCase {
|
|||||||
myTracksProviderUtils);
|
myTracksProviderUtils);
|
||||||
|
|
||||||
mocksControl = EasyMock.createStrictControl();
|
mocksControl = EasyMock.createStrictControl();
|
||||||
trackFormatWriter = mocksControl.createMock(TrackFormatWriter.class);
|
trackWriter = mocksControl.createMock(TrackWriter.class);
|
||||||
|
|
||||||
track = new Track();
|
track = new Track();
|
||||||
track.setName(TRACK_NAME);
|
track.setName(TRACK_NAME);
|
||||||
@@ -76,7 +76,7 @@ public class TrackExporterTest extends AndroidTestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
trackExporter = new TrackExporter(myTracksProviderUtils, new Track[] {track}, trackFormatWriter, onWriteListener);
|
trackExporter = new TrackExporter(myTracksProviderUtils, new Track[] {track}, trackWriter, onWriteListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -91,12 +91,12 @@ public class TrackExporterTest extends AndroidTestCase {
|
|||||||
public void testWriteTrack_emptyTrack() throws Exception {
|
public void testWriteTrack_emptyTrack() throws Exception {
|
||||||
|
|
||||||
// Set expected mock behavior
|
// Set expected mock behavior
|
||||||
trackFormatWriter.prepare(outputStream);
|
trackWriter.prepare(outputStream);
|
||||||
trackFormatWriter.writeHeader(track);
|
trackWriter.writeHeader(track);
|
||||||
trackFormatWriter.writeBeginTrack(track, null);
|
trackWriter.writeBeginTrack(track, null);
|
||||||
trackFormatWriter.writeEndTrack(track, null);
|
trackWriter.writeEndTrack(track, null);
|
||||||
trackFormatWriter.writeFooter();
|
trackWriter.writeFooter();
|
||||||
trackFormatWriter.close();
|
trackWriter.close();
|
||||||
|
|
||||||
mocksControl.replay();
|
mocksControl.replay();
|
||||||
trackExporter.writeTrack(outputStream);
|
trackExporter.writeTrack(outputStream);
|
||||||
@@ -123,12 +123,12 @@ public class TrackExporterTest extends AndroidTestCase {
|
|||||||
myTracksProviderUtils.bulkInsertTrackPoint(locations, locations.length, TRACK_ID));
|
myTracksProviderUtils.bulkInsertTrackPoint(locations, locations.length, TRACK_ID));
|
||||||
|
|
||||||
// Set expected mock behavior
|
// Set expected mock behavior
|
||||||
trackFormatWriter.prepare(outputStream);
|
trackWriter.prepare(outputStream);
|
||||||
trackFormatWriter.writeHeader(track);
|
trackWriter.writeHeader(track);
|
||||||
trackFormatWriter.writeBeginTrack(track, null);
|
trackWriter.writeBeginTrack(track, null);
|
||||||
trackFormatWriter.writeEndTrack(track, null);
|
trackWriter.writeEndTrack(track, null);
|
||||||
trackFormatWriter.writeFooter();
|
trackWriter.writeFooter();
|
||||||
trackFormatWriter.close();
|
trackWriter.close();
|
||||||
|
|
||||||
mocksControl.replay();
|
mocksControl.replay();
|
||||||
trackExporter.writeTrack(outputStream);
|
trackExporter.writeTrack(outputStream);
|
||||||
@@ -162,38 +162,38 @@ public class TrackExporterTest extends AndroidTestCase {
|
|||||||
waypoint.setId(i + 1);
|
waypoint.setId(i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
trackFormatWriter.prepare(outputStream);
|
trackWriter.prepare(outputStream);
|
||||||
trackFormatWriter.writeHeader(track);
|
trackWriter.writeHeader(track);
|
||||||
|
|
||||||
// Expect reading/writing of the waypoints (except the first)
|
// Expect reading/writing of the waypoints (except the first)
|
||||||
trackFormatWriter.writeBeginWaypoints();
|
trackWriter.writeBeginWaypoints();
|
||||||
trackFormatWriter.writeWaypoint(waypointEq(waypoints[1]));
|
trackWriter.writeWaypoint(waypointEq(waypoints[1]));
|
||||||
trackFormatWriter.writeWaypoint(waypointEq(waypoints[2]));
|
trackWriter.writeWaypoint(waypointEq(waypoints[2]));
|
||||||
trackFormatWriter.writeEndWaypoints();
|
trackWriter.writeEndWaypoints();
|
||||||
|
|
||||||
// Begin the track
|
// Begin the track
|
||||||
trackFormatWriter.writeBeginTrack(trackEq(track), locationEq(locations[0]));
|
trackWriter.writeBeginTrack(trackEq(track), locationEq(locations[0]));
|
||||||
|
|
||||||
// Write locations 1-2
|
// Write locations 1-2
|
||||||
trackFormatWriter.writeOpenSegment();
|
trackWriter.writeOpenSegment();
|
||||||
trackFormatWriter.writeLocation(locationEq(locations[0]));
|
trackWriter.writeLocation(locationEq(locations[0]));
|
||||||
trackFormatWriter.writeLocation(locationEq(locations[1]));
|
trackWriter.writeLocation(locationEq(locations[1]));
|
||||||
trackFormatWriter.writeCloseSegment();
|
trackWriter.writeCloseSegment();
|
||||||
|
|
||||||
// Location 3 is not written - it's invalid
|
// Location 3 is not written - it's invalid
|
||||||
|
|
||||||
// Write locations 4-6
|
// Write locations 4-6
|
||||||
trackFormatWriter.writeOpenSegment();
|
trackWriter.writeOpenSegment();
|
||||||
trackFormatWriter.writeLocation(locationEq(locations[3]));
|
trackWriter.writeLocation(locationEq(locations[3]));
|
||||||
trackFormatWriter.writeLocation(locationEq(locations[4]));
|
trackWriter.writeLocation(locationEq(locations[4]));
|
||||||
trackFormatWriter.writeLocation(locationEq(locations[5]));
|
trackWriter.writeLocation(locationEq(locations[5]));
|
||||||
trackFormatWriter.writeCloseSegment();
|
trackWriter.writeCloseSegment();
|
||||||
|
|
||||||
// End the track
|
// End the track
|
||||||
trackFormatWriter.writeEndTrack(trackEq(track), locationEq(locations[5]));
|
trackWriter.writeEndTrack(trackEq(track), locationEq(locations[5]));
|
||||||
|
|
||||||
trackFormatWriter.writeFooter();
|
trackWriter.writeFooter();
|
||||||
trackFormatWriter.close();
|
trackWriter.close();
|
||||||
|
|
||||||
mocksControl.replay();
|
mocksControl.replay();
|
||||||
trackExporter.writeTrack(outputStream);
|
trackExporter.writeTrack(outputStream);
|
||||||
|
|||||||
+21
-21
@@ -34,7 +34,7 @@ import org.xml.sax.SAXException;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public abstract class TrackFormatWriterTest extends AndroidTestCase {
|
public abstract class TrackWriterTest extends AndroidTestCase {
|
||||||
|
|
||||||
// All the user-provided strings have "]]>" to ensure that proper escaping is
|
// All the user-provided strings have "]]>" to ensure that proper escaping is
|
||||||
// being done.
|
// being done.
|
||||||
@@ -110,29 +110,29 @@ public abstract class TrackFormatWriterTest extends AndroidTestCase {
|
|||||||
* Makes the right sequence of calls to the writer in order to write the fake
|
* Makes the right sequence of calls to the writer in order to write the fake
|
||||||
* track in {@link #track}.
|
* track in {@link #track}.
|
||||||
*
|
*
|
||||||
* @param writer the writer to write to
|
* @param trackWriter the track writer
|
||||||
* @return the written contents
|
* @return the written contents
|
||||||
*/
|
*/
|
||||||
protected String writeTrack(TrackFormatWriter writer) throws Exception {
|
protected String writeTrack(TrackWriter trackWriter) throws Exception {
|
||||||
OutputStream output = new ByteArrayOutputStream(BUFFER_SIZE);
|
OutputStream output = new ByteArrayOutputStream(BUFFER_SIZE);
|
||||||
writer.prepare(output);
|
trackWriter.prepare(output);
|
||||||
writer.writeHeader(track);
|
trackWriter.writeHeader(track);
|
||||||
writer.writeBeginWaypoints();
|
trackWriter.writeBeginWaypoints();
|
||||||
writer.writeWaypoint(wp1);
|
trackWriter.writeWaypoint(wp1);
|
||||||
writer.writeWaypoint(wp2);
|
trackWriter.writeWaypoint(wp2);
|
||||||
writer.writeEndWaypoints();
|
trackWriter.writeEndWaypoints();
|
||||||
writer.writeBeginTrack(track, location1);
|
trackWriter.writeBeginTrack(track, location1);
|
||||||
writer.writeOpenSegment();
|
trackWriter.writeOpenSegment();
|
||||||
writer.writeLocation(location1);
|
trackWriter.writeLocation(location1);
|
||||||
writer.writeLocation(location2);
|
trackWriter.writeLocation(location2);
|
||||||
writer.writeCloseSegment();
|
trackWriter.writeCloseSegment();
|
||||||
writer.writeOpenSegment();
|
trackWriter.writeOpenSegment();
|
||||||
writer.writeLocation(location3);
|
trackWriter.writeLocation(location3);
|
||||||
writer.writeLocation(location4);
|
trackWriter.writeLocation(location4);
|
||||||
writer.writeCloseSegment();
|
trackWriter.writeCloseSegment();
|
||||||
writer.writeEndTrack(track, location4);
|
trackWriter.writeEndTrack(track, location4);
|
||||||
writer.writeFooter();
|
trackWriter.writeFooter();
|
||||||
writer.close();
|
trackWriter.close();
|
||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user