forked from upstream-mirrors/OpenTracks
Code cleanup: PauseResumeTest
This commit is contained in:
+7
-8
@@ -18,7 +18,6 @@ package com.google.android.apps.mytracks.endtoendtest;
|
|||||||
|
|
||||||
import com.google.android.apps.mytracks.ChartView;
|
import com.google.android.apps.mytracks.ChartView;
|
||||||
import com.google.android.apps.mytracks.TrackListActivity;
|
import com.google.android.apps.mytracks.TrackListActivity;
|
||||||
import com.google.android.apps.mytracks.util.StringUtils;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
import com.robotium.solo.Solo;
|
import com.robotium.solo.Solo;
|
||||||
|
|
||||||
@@ -807,15 +806,15 @@ public class EndToEndTestUtils {
|
|||||||
*/
|
*/
|
||||||
public static void checkNotRecording() {
|
public static void checkNotRecording() {
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
Assert.assertEquals(trackListActivity.getString(R.string.image_record), (String) SOLO
|
Assert.assertEquals(trackListActivity.getString(R.string.image_record),
|
||||||
.getCurrentActivity().findViewById(R.id.track_controller_record).getContentDescription());
|
(String) SOLO.getCurrentActivity()
|
||||||
Assert.assertFalse(SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop)
|
.findViewById(R.id.track_controller_record).getContentDescription());
|
||||||
.isEnabled());
|
Assert.assertFalse(
|
||||||
|
SOLO.getCurrentActivity().findViewById(R.id.track_controller_stop).isEnabled());
|
||||||
Assert.assertNull(findTextView(trackListActivity.getString(R.string.generic_recording)));
|
Assert.assertNull(findTextView(trackListActivity.getString(R.string.generic_recording)));
|
||||||
Assert.assertNull(findTextView(trackListActivity.getString(R.string.generic_paused)));
|
Assert.assertNull(findTextView(trackListActivity.getString(R.string.generic_paused)));
|
||||||
TextView totalTime = (TextView) SOLO.getCurrentActivity().findViewById(
|
Assert.assertFalse(
|
||||||
R.id.track_controller_total_time);
|
SOLO.getCurrentActivity().findViewById(R.id.track_controller_total_time).isShown());
|
||||||
Assert.assertEquals(StringUtils.formatElapsedTimeWithHour(0), totalTime.getText().toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
-155
@@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package com.google.android.apps.mytracks.endtoendtest.common;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.TrackListActivity;
|
|
||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
|
||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator;
|
|
||||||
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
|
||||||
import com.google.android.apps.mytracks.services.TrackRecordingService;
|
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
|
||||||
import android.location.Location;
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the pause and resume of recording.
|
|
||||||
*
|
|
||||||
* @author Youtao Liu
|
|
||||||
*/
|
|
||||||
public class PauseRecordingTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
|
||||||
|
|
||||||
private Instrumentation instrumentation;
|
|
||||||
private TrackListActivity activityMyTracks;
|
|
||||||
|
|
||||||
public PauseRecordingTest() {
|
|
||||||
super(TrackListActivity.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
instrumentation = getInstrumentation();
|
|
||||||
activityMyTracks = getActivity();
|
|
||||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the pause recording feature. Stops the recording after pause.
|
|
||||||
*/
|
|
||||||
public void testPauseRecording_stopAfterPause() {
|
|
||||||
int gpsSignalNumber = 3;
|
|
||||||
|
|
||||||
EndToEndTestUtils.checkNotRecording();
|
|
||||||
// Start recording
|
|
||||||
EndToEndTestUtils.startRecording();
|
|
||||||
EndToEndTestUtils.checkUnderRecording();
|
|
||||||
EndToEndTestUtils.sendGps(gpsSignalNumber);
|
|
||||||
|
|
||||||
// Pause
|
|
||||||
EndToEndTestUtils.pauseRecording();
|
|
||||||
EndToEndTestUtils.checkUnderPaused();
|
|
||||||
EndToEndTestUtils.sendGps(gpsSignalNumber, gpsSignalNumber);
|
|
||||||
|
|
||||||
// Stop
|
|
||||||
EndToEndTestUtils.stopRecording(true);
|
|
||||||
checkPointsInPausedTrack(gpsSignalNumber, 1, 0);
|
|
||||||
EndToEndTestUtils.SOLO.goBack();
|
|
||||||
EndToEndTestUtils.checkNotRecording();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the pause recording feature. Stops the recording after resume.
|
|
||||||
*/
|
|
||||||
public void testPauseRecording_stopAfterResume() {
|
|
||||||
int gpsSignalNumber = 0;
|
|
||||||
|
|
||||||
EndToEndTestUtils.checkNotRecording();
|
|
||||||
// Start recording
|
|
||||||
EndToEndTestUtils.startRecording();
|
|
||||||
EndToEndTestUtils.checkUnderRecording();
|
|
||||||
EndToEndTestUtils.sendGps(gpsSignalNumber);
|
|
||||||
|
|
||||||
// Pause
|
|
||||||
EndToEndTestUtils.pauseRecording();
|
|
||||||
EndToEndTestUtils.checkUnderPaused();
|
|
||||||
|
|
||||||
// Send Gps signal after pause.
|
|
||||||
// Add 10 to make these signals are apparently different.
|
|
||||||
EndToEndTestUtils.sendGps(gpsSignalNumber, gpsSignalNumber + 10, 10);
|
|
||||||
|
|
||||||
// Resume
|
|
||||||
EndToEndTestUtils.resumeRecording();
|
|
||||||
EndToEndTestUtils.checkUnderRecording();
|
|
||||||
EndToEndTestUtils.sendGps(gpsSignalNumber, gpsSignalNumber);
|
|
||||||
|
|
||||||
// Stop
|
|
||||||
EndToEndTestUtils.stopRecording(true);
|
|
||||||
checkPointsInPausedTrack(gpsSignalNumber * 2, 1, 1);
|
|
||||||
EndToEndTestUtils.SOLO.goBack();
|
|
||||||
EndToEndTestUtils.checkNotRecording();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check the points in the last track.
|
|
||||||
*
|
|
||||||
* @param expectPointNumber the number of location points
|
|
||||||
* @param expectPauseNumber the number of pause points
|
|
||||||
* @param expectResumeNumber the number of resume points
|
|
||||||
*/
|
|
||||||
private void checkPointsInPausedTrack(int expectPointNumber, int expectPauseNumber,
|
|
||||||
int expectResumeNumber) {
|
|
||||||
if (EndToEndTestUtils.isEmulator) {
|
|
||||||
int numberOfPoints = 0;
|
|
||||||
int numberOfPausePoint = 0;
|
|
||||||
int numberOfResumePoint = 0;
|
|
||||||
|
|
||||||
MyTracksProviderUtils providerUtils = MyTracksProviderUtils.Factory.get(activityMyTracks
|
|
||||||
.getApplicationContext());
|
|
||||||
long trackId = providerUtils.getLastTrack().getId();
|
|
||||||
LocationIterator points = providerUtils.getTrackPointLocationIterator(trackId, 0, false,
|
|
||||||
MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
|
||||||
while (points.hasNext()) {
|
|
||||||
Location onePoint = points.next();
|
|
||||||
double latitude = onePoint.getLatitude();
|
|
||||||
double longitude = onePoint.getLongitude();
|
|
||||||
if (latitude == TrackRecordingService.PAUSE_LATITUDE) {
|
|
||||||
numberOfPausePoint++;
|
|
||||||
} else if (latitude == TrackRecordingService.RESUME_LATITUDE) {
|
|
||||||
numberOfResumePoint++;
|
|
||||||
} else {
|
|
||||||
assertEquals(numberOfPoints, (int) ((latitude - EndToEndTestUtils.START_LATITUDE)
|
|
||||||
/ EndToEndTestUtils.DELTA_LADITUDE + 0.5));
|
|
||||||
assertEquals(numberOfPoints, (int) ((longitude - EndToEndTestUtils.START_LONGITUDE)
|
|
||||||
/ EndToEndTestUtils.DELTA_LONGITUDE + 0.5));
|
|
||||||
numberOfPoints++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(expectPointNumber, numberOfPoints);
|
|
||||||
assertEquals(expectPauseNumber, numberOfPausePoint);
|
|
||||||
assertEquals(expectResumeNumber, numberOfResumePoint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void tearDown() throws Exception {
|
|
||||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+152
@@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012 Google Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package com.google.android.apps.mytracks.endtoendtest.common;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.TrackListActivity;
|
||||||
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||||
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator;
|
||||||
|
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
|
||||||
|
import com.google.android.apps.mytracks.services.TrackRecordingService;
|
||||||
|
|
||||||
|
import android.app.Instrumentation;
|
||||||
|
import android.location.Location;
|
||||||
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests pause and resume during a recording.
|
||||||
|
*
|
||||||
|
* @author Youtao Liu
|
||||||
|
*/
|
||||||
|
public class PauseResumeTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||||
|
|
||||||
|
private static final int SEND_INTERVAL = 100; // ms
|
||||||
|
|
||||||
|
private Instrumentation instrumentation;
|
||||||
|
private TrackListActivity trackListActivity;
|
||||||
|
|
||||||
|
public PauseResumeTest() {
|
||||||
|
super(TrackListActivity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
instrumentation = getInstrumentation();
|
||||||
|
trackListActivity = getActivity();
|
||||||
|
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests stop after a pause.
|
||||||
|
*/
|
||||||
|
public void testStopAfterPause() {
|
||||||
|
int firstBatch = 3;
|
||||||
|
int secondBatch = 10;
|
||||||
|
|
||||||
|
EndToEndTestUtils.checkNotRecording();
|
||||||
|
|
||||||
|
// Start a recording
|
||||||
|
EndToEndTestUtils.startRecording();
|
||||||
|
EndToEndTestUtils.checkUnderRecording();
|
||||||
|
EndToEndTestUtils.sendGps(firstBatch);
|
||||||
|
|
||||||
|
// Pause the recording
|
||||||
|
EndToEndTestUtils.pauseRecording();
|
||||||
|
EndToEndTestUtils.checkUnderPaused();
|
||||||
|
EndToEndTestUtils.sendGps(secondBatch, firstBatch);
|
||||||
|
|
||||||
|
// Stop the recording
|
||||||
|
EndToEndTestUtils.stopRecording(true);
|
||||||
|
checkTrackLocation(firstBatch, 1, 0);
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
EndToEndTestUtils.checkNotRecording();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests stop after a resume.
|
||||||
|
*/
|
||||||
|
public void testStopAfterResume() {
|
||||||
|
int firstBatch = 3;
|
||||||
|
int secondBatch = 5;
|
||||||
|
int thirdBatch = 7;
|
||||||
|
|
||||||
|
EndToEndTestUtils.checkNotRecording();
|
||||||
|
|
||||||
|
// Start a recording
|
||||||
|
EndToEndTestUtils.startRecording();
|
||||||
|
EndToEndTestUtils.checkUnderRecording();
|
||||||
|
EndToEndTestUtils.sendGps(firstBatch);
|
||||||
|
|
||||||
|
// Pause the recording
|
||||||
|
EndToEndTestUtils.pauseRecording();
|
||||||
|
EndToEndTestUtils.checkUnderPaused();
|
||||||
|
|
||||||
|
// Send gps signal after pause
|
||||||
|
EndToEndTestUtils.sendGps(secondBatch, firstBatch, SEND_INTERVAL);
|
||||||
|
|
||||||
|
// Resume the recording
|
||||||
|
EndToEndTestUtils.resumeRecording();
|
||||||
|
EndToEndTestUtils.checkUnderRecording();
|
||||||
|
EndToEndTestUtils.sendGps(thirdBatch, firstBatch + secondBatch);
|
||||||
|
|
||||||
|
// Stop the recordinga
|
||||||
|
EndToEndTestUtils.stopRecording(true);
|
||||||
|
checkTrackLocation(firstBatch + secondBatch, 1, 1);
|
||||||
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
|
EndToEndTestUtils.checkNotRecording();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the last track's location.
|
||||||
|
*
|
||||||
|
* @param expectedPoint the number of expected points
|
||||||
|
* @param expectedPause the number of expected pauses
|
||||||
|
* @param expectedResume the number of expected resumes
|
||||||
|
*/
|
||||||
|
private void checkTrackLocation(int expectedPoint, int expectedPause, int expectedResume) {
|
||||||
|
if (EndToEndTestUtils.isEmulator) {
|
||||||
|
int point = 0;
|
||||||
|
int pause = 0;
|
||||||
|
int resume = 0;
|
||||||
|
|
||||||
|
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(
|
||||||
|
trackListActivity.getApplicationContext());
|
||||||
|
long trackId = myTracksProviderUtils.getLastTrack().getId();
|
||||||
|
LocationIterator locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
|
trackId, 0, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
||||||
|
while (locationIterator.hasNext()) {
|
||||||
|
Location location = locationIterator.next();
|
||||||
|
double latitude = location.getLatitude();
|
||||||
|
if (latitude == TrackRecordingService.PAUSE_LATITUDE) {
|
||||||
|
pause++;
|
||||||
|
} else if (latitude == TrackRecordingService.RESUME_LATITUDE) {
|
||||||
|
resume++;
|
||||||
|
} else {
|
||||||
|
point++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(expectedPoint, point);
|
||||||
|
assertEquals(expectedPause, pause);
|
||||||
|
assertEquals(expectedResume, resume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user