1818import androidx .test .ext .junit .runners .AndroidJUnit4 ;
1919import androidx .test .filters .LargeTest ;
2020import androidx .test .platform .app .InstrumentationRegistry ;
21+ import androidx .test .rule .GrantPermissionRule ;
2122import androidx .test .rule .ServiceTestRule ;
2223
2324import org .junit .After ;
4546import java .util .stream .Collectors ;
4647
4748import de .dennisguse .opentracks .R ;
49+ import de .dennisguse .opentracks .TestUtil ;
4850import de .dennisguse .opentracks .TimezoneRule ;
4951import de .dennisguse .opentracks .content .data .TestDataUtil ;
5052import de .dennisguse .opentracks .data .ContentProviderUtils ;
@@ -87,6 +89,9 @@ public class ExportImportTest {
8789 @ Rule
8890 public final ServiceTestRule mServiceRule = ServiceTestRule .withTimeout (5 , TimeUnit .SECONDS );
8991
92+ @ Rule
93+ public GrantPermissionRule mGrantPermissionRule = TestUtil .createGrantPermissionRule ();
94+
9095 //For csv_export_only() as we the timezone is hardcoded in the expectation.
9196 @ Rule
9297 public TimezoneRule timezoneRule = new TimezoneRule (TimeZone .getTimeZone ("Europe/Berlin" ));
@@ -144,7 +149,7 @@ public void setUp() throws TimeoutException {
144149
145150 Distance sensorDistance = Distance .of (10 ); // recording distance interval
146151
147- sendLocation (trackPointCreator , "2020-02-02T02:02:03Z" , 3 , 14 , 10 , 13 , 15 , 10 , 1f );
152+ sendLocation (trackPointCreator , "2020-02-02T02:02:03Z" , 3.1234567 , 14.0014567 , 10 , 13 , 15 , 1020.25 , 1f );
148153 contentProviderUtils .insertMarker (new Marker (trackId , service .getLastStoredTrackPointWithLocation (), "Marker 1" , "Marker 1 desc" , "Marker 1 category" , null , null ));
149154
150155 // A sensor-only TrackPoint
@@ -155,11 +160,10 @@ public void setUp() throws TimeoutException {
155160 mockSensorData (trackPointCreator , 15f , null , 67f , 3f , 50f , null );
156161 trackPointCreator .setClock ("2020-02-02T02:02:15Z" );
157162 mockSensorData (trackPointCreator , null , null , 68f , 3f , 50f , null );
158-
159163 trackPointCreator .setClock ("2020-02-02T02:02:16Z" );
160164 mockSensorData (trackPointCreator , 5f , Distance .of (2 ), 69f , 3f , 50f , null ); // Distance will be added to next TrackPoint
161165
162- sendLocation (trackPointCreator , "2020-02-02T02:02:17Z" , 3 , 14.001 , 10 , 13 , 15 , 10 , 0f );
166+ sendLocation (trackPointCreator , "2020-02-02T02:02:17Z" , 3.1234567 , 14.0014567 , 10 , 13 , 15 , 1020.25 , 0f );
163167 contentProviderUtils .insertMarker (new Marker (trackId , service .getLastStoredTrackPointWithLocation (), "Marker 2" , "Marker 2 desc" , "Marker 2 category" , null , null ));
164168
165169 trackPointCreator .setClock ("2020-02-02T02:02:18Z" );
@@ -169,14 +173,14 @@ public void setUp() throws TimeoutException {
169173 trackPointCreator .setClock ("2020-02-02T02:03:20Z" );
170174 service .resumeTrack (trackId );
171175
172- sendLocation (trackPointCreator , "2020-02-02T02:03:21Z" , 3 , 14.002 , 10 , 13 , 15 , 10 , 0f );
176+ sendLocation (trackPointCreator , "2020-02-02T02:03:21Z" , 3.1234567 , 14.0024567 , 10 , 13 , 15 , 999.123 , 0f );
173177
174- sendLocation (trackPointCreator , "2020-02-02T02:03:22Z" , 3 , 16 , 10 , 13 , 15 , 10 , 0f );
178+ sendLocation (trackPointCreator , "2020-02-02T02:03:22Z" , 3.1234567 , 16 , 10 , 13 , 15 , 999.123 , 0f );
175179
176180 trackPointCreator .setClock ("2020-02-02T02:03:30Z" );
177181 service .getTrackRecordingManager ().onIdle ();
178182
179- sendLocation (trackPointCreator , "2020-02-02T02:03:50Z" , 3 , 16.001 , 10 , 27 , 15 , 10 , 0f );
183+ sendLocation (trackPointCreator , "2020-02-02T02:03:50Z" , 3.1234567 , 16.001 , 10 , 27 , 15 , 999.123 , 0f );
180184
181185 trackPointCreator .getSensorManager ().sensorDataSet = new SensorDataSet (trackPointCreator );
182186 trackPointCreator .setClock ("2020-02-02T02:04:00Z" );
@@ -209,16 +213,16 @@ public void track() throws TimeoutException {
209213 assertEquals (Duration .ofSeconds (26 ), trackStatistics .getMovingTime ()); //TODO Likely too low
210214
211215 // Distance
212- assertEquals (222125.53125 , trackStatistics .getTotalDistance ().toM (), 0.01 ); //TODO Too low
216+ assertEquals (222049.34375 , trackStatistics .getTotalDistance ().toM (), 0.01 ); //TODO Too low
213217
214218 // Speed
215- assertEquals (8543.29 , trackStatistics .getMaxSpeed ().toMPS (), 0.01 );
216- assertEquals (3966.52 , trackStatistics .getAverageSpeed ().toMPS (), 0.01 );
217- assertEquals (8543.28 , trackStatistics .getAverageMovingSpeed ().toMPS (), 0.01 );
219+ assertEquals (8540.359 , trackStatistics .getMaxSpeed ().toMPS (), 0.01 );
220+ assertEquals (3965.166 , trackStatistics .getAverageSpeed ().toMPS (), 0.01 );
221+ assertEquals (8540.359 , trackStatistics .getAverageMovingSpeed ().toMPS (), 0.01 );
218222
219223 // Altitude
220- assertEquals (10 , trackStatistics .getMinAltitude (), 0.01 );
221- assertEquals (10 , trackStatistics .getMaxAltitude (), 0.01 );
224+ assertEquals (999.122 , trackStatistics .getMinAltitude (), 0.01 );
225+ assertEquals (1020.25 , trackStatistics .getMaxAltitude (), 0.01 );
222226
223227 assertEquals (2 , trackStatistics .getTotalAltitudeGain (), 0.01 );
224228 assertEquals (2 , trackStatistics .getTotalAltitudeLoss (), 0.01 );
@@ -229,8 +233,8 @@ public void track() throws TimeoutException {
229233 new TrackPoint (TrackPoint .Type .TRACKPOINT ,
230234 new Position (
231235 Instant .parse ("2020-02-02T02:02:03Z" ),
232- 3d , 14d , Distance .of (10 ),
233- Altitude .WGS84 .of (10 ), null ,
236+ 3.123456 , 14.001456 , Distance .of (10 ),
237+ Altitude .WGS84 .of (1020.25 ), null ,
234238 null ,
235239 Speed .of (15 )))
236240 .setAltitudeLoss (1f )
@@ -251,8 +255,8 @@ public void track() throws TimeoutException {
251255 new TrackPoint (TrackPoint .Type .TRACKPOINT ,
252256 new Position (
253257 Instant .parse ("2020-02-02T02:02:17Z" ),
254- 3d , 14.001 , Distance .of (10 ),
255- Altitude .WGS84 .of (10 ), null ,
258+ 3.123456 , 14.001456 , Distance .of (10 ),
259+ Altitude .WGS84 .of (1020.25 ), null ,
256260 null ,
257261 Speed .of (5 )))
258262 .setSensorDistance (Distance .of (2 ))
@@ -266,16 +270,16 @@ public void track() throws TimeoutException {
266270 new TrackPoint (TrackPoint .Type .TRACKPOINT ,
267271 new Position (
268272 Instant .parse ("2020-02-02T02:03:21Z" ),
269- 3d , 14.002d , Distance .of (10 ),
270- Altitude .WGS84 .of (10 ), null ,
273+ 3.123456 , 14.002456 , Distance .of (10 ),
274+ Altitude .WGS84 .of (999.1229858398438 ), null ,
271275 null ,
272276 Speed .of (15 )))
273277 .setAltitudeLoss (0f )
274278 .setAltitudeGain (0f ),
275279 new TrackPoint (TrackPoint .Type .SEGMENT_START_AUTOMATIC ,
276280 new Position (Instant .parse ("2020-02-02T02:03:22Z" ),
277- 3d , 16d , Distance .of (10 ),
278- Altitude .WGS84 .of (10 ), null ,
281+ 3.123456 , 16d , Distance .of (10 ),
282+ Altitude .WGS84 .of (999.1229858398438 ), null ,
279283 null ,
280284 Speed .of (15 )))
281285 .setAltitudeLoss (0f )
@@ -286,8 +290,8 @@ public void track() throws TimeoutException {
286290 new TrackPoint (TrackPoint .Type .TRACKPOINT ,
287291 new Position (
288292 Instant .parse ("2020-02-02T02:03:50Z" ),
289- 3d , 16.001 , Distance .of (10 ),
290- Altitude .WGS84 .of (10 ), null ,
293+ 3.123456 , 16.001 , Distance .of (10 ),
294+ Altitude .WGS84 .of (999.1229858398438 ), null ,
291295 null , Speed .of (15 )))
292296 .setAltitudeLoss (0f )
293297 .setAltitudeGain (0f ),
@@ -334,7 +338,26 @@ public void kmz_with_trackdetail_and_sensordata() throws TimeoutException, IOExc
334338
335339 // Time
336340 assertEquals (track .getZoneOffset (), importedTrack .getZoneOffset ());
337- assertEquals (track .getTrackStatistics (), importedTrackStatistics );
341+ assertEquals (Instant .parse ("2020-02-02T02:02:02Z" ), importedTrackStatistics .getStartTime ());
342+ assertEquals (Instant .parse ("2020-02-02T02:04:00Z" ), importedTrackStatistics .getStopTime ());
343+
344+ assertEquals (Duration .ofSeconds (56 ), importedTrackStatistics .getTotalTime ());
345+ assertEquals (Duration .ofSeconds (26 ), importedTrackStatistics .getMovingTime ());
346+
347+ // Distance
348+ assertEquals (222049.421 , importedTrackStatistics .getTotalDistance ().toM (), 0.01 );
349+
350+ // Speed
351+ assertEquals (8540.362 , importedTrackStatistics .getMaxSpeed ().toMPS (), 0.01 );
352+ assertEquals (3965.168 , importedTrackStatistics .getAverageSpeed ().toMPS (), 0.01 );
353+ assertEquals (8540.362 , importedTrackStatistics .getAverageMovingSpeed ().toMPS (), 0.01 );
354+
355+ // Altitude
356+ assertEquals (999.122 , importedTrackStatistics .getMinAltitude (), 0.01 );
357+ assertEquals (1020.25 , importedTrackStatistics .getMaxAltitude (), 0.01 );
358+ assertEquals (2 , importedTrackStatistics .getTotalAltitudeGain (), 0.01 );
359+ assertEquals (2 , importedTrackStatistics .getTotalAltitudeLoss (), 0.01 );
360+
338361
339362 // 4. markers
340363 assertMarkers ();
@@ -406,17 +429,17 @@ public void gpx() throws TimeoutException, IOException {
406429 new TrackPoint (TrackPoint .Type .SEGMENT_START_AUTOMATIC ,
407430 new Position (
408431 Instant .parse ("2020-02-02T02:02:03Z" ),
409- 3d , 14d , Distance .of (10 ),
410- Altitude .WGS84 .of (10 ), null ,
432+ 3.123456 , 14.001456d , Distance .of (10 ),
433+ Altitude .WGS84 .of (1020.2 ), null ,
411434 null ,
412435 Speed .of (15 )))
413436 .setAltitudeLoss (1f )
414437 .setAltitudeGain (1f ),
415438 new TrackPoint (TrackPoint .Type .TRACKPOINT ,
416439 new Position (
417440 Instant .parse ("2020-02-02T02:02:17Z" ),
418- 3d , 14.001 , Distance .of (10 ),
419- Altitude .WGS84 .of (10 ), null ,
441+ 3.123456 , 14.001456 , Distance .of (10 ),
442+ Altitude .WGS84 .of (1020.2 ), null ,
420443 null ,
421444 Speed .of (5 )))
422445 .setAltitudeLoss (1f )
@@ -428,26 +451,26 @@ public void gpx() throws TimeoutException, IOException {
428451 new TrackPoint (TrackPoint .Type .SEGMENT_START_AUTOMATIC ,
429452 new Position (
430453 Instant .parse ("2020-02-02T02:03:21Z" ),
431- 3d , 14.002 , Distance .of (10 ),
432- Altitude .WGS84 .of (10 ), null ,
454+ 3.123456 , 14.002456 , Distance .of (10 ),
455+ Altitude .WGS84 .of (999.0999755859375 ), null ,
433456 null ,
434457 Speed .of (15 )))
435458 .setAltitudeLoss (0f )
436459 .setAltitudeGain (0f ),
437460 new TrackPoint (TrackPoint .Type .SEGMENT_START_AUTOMATIC ,
438461 new Position (
439462 Instant .parse ("2020-02-02T02:03:22Z" ),
440- 3d , 16d , Distance .of (10 ),
441- Altitude .WGS84 .of (10 ), null ,
463+ 3.123456 , 16d , Distance .of (10 ),
464+ Altitude .WGS84 .of (999.0999755859375 ), null ,
442465 null ,
443466 Speed .of (15 )))
444467 .setAltitudeLoss (0f )
445468 .setAltitudeGain (0f ),
446469 new TrackPoint (TrackPoint .Type .TRACKPOINT ,
447470 new Position (
448471 Instant .parse ("2020-02-02T02:03:50Z" ),
449- 3d , 16.001 , Distance .of (10 ),
450- Altitude .WGS84 .of (10 ), null ,
472+ 3.123456 , 16.001 , Distance .of (10 ),
473+ Altitude .WGS84 .of (999.0999755859375 ), null ,
451474 null ,
452475 Speed .of (10 )))
453476 .setAltitudeLoss (0f )
@@ -467,16 +490,16 @@ public void gpx() throws TimeoutException, IOException {
467490 assertEquals (Duration .ofSeconds (107 ), importedTrackStatistics .getMovingTime ());
468491
469492 // Distance
470- assertEquals (222347.85 , importedTrackStatistics .getTotalDistance ().toM (), 0.01 );
493+ assertEquals (222271.734 , importedTrackStatistics .getTotalDistance ().toM (), 0.01 );
471494
472495 // Speed
473- assertEquals (2078.01 , importedTrackStatistics .getMaxSpeed ().toMPS (), 0.01 );
474- assertEquals (2078.01 , importedTrackStatistics .getAverageSpeed ().toMPS (), 0.01 );
475- assertEquals (2078.01 , importedTrackStatistics .getAverageMovingSpeed ().toMPS (), 0.01 );
496+ assertEquals (2077.305 , importedTrackStatistics .getMaxSpeed ().toMPS (), 0.01 );
497+ assertEquals (2077.305 , importedTrackStatistics .getAverageSpeed ().toMPS (), 0.01 );
498+ assertEquals (2077.305 , importedTrackStatistics .getAverageMovingSpeed ().toMPS (), 0.01 );
476499
477500 // Altitude
478- assertEquals (10 , importedTrackStatistics .getMinAltitude (), 0.01 );
479- assertEquals (10 , importedTrackStatistics .getMaxAltitude (), 0.01 );
501+ assertEquals (999.099 , importedTrackStatistics .getMinAltitude (), 0.01 );
502+ assertEquals (1020.2 , importedTrackStatistics .getMaxAltitude (), 0.01 );
480503 assertEquals (2 , importedTrackStatistics .getTotalAltitudeGain (), 0.01 );
481504 assertEquals (2 , importedTrackStatistics .getTotalAltitudeLoss (), 0.01 );
482505
@@ -614,7 +637,7 @@ private void mockAltitudeChange(TrackPointCreator trackPointCreator, Float altit
614637 }
615638 }
616639
617- private void sendLocation (TrackPointCreator trackPointCreator , String time , double latitude , double longitude , float accuracy , float verticalAccuracy , float speed , float altitude , Float altitudeGain ) {
640+ private void sendLocation (TrackPointCreator trackPointCreator , String time , double latitude , double longitude , float accuracy , float verticalAccuracy , float speed , double altitude , Float altitudeGain ) {
618641 Location location = new Location ("mock" );
619642 location .setLatitude (latitude );
620643 location .setLongitude (longitude );
0 commit comments