forked from upstream-mirrors/OpenTracks
Update tests.
Lazily allocate stats objects on waypoints.
This commit is contained in:
@@ -427,7 +427,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
lastValidLocation = null;
|
lastValidLocation = null;
|
||||||
|
|
||||||
Waypoint waypoint = providerUtils.getFirstWaypoint(recordingTrackId);
|
Waypoint waypoint = providerUtils.getFirstWaypoint(recordingTrackId);
|
||||||
if (waypoint != null) {
|
if (waypoint != null && waypoint.getStatistics() != null) {
|
||||||
currentWaypointId = waypoint.getId();
|
currentWaypointId = waypoint.getId();
|
||||||
waypointStatsBuilder = new TripStatisticsBuilder(
|
waypointStatsBuilder = new TripStatisticsBuilder(
|
||||||
waypoint.getStatistics());
|
waypoint.getStatistics());
|
||||||
|
|||||||
+34
-17
@@ -124,7 +124,6 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
|
|
||||||
private static ContentValues createContentValues(Waypoint waypoint) {
|
private static ContentValues createContentValues(Waypoint waypoint) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
TripStatistics stats = waypoint.getStatistics();
|
|
||||||
|
|
||||||
// Values id < 0 indicate no id is available:
|
// Values id < 0 indicate no id is available:
|
||||||
if (waypoint.getId() >= 0) {
|
if (waypoint.getId() >= 0) {
|
||||||
@@ -138,21 +137,24 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
values.put(WaypointsColumns.TYPE, waypoint.getType());
|
values.put(WaypointsColumns.TYPE, waypoint.getType());
|
||||||
values.put(WaypointsColumns.LENGTH, waypoint.getLength());
|
values.put(WaypointsColumns.LENGTH, waypoint.getLength());
|
||||||
values.put(WaypointsColumns.DURATION, waypoint.getDuration());
|
values.put(WaypointsColumns.DURATION, waypoint.getDuration());
|
||||||
values.put(WaypointsColumns.STARTTIME, stats.getStartTime());
|
|
||||||
values.put(WaypointsColumns.STARTID, waypoint.getStartId());
|
values.put(WaypointsColumns.STARTID, waypoint.getStartId());
|
||||||
values.put(WaypointsColumns.STOPID, waypoint.getStopId());
|
values.put(WaypointsColumns.STOPID, waypoint.getStopId());
|
||||||
|
|
||||||
values.put(WaypointsColumns.TOTALDISTANCE, stats.getTotalDistance());
|
TripStatistics stats = waypoint.getStatistics();
|
||||||
values.put(WaypointsColumns.TOTALTIME, stats.getTotalTime());
|
if (stats != null) {
|
||||||
values.put(WaypointsColumns.MOVINGTIME, stats.getMovingTime());
|
values.put(WaypointsColumns.TOTALDISTANCE, stats.getTotalDistance());
|
||||||
values.put(WaypointsColumns.AVGSPEED, stats.getAverageSpeed());
|
values.put(WaypointsColumns.TOTALTIME, stats.getTotalTime());
|
||||||
values.put(WaypointsColumns.AVGMOVINGSPEED, stats.getAverageMovingSpeed());
|
values.put(WaypointsColumns.MOVINGTIME, stats.getMovingTime());
|
||||||
values.put(WaypointsColumns.MAXSPEED, stats.getMaxSpeed());
|
values.put(WaypointsColumns.AVGSPEED, stats.getAverageSpeed());
|
||||||
values.put(WaypointsColumns.MINELEVATION, stats.getMinElevation());
|
values.put(WaypointsColumns.AVGMOVINGSPEED, stats.getAverageMovingSpeed());
|
||||||
values.put(WaypointsColumns.MAXELEVATION, stats.getMaxElevation());
|
values.put(WaypointsColumns.MAXSPEED, stats.getMaxSpeed());
|
||||||
values.put(WaypointsColumns.ELEVATIONGAIN, stats.getTotalElevationGain());
|
values.put(WaypointsColumns.MINELEVATION, stats.getMinElevation());
|
||||||
values.put(WaypointsColumns.MINGRADE, stats.getMinGrade());
|
values.put(WaypointsColumns.MAXELEVATION, stats.getMaxElevation());
|
||||||
values.put(WaypointsColumns.MAXGRADE, stats.getMaxGrade());
|
values.put(WaypointsColumns.ELEVATIONGAIN, stats.getTotalElevationGain());
|
||||||
|
values.put(WaypointsColumns.MINGRADE, stats.getMinGrade());
|
||||||
|
values.put(WaypointsColumns.MAXGRADE, stats.getMaxGrade());
|
||||||
|
values.put(WaypointsColumns.STARTTIME, stats.getStartTime());
|
||||||
|
}
|
||||||
|
|
||||||
Location location = waypoint.getLocation();
|
Location location = waypoint.getLocation();
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
@@ -378,7 +380,6 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
int idxSpeed = cursor.getColumnIndexOrThrow(WaypointsColumns.SPEED);
|
int idxSpeed = cursor.getColumnIndexOrThrow(WaypointsColumns.SPEED);
|
||||||
|
|
||||||
Waypoint waypoint = new Waypoint();
|
Waypoint waypoint = new Waypoint();
|
||||||
TripStatistics stats = waypoint.getStatistics();
|
|
||||||
|
|
||||||
if (!cursor.isNull(idxId)) {
|
if (!cursor.isNull(idxId)) {
|
||||||
waypoint.setId(cursor.getLong(idxId));
|
waypoint.setId(cursor.getLong(idxId));
|
||||||
@@ -407,41 +408,57 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
if (!cursor.isNull(idxDuration)) {
|
if (!cursor.isNull(idxDuration)) {
|
||||||
waypoint.setDuration(cursor.getLong(idxDuration));
|
waypoint.setDuration(cursor.getLong(idxDuration));
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(idxStartTime)) {
|
|
||||||
stats.setStartTime(cursor.getLong(idxStartTime));
|
|
||||||
}
|
|
||||||
if (!cursor.isNull(idxStartId)) {
|
if (!cursor.isNull(idxStartId)) {
|
||||||
waypoint.setStartId(cursor.getLong(idxStartId));
|
waypoint.setStartId(cursor.getLong(idxStartId));
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(idxStopId)) {
|
if (!cursor.isNull(idxStopId)) {
|
||||||
waypoint.setStopId(cursor.getLong(idxStopId));
|
waypoint.setStopId(cursor.getLong(idxStopId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TripStatistics stats = new TripStatistics();
|
||||||
|
boolean hasStats = false;
|
||||||
|
if (!cursor.isNull(idxStartTime)) {
|
||||||
|
stats.setStartTime(cursor.getLong(idxStartTime));
|
||||||
|
hasStats = true;
|
||||||
|
}
|
||||||
if (!cursor.isNull(idxTotalDistance)) {
|
if (!cursor.isNull(idxTotalDistance)) {
|
||||||
stats.setTotalDistance(cursor.getFloat(idxTotalDistance));
|
stats.setTotalDistance(cursor.getFloat(idxTotalDistance));
|
||||||
|
hasStats = true;
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(idxTotalTime)) {
|
if (!cursor.isNull(idxTotalTime)) {
|
||||||
stats.setTotalTime(cursor.getLong(idxTotalTime));
|
stats.setTotalTime(cursor.getLong(idxTotalTime));
|
||||||
|
hasStats = true;
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(idxMovingTime)) {
|
if (!cursor.isNull(idxMovingTime)) {
|
||||||
stats.setMovingTime(cursor.getLong(idxMovingTime));
|
stats.setMovingTime(cursor.getLong(idxMovingTime));
|
||||||
|
hasStats = true;
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(idxMaxSpeed)) {
|
if (!cursor.isNull(idxMaxSpeed)) {
|
||||||
stats.setMaxSpeed(cursor.getFloat(idxMaxSpeed));
|
stats.setMaxSpeed(cursor.getFloat(idxMaxSpeed));
|
||||||
|
hasStats = true;
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(idxMinElevation)) {
|
if (!cursor.isNull(idxMinElevation)) {
|
||||||
stats.setMinElevation(cursor.getFloat(idxMinElevation));
|
stats.setMinElevation(cursor.getFloat(idxMinElevation));
|
||||||
|
hasStats = true;
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(idxMaxElevation)) {
|
if (!cursor.isNull(idxMaxElevation)) {
|
||||||
stats.setMaxElevation(cursor.getFloat(idxMaxElevation));
|
stats.setMaxElevation(cursor.getFloat(idxMaxElevation));
|
||||||
|
hasStats = true;
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(idxElevationGain)) {
|
if (!cursor.isNull(idxElevationGain)) {
|
||||||
stats.setTotalElevationGain(cursor.getFloat(idxElevationGain));
|
stats.setTotalElevationGain(cursor.getFloat(idxElevationGain));
|
||||||
|
hasStats = true;
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(idxMinGrade)) {
|
if (!cursor.isNull(idxMinGrade)) {
|
||||||
stats.setMinGrade(cursor.getFloat(idxMinGrade));
|
stats.setMinGrade(cursor.getFloat(idxMinGrade));
|
||||||
|
hasStats = true;
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(idxMaxGrade)) {
|
if (!cursor.isNull(idxMaxGrade)) {
|
||||||
stats.setMaxGrade(cursor.getFloat(idxMaxGrade));
|
stats.setMaxGrade(cursor.getFloat(idxMaxGrade));
|
||||||
|
hasStats = true;
|
||||||
|
}
|
||||||
|
if (hasStats) {
|
||||||
|
waypoint.setStatistics(stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
Location location = new Location("");
|
Location location = new Location("");
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public final class Waypoint implements Parcelable {
|
|||||||
/** Stop track point id */
|
/** Stop track point id */
|
||||||
private long stopId = -1;
|
private long stopId = -1;
|
||||||
|
|
||||||
private TripStatistics stats = new TripStatistics();
|
private TripStatistics stats;
|
||||||
|
|
||||||
/** The length of the track, without smoothing. */
|
/** The length of the track, without smoothing. */
|
||||||
private double length;
|
private double length;
|
||||||
|
|||||||
+27
-1
@@ -23,9 +23,12 @@ import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
|||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.content.WaypointType;
|
import com.google.android.apps.mytracks.content.WaypointType;
|
||||||
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.Factory;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||||
|
import com.google.android.apps.mytracks.testing.TestingProviderUtilsFactory;
|
||||||
import com.google.android.apps.mytracks.util.ApiFeatures;
|
import com.google.android.apps.mytracks.util.ApiFeatures;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
import com.google.android.testing.mocking.AndroidMock;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
@@ -37,6 +40,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.RemoteException;
|
||||||
import android.test.RenamingDelegatingContext;
|
import android.test.RenamingDelegatingContext;
|
||||||
import android.test.ServiceTestCase;
|
import android.test.ServiceTestCase;
|
||||||
import android.test.mock.MockContentResolver;
|
import android.test.mock.MockContentResolver;
|
||||||
@@ -565,7 +569,19 @@ public class TrackRecordingServiceTest
|
|||||||
assertEquals(1, service.insertWaypoint(WaypointType.STATISTICS));
|
assertEquals(1, service.insertWaypoint(WaypointType.STATISTICS));
|
||||||
assertEquals(2, service.insertWaypoint(WaypointType.STATISTICS));
|
assertEquals(2, service.insertWaypoint(WaypointType.STATISTICS));
|
||||||
|
|
||||||
// TODO: Add more checks.
|
Waypoint wpt = providerUtils.getWaypoint(1);
|
||||||
|
assertEquals(getContext().getString(R.string.stats_icon_url),
|
||||||
|
wpt.getIcon());
|
||||||
|
assertEquals(getContext().getString(R.string.statistics),
|
||||||
|
wpt.getName());
|
||||||
|
assertEquals(Waypoint.TYPE_STATISTICS, wpt.getType());
|
||||||
|
assertEquals(123, wpt.getTrackId());
|
||||||
|
assertEquals(0.0, wpt.getLength());
|
||||||
|
assertNotNull(wpt.getLocation());
|
||||||
|
assertNotNull(wpt.getStatistics());
|
||||||
|
// TODO check the rest of the params.
|
||||||
|
|
||||||
|
// TODO: Check waypoint 2.
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
@@ -589,6 +605,16 @@ public class TrackRecordingServiceTest
|
|||||||
assertTrue(service.isRecording());
|
assertTrue(service.isRecording());
|
||||||
|
|
||||||
assertEquals(1, service.insertWaypoint(WaypointType.MARKER));
|
assertEquals(1, service.insertWaypoint(WaypointType.MARKER));
|
||||||
|
Waypoint wpt = providerUtils.getWaypoint(1);
|
||||||
|
assertEquals(getContext().getString(R.string.waypoint_icon_url),
|
||||||
|
wpt.getIcon());
|
||||||
|
assertEquals(getContext().getString(R.string.waypoint),
|
||||||
|
wpt.getName());
|
||||||
|
assertEquals(Waypoint.TYPE_WAYPOINT, wpt.getType());
|
||||||
|
assertEquals(123, wpt.getTrackId());
|
||||||
|
assertEquals(0.0, wpt.getLength());
|
||||||
|
assertNotNull(wpt.getLocation());
|
||||||
|
assertNull(wpt.getStatistics());
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ limitations under the License.
|
|||||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
<uses-permission android:name="com.google.android.apps.mytracks.TRACK_NOTIFICATIONS" />
|
<uses-permission android:name="com.google.android.apps.mytracks.TRACK_NOTIFICATIONS" />
|
||||||
|
<uses-permission android:name="com.google.android.apps.mytracks.READ_TRACK_DATA" />
|
||||||
<uses-permission android:name="com.google.android.apps.mytracks.WRITE_TRACK_DATA" />
|
<uses-permission android:name="com.google.android.apps.mytracks.WRITE_TRACK_DATA" />
|
||||||
<uses-feature android:name="android.hardware.telephony" android:required="true"/>
|
<uses-feature android:name="android.hardware.telephony" android:required="true"/>
|
||||||
<uses-feature android:name="android.hardware.telephony.gsm" android:required="false"/>
|
<uses-feature android:name="android.hardware.telephony.gsm" android:required="false"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user