forked from upstream-mirrors/OpenTracks
Export/import test now verifies the TrackPoints.
This commit is contained in:
@@ -39,7 +39,7 @@ public class TestDataUtil {
|
|||||||
|
|
||||||
TrackPoint[] trackPoints = new TrackPoint[numPoints];
|
TrackPoint[] trackPoints = new TrackPoint[numPoints];
|
||||||
for (int i = 0; i < numPoints; i++) {
|
for (int i = 0; i < numPoints; i++) {
|
||||||
trackPoints[i] = (createTrackPoint(i));
|
trackPoints[i] = createTrackPoint(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Pair<>(track, trackPoints);
|
return new Pair<>(track, trackPoints);
|
||||||
@@ -56,17 +56,21 @@ public class TestDataUtil {
|
|||||||
/**
|
/**
|
||||||
* Creates a location.
|
* Creates a location.
|
||||||
*
|
*
|
||||||
* @param i the index to set the value of location.
|
* @param i the index for the TrackPoint.
|
||||||
* @return created location
|
|
||||||
*/
|
*/
|
||||||
public static TrackPoint createTrackPoint(int i) {
|
public static TrackPoint createTrackPoint(int i) {
|
||||||
Location location = new Location("test");
|
TrackPoint trackPoint = new TrackPoint();
|
||||||
location.setLatitude(INITIAL_LATITUDE + (double) i / 10000.0);
|
trackPoint.setLatitude(INITIAL_LATITUDE + (double) i / 10000.0);
|
||||||
location.setLongitude(INITIAL_LONGITUDE - (double) i / 10000.0);
|
trackPoint.setLongitude(INITIAL_LONGITUDE - (double) i / 10000.0);
|
||||||
location.setAccuracy((float) i / 100.0f);
|
trackPoint.setAccuracy((float) i / 100.0f);
|
||||||
location.setAltitude(i * ALTITUDE_INTERVAL);
|
trackPoint.setAltitude(i * ALTITUDE_INTERVAL);
|
||||||
location.setTime(i + 1);
|
trackPoint.setTime(i + 1);
|
||||||
return new TrackPoint(location);
|
|
||||||
|
trackPoint.setHeartRate_bpm(100f + i);
|
||||||
|
trackPoint.setCyclingCadence_rpm(200f + i);
|
||||||
|
trackPoint.setCyclingCadence_rpm(300f + i);
|
||||||
|
trackPoint.setPower(400f + i);
|
||||||
|
return trackPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+78
-12
@@ -17,6 +17,7 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.TestDataUtil;
|
import de.dennisguse.opentracks.content.data.TestDataUtil;
|
||||||
@@ -35,6 +36,7 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
* Export a track to {@link TrackFileFormat} and verify that the import is identical.
|
* Export a track to {@link TrackFileFormat} and verify that the import is identical.
|
||||||
* <p>
|
* <p>
|
||||||
* TODO: test ignores {@link TrackStatistics} for now.
|
* TODO: test ignores {@link TrackStatistics} for now.
|
||||||
|
* TODO: enable verify speed.
|
||||||
*/
|
*/
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class ExportImportTest {
|
public class ExportImportTest {
|
||||||
@@ -48,7 +50,10 @@ public class ExportImportTest {
|
|||||||
private static final String TRACK_ICON = "the track icon";
|
private static final String TRACK_ICON = "the track icon";
|
||||||
private static final String TRACK_CATEGORY = "the category";
|
private static final String TRACK_CATEGORY = "the category";
|
||||||
private static final String TRACK_DESCRIPTION = "the description";
|
private static final String TRACK_DESCRIPTION = "the description";
|
||||||
|
|
||||||
private final List<Waypoint> waypoints = new ArrayList<>();
|
private final List<Waypoint> waypoints = new ArrayList<>();
|
||||||
|
private final List<TrackPoint> trackPoints = new ArrayList<>();
|
||||||
|
|
||||||
private long importTrackId;
|
private long importTrackId;
|
||||||
private final long trackId = System.currentTimeMillis();
|
private final long trackId = System.currentTimeMillis();
|
||||||
|
|
||||||
@@ -61,6 +66,9 @@ public class ExportImportTest {
|
|||||||
contentProviderUtils.insertTrack(track.first);
|
contentProviderUtils.insertTrack(track.first);
|
||||||
contentProviderUtils.bulkInsertTrackPoint(track.second, track.first.getId());
|
contentProviderUtils.bulkInsertTrackPoint(track.second, track.first.getId());
|
||||||
|
|
||||||
|
trackPoints.clear();
|
||||||
|
trackPoints.addAll(Arrays.asList(track.second));
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
Waypoint waypoint = new Waypoint(track.second[i].getLocation());
|
Waypoint waypoint = new Waypoint(track.second[i].getLocation());
|
||||||
waypoint.setName("the waypoint " + i);
|
waypoint.setName("the waypoint " + i);
|
||||||
@@ -104,7 +112,40 @@ public class ExportImportTest {
|
|||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
trackExporter.writeTrack(context, outputStream);
|
trackExporter.writeTrack(context, outputStream);
|
||||||
|
|
||||||
System.out.println(outputStream.toString());
|
// 2. import
|
||||||
|
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
|
AbstractFileTrackImporter trackImporter = new KmlFileTrackImporter(context, -1L);
|
||||||
|
importTrackId = trackImporter.importFile(inputStream);
|
||||||
|
|
||||||
|
// then
|
||||||
|
// 1. track
|
||||||
|
Track importedTrack = contentProviderUtils.getTrack(importTrackId);
|
||||||
|
assertNotNull(importedTrack);
|
||||||
|
assertEquals(track.getCategory(), importedTrack.getCategory());
|
||||||
|
assertEquals(track.getDescription(), importedTrack.getDescription());
|
||||||
|
assertEquals(track.getName(), importedTrack.getName());
|
||||||
|
assertEquals(track.getIcon(), importedTrack.getIcon());
|
||||||
|
|
||||||
|
// 2. waypoints
|
||||||
|
assertWaypoints();
|
||||||
|
|
||||||
|
// 3. trackpoints
|
||||||
|
assertTrackpoints(false, false, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
|
@Test
|
||||||
|
public void kml_with_trackdetail_and_sensordata() {
|
||||||
|
// given
|
||||||
|
Track track = contentProviderUtils.getTrack(trackId);
|
||||||
|
|
||||||
|
TrackFileFormat trackFileFormat = TrackFileFormat.KML_WITH_TRACKDETAIL_AND_SENSORDATA;
|
||||||
|
TrackExporter trackExporter = trackFileFormat.newTrackExporter(context, new Track[]{track});
|
||||||
|
|
||||||
|
// when
|
||||||
|
// 1. export
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
trackExporter.writeTrack(context, outputStream);
|
||||||
|
|
||||||
// 2. import
|
// 2. import
|
||||||
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
@@ -115,7 +156,6 @@ public class ExportImportTest {
|
|||||||
// 1. track
|
// 1. track
|
||||||
Track importedTrack = contentProviderUtils.getTrack(importTrackId);
|
Track importedTrack = contentProviderUtils.getTrack(importTrackId);
|
||||||
assertNotNull(importedTrack);
|
assertNotNull(importedTrack);
|
||||||
//TODO assertEquals(track.getTrackPoints(), importedTrack.getTrackPoints());
|
|
||||||
assertEquals(track.getCategory(), importedTrack.getCategory());
|
assertEquals(track.getCategory(), importedTrack.getCategory());
|
||||||
assertEquals(track.getDescription(), importedTrack.getDescription());
|
assertEquals(track.getDescription(), importedTrack.getDescription());
|
||||||
assertEquals(track.getName(), importedTrack.getName());
|
assertEquals(track.getName(), importedTrack.getName());
|
||||||
@@ -124,14 +164,8 @@ public class ExportImportTest {
|
|||||||
// 2. waypoints
|
// 2. waypoints
|
||||||
assertWaypoints();
|
assertWaypoints();
|
||||||
|
|
||||||
//TODO Check absolute time of trackpoints
|
// 3. trackpoints
|
||||||
}
|
assertTrackpoints(false, true, true, true);
|
||||||
|
|
||||||
@LargeTest
|
|
||||||
@Test
|
|
||||||
public void kml_with_trackdetail_and_sensordata() {
|
|
||||||
// TODO
|
|
||||||
Log.e(TAG, "Test not implemented.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@@ -185,7 +219,6 @@ public class ExportImportTest {
|
|||||||
// 1. track
|
// 1. track
|
||||||
Track trackImported = contentProviderUtils.getTrack(importTrackId);
|
Track trackImported = contentProviderUtils.getTrack(importTrackId);
|
||||||
assertNotNull(trackImported);
|
assertNotNull(trackImported);
|
||||||
//TODO assertEquals(track.getTrackPoints(), trackImported.getTrackPoints());
|
|
||||||
assertEquals(track.getCategory(), trackImported.getCategory());
|
assertEquals(track.getCategory(), trackImported.getCategory());
|
||||||
assertEquals(track.getDescription(), trackImported.getDescription());
|
assertEquals(track.getDescription(), trackImported.getDescription());
|
||||||
assertEquals(track.getName(), trackImported.getName());
|
assertEquals(track.getName(), trackImported.getName());
|
||||||
@@ -196,7 +229,9 @@ public class ExportImportTest {
|
|||||||
// 2. waypoints
|
// 2. waypoints
|
||||||
assertWaypoints();
|
assertWaypoints();
|
||||||
|
|
||||||
//TODO Check absolute time of trackpoints
|
// 3. trackpoints
|
||||||
|
//TODO Verify speed
|
||||||
|
assertTrackpoints(false, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertWaypoints() {
|
private void assertWaypoints() {
|
||||||
@@ -217,4 +252,35 @@ public class ExportImportTest {
|
|||||||
assertEquals(waypoint.getLocation().getAltitude(), importedWaypoint.getLocation().getAltitude(), 0.001);
|
assertEquals(waypoint.getLocation().getAltitude(), importedWaypoint.getLocation().getAltitude(), 0.001);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertTrackpoints(boolean verifySpeed, boolean verifyPower, boolean verifyHeartrate, boolean verifyCadence) {
|
||||||
|
List<TrackPoint> importedTrackPoints = contentProviderUtils.getTrackPoints(importTrackId);
|
||||||
|
assertEquals(trackPoints.size(), importedTrackPoints.size());
|
||||||
|
|
||||||
|
for (int i = 0; i < trackPoints.size(); i++) {
|
||||||
|
TrackPoint trackPoint = trackPoints.get(i);
|
||||||
|
TrackPoint importedTrackPoint = importedTrackPoints.get(i);
|
||||||
|
|
||||||
|
assertEquals(trackPoint.getTime(), importedTrackPoint.getTime(), 0.01);
|
||||||
|
|
||||||
|
// TODO Not exported for GPX/KML
|
||||||
|
// assertEquals(trackPoint.getAccuracy(), importedTrackPoint.getAccuracy(), 0.01);
|
||||||
|
|
||||||
|
assertEquals(trackPoint.getLatitude(), importedTrackPoint.getLatitude(), 0.001);
|
||||||
|
assertEquals(trackPoint.getLongitude(), importedTrackPoint.getLongitude(), 0.001);
|
||||||
|
assertEquals(trackPoint.getAltitude(), importedTrackPoint.getAltitude(), 0.001);
|
||||||
|
if (verifySpeed) {
|
||||||
|
assertEquals(trackPoint.getSpeed(), importedTrackPoint.getSpeed(), 0.01);
|
||||||
|
}
|
||||||
|
if (verifyHeartrate) {
|
||||||
|
assertEquals(trackPoint.getHeartRate_bpm(), importedTrackPoint.getHeartRate_bpm(), 0.01);
|
||||||
|
}
|
||||||
|
if (verifyCadence) {
|
||||||
|
assertEquals(trackPoint.getCyclingCadence_rpm(), importedTrackPoint.getCyclingCadence_rpm(), 0.01);
|
||||||
|
}
|
||||||
|
if (verifyPower) {
|
||||||
|
assertEquals(trackPoint.getPower(), importedTrackPoint.getPower(), 0.01);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+3
-4
@@ -323,7 +323,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
|
|
||||||
// Check for negative time change
|
// Check for negative time change
|
||||||
if (timeDifference <= 0) {
|
if (timeDifference <= 0) {
|
||||||
Log.w(TAG, "Time difference not postive.");
|
Log.w(TAG, "Time difference not positive.");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -389,9 +389,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
Uri photoUri = FileUtils.getUriForFile(context, file);
|
Uri photoUri = FileUtils.getUriForFile(context, file);
|
||||||
return "" + photoUri;
|
return "" + photoUri;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
|
|||||||
trackPoint.setCyclingCadence_rpm(cadenceList.get(i));
|
trackPoint.setCyclingCadence_rpm(cadenceList.get(i));
|
||||||
}
|
}
|
||||||
if (i < powerList.size()) {
|
if (i < powerList.size()) {
|
||||||
trackPoint.setPower(cadenceList.get(i));
|
trackPoint.setPower(powerList.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
insertTrackPoint(trackPoint);
|
insertTrackPoint(trackPoint);
|
||||||
|
|||||||
Reference in New Issue
Block a user