Merge heads

This commit is contained in:
youtaol
2013-09-04 10:11:32 +08:00
39 changed files with 888 additions and 457 deletions
@@ -42,11 +42,11 @@ import java.util.SimpleTimeZone;
import org.easymock.Capture;
/**
* Abstract class for testing importer.
* Abstract class for testing file track importers.
*
* @author Jimmy Shih.
*/
public class AbstractTestImporter extends AndroidTestCase {
public class AbstractTestFileTrackImporter extends AndroidTestCase {
protected static final String TRACK_NAME_0 = "blablub";
protected static final String TRACK_DESCRIPTION_0 = "s'Laebe isch koi Schlotzer";
@@ -31,11 +31,11 @@ import org.easymock.Capture;
import org.xml.sax.SAXException;
/**
* Tests for {@link GpxImporter}.
* Tests for {@link GpxFileTrackImporter}.
*
* @author Steffen Horlacher
*/
public class GpxImporterTest extends AbstractTestImporter {
public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
private static String getNameAndDescription(String name, String description) {
return "<name><![CDATA[" + name + "]]></name>" + "<desc><![CDATA[" + description + "]]></desc>";
@@ -107,8 +107,9 @@ public class GpxImporterTest extends AbstractTestImporter {
AndroidMock.replay(myTracksProviderUtils);
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils);
long[] trackIds = gpxImporter.importFile(inputStream);
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
getContext(), myTracksProviderUtils);
long[] trackIds = gpxFileTrackImporter.importFile(inputStream);
assertEquals(1, trackIds.length);
assertEquals(TRACK_ID_0, trackIds[0]);
@@ -140,8 +141,9 @@ public class GpxImporterTest extends AbstractTestImporter {
AndroidMock.replay(myTracksProviderUtils);
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils);
long[] trackIds = gpxImporter.importFile(inputStream);
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
getContext(), myTracksProviderUtils);
long[] trackIds = gpxFileTrackImporter.importFile(inputStream);
assertEquals(1, trackIds.length);
assertEquals(TRACK_ID_0, trackIds[0]);
@@ -177,8 +179,9 @@ public class GpxImporterTest extends AbstractTestImporter {
InputStream inputStream = new ByteArrayInputStream(
VALID_ONE_TRACK_TWO_SEGMENTS_NO_TIME_GPX.getBytes());
GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils);
long[] trackIds = gpxImporter.importFile(inputStream);
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
getContext(), myTracksProviderUtils);
long[] trackIds = gpxFileTrackImporter.importFile(inputStream);
assertEquals(1, trackIds.length);
assertEquals(TRACK_ID_0, trackIds[0]);
@@ -212,8 +215,9 @@ public class GpxImporterTest extends AbstractTestImporter {
AndroidMock.replay(myTracksProviderUtils);
InputStream inputStream = new ByteArrayInputStream(VALID_TWO_TRACKS_GPX.getBytes());
GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils);
long[] trackIds = gpxImporter.importFile(inputStream);
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
getContext(), myTracksProviderUtils);
long[] trackIds = gpxFileTrackImporter.importFile(inputStream);
assertEquals(2, trackIds.length);
assertEquals(TRACK_ID_0, trackIds[0]);
assertEquals(TRACK_ID_1, trackIds[1]);
@@ -279,8 +283,9 @@ public class GpxImporterTest extends AbstractTestImporter {
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
try {
GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils);
gpxImporter.importFile(inputStream);
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
getContext(), myTracksProviderUtils);
gpxFileTrackImporter.importFile(inputStream);
} catch (SAXException e) {
// expected
}
@@ -30,11 +30,11 @@ import java.io.InputStream;
import org.easymock.Capture;
/**
* Tests for {@link KmlImporter}.
* Tests for {@link KmlFileTrackImporter}.
*
* @author Jimmy Shih
*/
public class KmlImporterTest extends AbstractTestImporter {
public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
private static String getNameAndDescription(String name, String description) {
return "<name><![CDATA[" + name + "]]></name><description><![CDATA[" + description
@@ -85,8 +85,9 @@ public class KmlImporterTest extends AbstractTestImporter {
AndroidMock.replay(myTracksProviderUtils);
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
KmlImporter kmlImporter = new KmlImporter(getContext(), myTracksProviderUtils);
long[] trackIds = kmlImporter.importFile(inputStream);
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(
getContext(), myTracksProviderUtils);
long[] trackIds = kmlFileTrackImporter.importFile(inputStream);
assertEquals(1, trackIds.length);
assertEquals(TRACK_ID_0, trackIds[0]);
@@ -118,8 +119,9 @@ public class KmlImporterTest extends AbstractTestImporter {
AndroidMock.replay(myTracksProviderUtils);
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
KmlImporter kmlImporter = new KmlImporter(getContext(), myTracksProviderUtils);
long[] trackIds = kmlImporter.importFile(inputStream);
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(
getContext(), myTracksProviderUtils);
long[] trackIds = kmlFileTrackImporter.importFile(inputStream);
assertEquals(1, trackIds.length);
assertEquals(TRACK_ID_0, trackIds[0]);
@@ -13,7 +13,9 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.io.file;
package com.google.android.apps.mytracks.io.file.export;
import com.google.android.apps.mytracks.io.file.export.CsvTrackWriter;
/**
@@ -21,7 +23,7 @@ package com.google.android.apps.mytracks.io.file;
*
* @author Rodrigo Damazio
*/
public class CsvTrackWriterTest extends TrackFormatWriterTest {
public class CsvTrackWriterTest extends TrackWriterTest {
private static final String BEGIN_TAG = "\"";
private static final String END_TAG = "\"\n";
@@ -62,8 +64,8 @@ public class CsvTrackWriterTest extends TrackFormatWriterTest {
+ expectedMarkerHeader + expectedMarker1 + expectedMarker2 + "\n"
+ expectedPointHeader + expectedPoint1 + expectedPoint2 + expectedPoint3 + expectedPoint4;
CsvTrackWriter writer = new CsvTrackWriter(getContext());
assertEquals(expected, writeTrack(writer));
CsvTrackWriter csvTrackWriter = new CsvTrackWriter(getContext());
assertEquals(expected, writeTrack(csvTrackWriter));
}
/**
@@ -1,13 +1,15 @@
// Copyright 2010 Google Inc. All Rights Reserved.
package com.google.android.apps.mytracks.io.file;
package com.google.android.apps.mytracks.io.file.export;
import com.google.android.apps.mytracks.content.MyTracksProvider;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.Factory;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.io.file.TrackWriter.OnWriteListener;
import com.google.android.apps.mytracks.io.file.export.FileTrackExporter;
import com.google.android.apps.mytracks.io.file.export.TrackExporterListener;
import com.google.android.apps.mytracks.io.file.export.TrackWriter;
import com.google.android.apps.mytracks.services.TrackRecordingServiceTest.MockContext;
import com.google.android.apps.mytracks.testing.TestingProviderUtilsFactory;
@@ -25,11 +27,11 @@ import org.easymock.IArgumentMatcher;
import org.easymock.IMocksControl;
/**
* Tests for {@link TrackWriter}.
* Tests for {@link FileTrackExporter}.
*
* @author Rodrigo Damazio
*/
public class TrackWriterTest extends AndroidTestCase {
public class FileTrackExporterTest extends AndroidTestCase {
private static final long TRACK_ID = 1234567L;
private static final String TRACK_NAME = "Swimming across the pacific";
@@ -39,10 +41,10 @@ public class TrackWriterTest extends AndroidTestCase {
private IMocksControl mocksControl;
private TrackFormatWriter trackFormatWriter;
private TrackWriter trackWriter;
private Track track;
private OutputStream outputStream;
private TrackWriter trackWriter;
private FileTrackExporter fileTrackExporter;
@Override
protected void setUp() throws Exception {
@@ -61,22 +63,23 @@ public class TrackWriterTest extends AndroidTestCase {
myTracksProviderUtils);
mocksControl = EasyMock.createStrictControl();
trackFormatWriter = mocksControl.createMock(TrackFormatWriter.class);
trackWriter = mocksControl.createMock(TrackWriter.class);
track = new Track();
track.setName(TRACK_NAME);
track.setId(TRACK_ID);
outputStream = new ByteArrayOutputStream();
OnWriteListener onWriteListener = new OnWriteListener() {
TrackExporterListener trackExporterListener = new TrackExporterListener() {
@Override
public void onWrite(int number, int max) {
public void onProgressUpdate(int number, int max) {
// Safe to ignore
}
};
trackWriter = new TrackWriter(myTracksProviderUtils, new Track[] {track}, trackFormatWriter, onWriteListener);
fileTrackExporter = new FileTrackExporter(
myTracksProviderUtils, new Track[] { track }, trackWriter, trackExporterListener);
}
@Override
@@ -91,17 +94,16 @@ public class TrackWriterTest extends AndroidTestCase {
public void testWriteTrack_emptyTrack() throws Exception {
// Set expected mock behavior
trackFormatWriter.prepare(outputStream);
trackFormatWriter.writeHeader(track);
trackFormatWriter.writeBeginTrack(track, null);
trackFormatWriter.writeEndTrack(track, null);
trackFormatWriter.writeFooter();
trackFormatWriter.close();
trackWriter.prepare(outputStream);
trackWriter.writeHeader(track);
trackWriter.writeBeginTrack(track, null);
trackWriter.writeEndTrack(track, null);
trackWriter.writeFooter();
mocksControl.replay();
trackWriter.writeTrack(outputStream);
fileTrackExporter.writeTrack(outputStream);
assertTrue(trackWriter.wasSuccess());
assertTrue(fileTrackExporter.isSuccess());
mocksControl.verify();
}
@@ -123,17 +125,16 @@ public class TrackWriterTest extends AndroidTestCase {
myTracksProviderUtils.bulkInsertTrackPoint(locations, locations.length, TRACK_ID));
// Set expected mock behavior
trackFormatWriter.prepare(outputStream);
trackFormatWriter.writeHeader(track);
trackFormatWriter.writeBeginTrack(track, null);
trackFormatWriter.writeEndTrack(track, null);
trackFormatWriter.writeFooter();
trackFormatWriter.close();
trackWriter.prepare(outputStream);
trackWriter.writeHeader(track);
trackWriter.writeBeginTrack(track, null);
trackWriter.writeEndTrack(track, null);
trackWriter.writeFooter();
mocksControl.replay();
trackWriter.writeTrack(outputStream);
fileTrackExporter.writeTrack(outputStream);
assertTrue(trackWriter.wasSuccess());
assertTrue(fileTrackExporter.isSuccess());
mocksControl.verify();
}
@@ -162,43 +163,42 @@ public class TrackWriterTest extends AndroidTestCase {
waypoint.setId(i + 1);
}
trackFormatWriter.prepare(outputStream);
trackFormatWriter.writeHeader(track);
trackWriter.prepare(outputStream);
trackWriter.writeHeader(track);
// Expect reading/writing of the waypoints (except the first)
trackFormatWriter.writeBeginWaypoints();
trackFormatWriter.writeWaypoint(waypointEq(waypoints[1]));
trackFormatWriter.writeWaypoint(waypointEq(waypoints[2]));
trackFormatWriter.writeEndWaypoints();
trackWriter.writeBeginWaypoints();
trackWriter.writeWaypoint(waypointEq(waypoints[1]));
trackWriter.writeWaypoint(waypointEq(waypoints[2]));
trackWriter.writeEndWaypoints();
// Begin the track
trackFormatWriter.writeBeginTrack(trackEq(track), locationEq(locations[0]));
trackWriter.writeBeginTrack(trackEq(track), locationEq(locations[0]));
// Write locations 1-2
trackFormatWriter.writeOpenSegment();
trackFormatWriter.writeLocation(locationEq(locations[0]));
trackFormatWriter.writeLocation(locationEq(locations[1]));
trackFormatWriter.writeCloseSegment();
trackWriter.writeOpenSegment();
trackWriter.writeLocation(locationEq(locations[0]));
trackWriter.writeLocation(locationEq(locations[1]));
trackWriter.writeCloseSegment();
// Location 3 is not written - it's invalid
// Write locations 4-6
trackFormatWriter.writeOpenSegment();
trackFormatWriter.writeLocation(locationEq(locations[3]));
trackFormatWriter.writeLocation(locationEq(locations[4]));
trackFormatWriter.writeLocation(locationEq(locations[5]));
trackFormatWriter.writeCloseSegment();
trackWriter.writeOpenSegment();
trackWriter.writeLocation(locationEq(locations[3]));
trackWriter.writeLocation(locationEq(locations[4]));
trackWriter.writeLocation(locationEq(locations[5]));
trackWriter.writeCloseSegment();
// End the track
trackFormatWriter.writeEndTrack(trackEq(track), locationEq(locations[5]));
trackWriter.writeEndTrack(trackEq(track), locationEq(locations[5]));
trackFormatWriter.writeFooter();
trackFormatWriter.close();
trackWriter.writeFooter();
mocksControl.replay();
trackWriter.writeTrack(outputStream);
fileTrackExporter.writeTrack(outputStream);
assertTrue(trackWriter.wasSuccess());
assertTrue(fileTrackExporter.isSuccess());
mocksControl.verify();
}
@@ -13,7 +13,9 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.io.file;
package com.google.android.apps.mytracks.io.file.export;
import com.google.android.apps.mytracks.io.file.export.GpxTrackWriter;
import java.util.List;
@@ -25,11 +27,11 @@ import org.w3c.dom.Element;
*
* @author Rodrigo Damazio
*/
public class GpxTrackWriterTest extends TrackFormatWriterTest {
public class GpxTrackWriterTest extends TrackWriterTest {
public void testXmlOutput() throws Exception {
TrackFormatWriter writer = new GpxTrackWriter(getContext());
String result = writeTrack(writer);
GpxTrackWriter gpxTrackWriter = new GpxTrackWriter(getContext());
String result = writeTrack(gpxTrackWriter);
Document doc = parseXmlDocument(result);
Element gpxTag = getChildElement(doc, "gpx");
@@ -13,10 +13,11 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.io.file;
package com.google.android.apps.mytracks.io.file.export;
import com.google.android.apps.mytracks.content.DescriptionGenerator;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.io.file.export.KmlTrackWriter;
import com.google.android.apps.mytracks.stats.TripStatistics;
import android.location.Location;
@@ -32,7 +33,7 @@ import org.w3c.dom.Element;
*
* @author Rodrigo Damazio
*/
public class KmlTrackWriterTest extends TrackFormatWriterTest {
public class KmlTrackWriterTest extends TrackWriterTest {
private static final String FULL_TRACK_DESCRIPTION = "full track description";
@@ -54,8 +55,9 @@ public class KmlTrackWriterTest extends TrackFormatWriterTest {
}
public void testXmlOutput() throws Exception {
KmlTrackWriter writer = new KmlTrackWriter(getContext(), new FakeDescriptionGenerator());
String result = writeTrack(writer);
KmlTrackWriter kmlTrackWriter = new KmlTrackWriter(
getContext(), false, new FakeDescriptionGenerator());
String result = writeTrack(kmlTrackWriter);
Document doc = parseXmlDocument(result);
Element kmlTag = getChildElement(doc, "kml");
@@ -13,10 +13,11 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.io.file;
package com.google.android.apps.mytracks.io.file.export;
import com.google.android.apps.mytracks.content.MyTracksLocation;
import com.google.android.apps.mytracks.content.Sensor;
import com.google.android.apps.mytracks.io.file.export.TcxTrackWriter;
import com.google.android.apps.mytracks.util.StringUtils;
import java.util.List;
@@ -29,11 +30,11 @@ import org.w3c.dom.Element;
*
* @author Sandor Dornbush
*/
public class TcxTrackWriterTest extends TrackFormatWriterTest {
public class TcxTrackWriterTest extends TrackWriterTest {
public void testXmlOutput() throws Exception {
TrackFormatWriter writer = new TcxTrackWriter(getContext());
String result = writeTrack(writer);
TcxTrackWriter tcxTrackWriter = new TcxTrackWriter(getContext());
String result = writeTrack(tcxTrackWriter);
Document doc = parseXmlDocument(result);
Element root = getChildElement(doc, "TrainingCenterDatabase");
@@ -1,10 +1,11 @@
// Copyright 2010 Google Inc. All Rights Reserved.
package com.google.android.apps.mytracks.io.file;
package com.google.android.apps.mytracks.io.file.export;
import com.google.android.apps.mytracks.content.MyTracksLocation;
import com.google.android.apps.mytracks.content.Sensor;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.io.file.export.TrackWriter;
import android.test.AndroidTestCase;
@@ -34,7 +35,7 @@ import org.xml.sax.SAXException;
*
* @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
// being done.
@@ -110,29 +111,28 @@ public abstract class TrackFormatWriterTest extends AndroidTestCase {
* Makes the right sequence of calls to the writer in order to write the fake
* track in {@link #track}.
*
* @param writer the writer to write to
* @param trackWriter the track writer
* @return the written contents
*/
protected String writeTrack(TrackFormatWriter writer) throws Exception {
protected String writeTrack(TrackWriter trackWriter) throws Exception {
OutputStream output = new ByteArrayOutputStream(BUFFER_SIZE);
writer.prepare(output);
writer.writeHeader(track);
writer.writeBeginWaypoints();
writer.writeWaypoint(wp1);
writer.writeWaypoint(wp2);
writer.writeEndWaypoints();
writer.writeBeginTrack(track, location1);
writer.writeOpenSegment();
writer.writeLocation(location1);
writer.writeLocation(location2);
writer.writeCloseSegment();
writer.writeOpenSegment();
writer.writeLocation(location3);
writer.writeLocation(location4);
writer.writeCloseSegment();
writer.writeEndTrack(track, location4);
writer.writeFooter();
writer.close();
trackWriter.prepare(output);
trackWriter.writeHeader(track);
trackWriter.writeBeginWaypoints();
trackWriter.writeWaypoint(wp1);
trackWriter.writeWaypoint(wp2);
trackWriter.writeEndWaypoints();
trackWriter.writeBeginTrack(track, location1);
trackWriter.writeOpenSegment();
trackWriter.writeLocation(location1);
trackWriter.writeLocation(location2);
trackWriter.writeCloseSegment();
trackWriter.writeOpenSegment();
trackWriter.writeLocation(location3);
trackWriter.writeLocation(location4);
trackWriter.writeCloseSegment();
trackWriter.writeEndTrack(track, location4);
trackWriter.writeFooter();
return output.toString();
}