mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
merge heads
This commit is contained in:
+1
-19
@@ -32,7 +32,6 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
private static final String WAYPOINT_NAME = "testWaypoint";
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
|
||||
@@ -126,7 +125,7 @@ public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListA
|
||||
.getString(R.string.generic_recording)));
|
||||
}
|
||||
|
||||
createWaypoint();
|
||||
EndToEndTestUtils.createWaypoint(0);
|
||||
EndToEndTestUtils.sendGps(2, 2);
|
||||
// Back to tracks list.
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
@@ -206,23 +205,6 @@ public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListA
|
||||
|
||||
EndToEndTestUtils.stopRecording(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a way point and a split maker during track recording.
|
||||
*/
|
||||
private void createWaypoint() {
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_markers), true);
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.marker_list_empty_message)));
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_insert_marker), true);
|
||||
EndToEndTestUtils.enterTextAvoidSoftKeyBoard(0, WAYPOINT_NAME);
|
||||
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_add));
|
||||
if (EndToEndTestUtils.hasGpsSingal) {
|
||||
assertTrue(EndToEndTestUtils.SOLO.waitForText(WAYPOINT_NAME, 1, EndToEndTestUtils.LONG_WAIT_TIME, true));
|
||||
} else {
|
||||
assertFalse(EndToEndTestUtils.SOLO.searchText(WAYPOINT_NAME));
|
||||
}
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
|
||||
+30
-6
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.endtoendtest;
|
||||
|
||||
import com.google.android.apps.mytracks.endtoendtest.others.BigTestUtils;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.test.InstrumentationTestRunner;
|
||||
import android.util.Log;
|
||||
@@ -31,13 +33,35 @@ public class EndToEndTestRunner extends InstrumentationTestRunner {
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle arguments) {
|
||||
try {
|
||||
EndToEndTestUtils.emulatorPort = Integer.parseInt(arguments.getString("port"));
|
||||
} catch (Exception e) {
|
||||
Log.e(EndToEndTestUtils.LOG_TAG, "Unable to get port parameter, use default value." + EndToEndTestUtils.emulatorPort, e);
|
||||
String portNumber = arguments.getString("port");
|
||||
if (portNumber != null) {
|
||||
try {
|
||||
EndToEndTestUtils.emulatorPort = Integer.parseInt(portNumber);
|
||||
} catch (Exception e) {
|
||||
Log.e(EndToEndTestUtils.LOG_TAG, "Unable to get port parameter, use default value."
|
||||
+ EndToEndTestUtils.emulatorPort, e);
|
||||
}
|
||||
}
|
||||
Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:" + EndToEndTestUtils.emulatorPort);
|
||||
|
||||
|
||||
String isStressTest = arguments.getString("stress");
|
||||
if (isStressTest != null && isStressTest.equalsIgnoreCase("true")) {
|
||||
BigTestUtils.runStressTest = true;
|
||||
} else {
|
||||
BigTestUtils.runStressTest = false;
|
||||
}
|
||||
|
||||
String isSensorTest = arguments.getString("sensor");
|
||||
if (isSensorTest != null && isSensorTest.equalsIgnoreCase("true")) {
|
||||
BigTestUtils.runSensorTest = true;
|
||||
} else {
|
||||
BigTestUtils.runSensorTest = false;
|
||||
}
|
||||
|
||||
Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:"
|
||||
+ EndToEndTestUtils.emulatorPort);
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test:" + BigTestUtils.runStressTest);
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test:" + BigTestUtils.runSensorTest);
|
||||
|
||||
super.onCreate(arguments);
|
||||
}
|
||||
|
||||
|
||||
+66
-12
@@ -56,7 +56,7 @@ public class EndToEndTestUtils {
|
||||
|
||||
private static final String ANDROID_LOCAL_IP = "10.0.2.2";
|
||||
// usually 5554.
|
||||
public static int emulatorPort = 5554;
|
||||
public static int emulatorPort = 5558;
|
||||
|
||||
private static final int ORIENTATION_PORTRAIT = 1;
|
||||
private static final int ORIENTATION_LANDSCAPE = 0;
|
||||
@@ -66,9 +66,12 @@ public class EndToEndTestUtils {
|
||||
static final double START_LATITUDE = -1.3f;
|
||||
static final double DELTA_LONGITUDE = 0.0005f;
|
||||
static final double DELTA_LADITUDE = 0.0005f;
|
||||
private static final String WAYPOINT_NAME = "testWaypoint";
|
||||
private static final String NO_GPS_MESSAGE_PREFIX = "GPS is not available";
|
||||
|
||||
private static final String MOREOPTION_CLASSNAME = "com.android.internal.view.menu.ActionMenuPresenter$OverflowMenuButton";
|
||||
private static final String MENUITEM_CLASSNAME = "com.android.internal.view.menu.IconMenuItemView";
|
||||
|
||||
|
||||
static final String DEFAULTACTIVITYTYPE = "TestActivity";
|
||||
public static String activityType = DEFAULTACTIVITYTYPE;
|
||||
@@ -248,6 +251,9 @@ public class EndToEndTestUtils {
|
||||
EndToEndTestUtils.instrumentation = instrumentation;
|
||||
EndToEndTestUtils.activityMytracks = activityMyTracks;
|
||||
SOLO = new Solo(EndToEndTestUtils.instrumentation, EndToEndTestUtils.activityMytracks);
|
||||
setIsEmulator();
|
||||
hasActionBar = setHasActionBar();
|
||||
checkLanguage();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,7 +284,7 @@ public class EndToEndTestUtils {
|
||||
Log.e(LOG_TAG, "Need update Google Play Services");
|
||||
}
|
||||
setIsEmulator();
|
||||
if ((getButtonOnScreen(EndToEndTestUtils.activityMytracks.getString(R.string.eula_accept),
|
||||
if ((getButtonOnScreen(activityMytracks.getString(R.string.eula_accept),
|
||||
false, false) != null)) {
|
||||
verifyFirstLaunch();
|
||||
} else if (SOLO.waitForText(
|
||||
@@ -297,7 +303,7 @@ public class EndToEndTestUtils {
|
||||
if (!isEmulator) {
|
||||
GoToMyLocationTest.findAndClickMyLocation(activityMyTracks);
|
||||
hasGpsSingal = !SOLO.waitForText(NO_GPS_MESSAGE_PREFIX, 1,
|
||||
EndToEndTestUtils.SHORT_WAIT_TIME);
|
||||
SHORT_WAIT_TIME);
|
||||
SOLO.goBack();
|
||||
}
|
||||
} else if (SOLO.waitForText(
|
||||
@@ -660,11 +666,11 @@ public class EndToEndTestUtils {
|
||||
findResult = SOLO.searchText(menuName, 1, true);
|
||||
} else {
|
||||
// Non-ICS phone.
|
||||
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||
if (SOLO.searchText(menuName, 1, true)) {
|
||||
findResult = true;
|
||||
} else if (SOLO.searchText(MENU_MORE, 1, true)) {
|
||||
SOLO.clickOnText(MENU_MORE);
|
||||
} else if (getMoreOptionView() != null) {
|
||||
SOLO.clickOnView(getMoreOptionView());
|
||||
findResult = SOLO.searchText(menuName, 1, true);
|
||||
isMoreMenuOpened = true;
|
||||
}
|
||||
@@ -728,18 +734,30 @@ public class EndToEndTestUtils {
|
||||
* Finds the more option menu. It should match following conditions:
|
||||
* <ul>
|
||||
* <li>The view extends ImageButton.</li>
|
||||
* <li>The view name equals {@link EndToEndTestUtils#MOREOPTION_CLASSNAME}.</li>
|
||||
* <li>The view name equals {@link #MOREOPTION_CLASSNAME}.</li>
|
||||
* </ul>
|
||||
* @return the more option view. Null means can not find it.
|
||||
*/
|
||||
private static View getMoreOptionView() {
|
||||
ArrayList<View> allViews = SOLO.getViews();
|
||||
for (View view : allViews) {
|
||||
if (view instanceof ImageButton && view.getClass().getName().equals(MOREOPTION_CLASSNAME)) {
|
||||
return view;
|
||||
View viewResult = null;
|
||||
if (hasActionBar) {
|
||||
ArrayList<View> allViews = SOLO.getViews();
|
||||
for (View view : allViews) {
|
||||
if (view instanceof ImageButton && view.getClass().getName().equals(MOREOPTION_CLASSNAME)) {
|
||||
viewResult = view;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ArrayList<View> allViews = SOLO.getViews();
|
||||
for (View view : allViews) {
|
||||
if (view.getClass().getName().equals(MENUITEM_CLASSNAME)) {
|
||||
viewResult = view;
|
||||
// No break here to get the last menu item.
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return viewResult;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -921,5 +939,41 @@ public class EndToEndTestUtils {
|
||||
.findViewById(R.id.track_controller_total_time)).getText().toString();
|
||||
Assert.assertTrue(totalTimeOld.equalsIgnoreCase(totalTimeNew));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a way point during track recording.
|
||||
*
|
||||
* @param markerNumber of number of previous markers
|
||||
*/
|
||||
public static void createWaypoint(int markerNumber) {
|
||||
findMenuItem(activityMytracks.getString(R.string.menu_markers), true);
|
||||
if (markerNumber > 0) {
|
||||
int actualMarkerNumber = SOLO.getCurrentListViews().get(0).getCount();
|
||||
Assert.assertEquals(markerNumber, actualMarkerNumber);
|
||||
} else {
|
||||
Assert.assertTrue(SOLO.waitForText(activityMytracks
|
||||
.getString(R.string.marker_list_empty_message)));
|
||||
}
|
||||
findMenuItem(activityMytracks.getString(R.string.menu_insert_marker), true);
|
||||
enterTextAvoidSoftKeyBoard(0, WAYPOINT_NAME);
|
||||
SOLO.clickOnButton(activityMytracks.getString(R.string.generic_add));
|
||||
if (hasGpsSingal) {
|
||||
Assert.assertTrue(SOLO.waitForText(WAYPOINT_NAME, 1, LONG_WAIT_TIME, true));
|
||||
} else {
|
||||
Assert.assertFalse(SOLO.searchText(WAYPOINT_NAME));
|
||||
}
|
||||
SOLO.goBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits a text to disappear.
|
||||
*/
|
||||
public static void waitTextToDisappear(String text) {
|
||||
// The first wait should longer than following waits.
|
||||
SOLO.waitForText(text, 1, SHORT_WAIT_TIME);
|
||||
while (SOLO.waitForText(text, 1, 200)) {}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -190,19 +190,23 @@ public class MenuItemsTest extends ActivityInstrumentationTestCase2<TrackListAct
|
||||
public void testGPSMenu() {
|
||||
boolean GPSStatus = EndToEndTestUtils.findMenuItem(
|
||||
activityMyTracks.getString(R.string.menu_stop_gps), false);
|
||||
|
||||
|
||||
// Following starting/stopping or stopping/starting GPS.
|
||||
EndToEndTestUtils.findMenuItem(GPSStatus ? activityMyTracks.getString(R.string.menu_stop_gps)
|
||||
: activityMyTracks.getString(R.string.menu_start_gps), true);
|
||||
GPSStatus = !GPSStatus;
|
||||
assertEquals(GPSStatus, EndToEndTestUtils.findMenuItem(
|
||||
activityMyTracks.getString(R.string.menu_stop_gps), false));
|
||||
|
||||
EndToEndTestUtils.waitTextToDisappear(GPSStatus ? activityMyTracks
|
||||
.getString(R.string.menu_start_gps) : activityMyTracks.getString(R.string.menu_stop_gps));
|
||||
assertEquals(GPSStatus,
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_stop_gps), false));
|
||||
|
||||
EndToEndTestUtils.findMenuItem(GPSStatus ? activityMyTracks.getString(R.string.menu_stop_gps)
|
||||
: activityMyTracks.getString(R.string.menu_start_gps), true);
|
||||
GPSStatus = !GPSStatus;
|
||||
assertEquals(GPSStatus, EndToEndTestUtils.findMenuItem(
|
||||
activityMyTracks.getString(R.string.menu_stop_gps), false));
|
||||
EndToEndTestUtils.waitTextToDisappear(GPSStatus ? activityMyTracks
|
||||
.getString(R.string.menu_start_gps) : activityMyTracks.getString(R.string.menu_stop_gps));
|
||||
assertEquals(GPSStatus,
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_stop_gps), false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.google.android.apps.mytracks.endtoendtest.others;
|
||||
|
||||
public class BigTestUtils {
|
||||
|
||||
/**
|
||||
* Set to false as default. True to run the test. Default to false since this
|
||||
* test can take a long time.
|
||||
*/
|
||||
public static boolean runStressTest = true;
|
||||
public static boolean runSensorTest = true;
|
||||
|
||||
|
||||
protected static final String DISABLE_MESSAGE = "This test is disabled";
|
||||
|
||||
|
||||
}
|
||||
+161
-57
@@ -23,114 +23,218 @@ import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.util.Log;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests Connect to Sensors.
|
||||
* Tests connecting to sensors.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
/**
|
||||
* Set to false as default.
|
||||
*/
|
||||
public static boolean testSensor = false;
|
||||
|
||||
public SensorTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
public static final String DISABLE_MESSAGE = "This test is disabled";
|
||||
private TrackListActivity trackListActivity;
|
||||
private boolean runTest = false;
|
||||
private static final String ZEPHYR_NAME = "HXM";
|
||||
private static final String POLAR_NAME = "Polar";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
runTest = BigTestUtils.runSensorTest;
|
||||
super.setUp();
|
||||
if (!testSensor) {
|
||||
if (!runTest) {
|
||||
return;
|
||||
}
|
||||
instrumentation = getInstrumentation();
|
||||
activityMyTracks = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
||||
trackListActivity = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests connecting to a Zephyr Bluetooth sensor. Before this test, a Zephyr
|
||||
* sensor must has been paired with the device.
|
||||
* Tests connecting to a Zephyr Bluetooth sensor while not recording. Before this test, a Zephyr
|
||||
* sensor must be paired with the device.
|
||||
*/
|
||||
public void testConnectZephyrBluetoothSensor() {
|
||||
if (!testSensor) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE);
|
||||
public void testConnectZephyrBluetoothSensor_notRecording() {
|
||||
if (!runTest) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sensor));
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sensor_type));
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_sensor_type_zephyr));
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_sensor_bluetooth_sensor));
|
||||
assertTrue(getPairedSensorsNumber() > 0);
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
assertTrue(checkSensorsStatus());
|
||||
bluetoothSensorTest(R.string.settings_sensor_type_zephyr, ZEPHYR_NAME, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests connecting to a Polar Bluetooth sensor. Before this test, a Polar
|
||||
* sensor must has been paired with the device.
|
||||
* Tests connecting to a Zephyr Bluetooth sensor while under recording. Before this test, a Zephyr
|
||||
* sensor must be paired with the device.
|
||||
*/
|
||||
public void testConnectPolarBluetoothSensor() {
|
||||
if (!testSensor) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE);
|
||||
public void testConnectZephyrBluetoothSensor_underRecording() {
|
||||
if (!runTest) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sensor));
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sensor_type));
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_sensor_type_polar));
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
.getString(R.string.settings_sensor_bluetooth_sensor));
|
||||
assertTrue(getPairedSensorsNumber() > 0);
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
assertTrue(checkSensorsStatus());
|
||||
bluetoothSensorTest(R.string.settings_sensor_type_zephyr, ZEPHYR_NAME, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of paired sensors.
|
||||
* Tests connecting to a Polar Bluetooth sensor while not recording. Before this test, a Polar
|
||||
* sensor must be paired with the device.
|
||||
*/
|
||||
public void testConnectPolarBluetoothSensor_notRecording() {
|
||||
if (!runTest) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
bluetoothSensorTest(R.string.settings_sensor_type_polar, POLAR_NAME, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests connecting to a Polar Bluetooth sensor while under recording. Before this test, a Polar
|
||||
* sensor must be paired with the device.
|
||||
*/
|
||||
public void testConnectPolarBluetoothSensor_underRecording() {
|
||||
if (!runTest) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
bluetoothSensorTest(R.string.settings_sensor_type_polar, POLAR_NAME, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the paired sensor.
|
||||
*
|
||||
* @return the number of paired sensors
|
||||
* @param sensorTypeStringId the string id of paired sensors type
|
||||
* @param nameString part of the sensor name string which can distinguish
|
||||
* different Bluetooth sensors
|
||||
* @param isUnderRecording true means test under recording
|
||||
*/
|
||||
private int getPairedSensorsNumber() {
|
||||
private void bluetoothSensorTest(int sensorTypeStringId, String nameString,
|
||||
boolean isUnderRecording) {
|
||||
EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_settings), true);
|
||||
EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(R.string.settings_sensor));
|
||||
EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(R.string.settings_sensor_type));
|
||||
EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(sensorTypeStringId));
|
||||
checkPairedSensorsNumber(nameString);
|
||||
// Set the paired sensor.
|
||||
EndToEndTestUtils.SOLO.clickOnText(nameString);
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
if (isUnderRecording) {
|
||||
assertTrue(checkSensorsStatus_underRecording());
|
||||
} else {
|
||||
assertTrue(checkSensorsStatus_notRecording());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the number of paired sensors.
|
||||
*/
|
||||
private void checkPairedSensorsNumber(String nameString) {
|
||||
EndToEndTestUtils.SOLO.clickOnText(trackListActivity
|
||||
.getString(R.string.settings_sensor_bluetooth_sensor));
|
||||
instrumentation.waitForIdleSync();
|
||||
ArrayList<ListView> allListViews = EndToEndTestUtils.SOLO.getCurrentListViews();
|
||||
int number = allListViews.get(0).getCount();
|
||||
return number;
|
||||
if (number > 0
|
||||
&& EndToEndTestUtils.SOLO.waitForText(nameString, 1, EndToEndTestUtils.SHORT_WAIT_TIME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, "No sensor is paried");
|
||||
fail("No bluetooth sensor is paired. Please pair at Settings->Bluetooth before running the test.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the sensor is connected with MyTracks.
|
||||
* Tests connecting to a cadence ANT+ sensor.
|
||||
*/
|
||||
public void testConnectANTSensor_Cadence() {
|
||||
if (!runTest) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
useANTSeonsor();
|
||||
assertTrue(checkSensorsStatus_notRecording());
|
||||
checkANTSensorsStatus(R.id.sensor_state_cadence);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests connecting to cadence and heart rate ANT+ sensors at the same time.
|
||||
*/
|
||||
public void testConnectTwoANTSensors() {
|
||||
if (!runTest) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
useANTSeonsor();
|
||||
assertTrue(checkSensorsStatus_notRecording());
|
||||
checkANTSensorsStatus(R.id.sensor_state_cadence);
|
||||
checkANTSensorsStatus(R.id.sensor_state_heart_rate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the setting to use ANT+ sensor
|
||||
*/
|
||||
private void useANTSeonsor() {
|
||||
EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_settings), true);
|
||||
EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(R.string.settings_sensor));
|
||||
EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(R.string.settings_sensor_type));
|
||||
EndToEndTestUtils.SOLO.clickOnText(trackListActivity
|
||||
.getString(R.string.settings_sensor_type_ant));
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the ANT+ sensor is connected with MyTracks.
|
||||
*
|
||||
* @param viewID the id to check which is not equal with None
|
||||
*/
|
||||
private void checkANTSensorsStatus(int viewID) {
|
||||
TextView sensorValueText = ((TextView) EndToEndTestUtils.SOLO.getCurrentActivity()
|
||||
.findViewById(viewID));
|
||||
assertNotNull(sensorValueText);
|
||||
String realValue = sensorValueText.getText().toString();
|
||||
String noneValue = trackListActivity.getString(R.string.settings_sensor_type_none);
|
||||
assertNotSame(realValue, noneValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the sensor is connected with MyTracks during recording.
|
||||
*
|
||||
* @return true means the sensor is connected with MyTracks
|
||||
*/
|
||||
private boolean checkSensorsStatus() {
|
||||
private boolean checkSensorsStatus_underRecording() {
|
||||
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.startRecording();
|
||||
EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_sensor_state), true);
|
||||
boolean result = EndToEndTestUtils.SOLO.waitForText(
|
||||
trackListActivity.getString(R.string.sensor_state_connected), 1,
|
||||
EndToEndTestUtils.LONG_WAIT_TIME);
|
||||
EndToEndTestUtils.stopRecording(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the sensor is connected with MyTracks while not under recording.
|
||||
*
|
||||
* @return true means the sensor is connected with MyTracks
|
||||
*/
|
||||
private boolean checkSensorsStatus_notRecording() {
|
||||
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.createTrackIfEmpty(0, false);
|
||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_sensor_state), true);
|
||||
EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_sensor_state), true);
|
||||
return EndToEndTestUtils.SOLO.waitForText(
|
||||
activityMyTracks.getString(R.string.sensor_state_connected), 1,
|
||||
EndToEndTestUtils.NORMAL_WAIT_TIME);
|
||||
trackListActivity.getString(R.string.sensor_state_connected), 1,
|
||||
EndToEndTestUtils.LONG_WAIT_TIME);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (!testSensor) {
|
||||
if (!runTest) {
|
||||
return;
|
||||
}
|
||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||
|
||||
+75
-42
@@ -24,58 +24,58 @@ import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Tests Rotation of MyTracks.
|
||||
* Stress test of MyTracks.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||
|
||||
/**
|
||||
* Set to false as default.
|
||||
*/
|
||||
public static boolean testStress = false;
|
||||
public static final int MINUTES_FOR_EACH_TEST = 30;
|
||||
public static final int MILLI_SECOND_IN_ONE_MINUTE = 60 * 1000;
|
||||
long startTime = 0;
|
||||
int trackNumber;
|
||||
private static final int TEST_DURATION_IN_MILLISECONDS = 30 * 60 * 1000;
|
||||
private static final int MAX_TRACK_NUMBER = 30;
|
||||
private boolean runTest = false;
|
||||
|
||||
private long startTime = 0;
|
||||
private int numberOfTracks;
|
||||
|
||||
public StressTest() {
|
||||
super(TrackListActivity.class);
|
||||
}
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private TrackListActivity activityMyTracks;
|
||||
private TrackListActivity trackListActivity;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
runTest = BigTestUtils.runStressTest;
|
||||
super.setUp();
|
||||
if (!testStress) {
|
||||
if (!runTest) {
|
||||
return;
|
||||
}
|
||||
instrumentation = getInstrumentation();
|
||||
activityMyTracks = getActivity();
|
||||
EndToEndTestUtils.setupForDebug(instrumentation, activityMyTracks);
|
||||
trackListActivity = getActivity();
|
||||
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
|
||||
startTime = System.currentTimeMillis();
|
||||
EndToEndTestUtils.emulatorPort = 5568;
|
||||
}
|
||||
|
||||
/**
|
||||
* Records tracks and delete them when there are more than 30 tracks..
|
||||
* Records tracks and deletes them when there are more than
|
||||
* {@link #MAX_TRACK_NUMBER} tracks. Keeps sending different GPS locations in
|
||||
* each track, making it closer to the real stress.
|
||||
*/
|
||||
public void testRecordAndDeleteTracks() {
|
||||
if (!testStress) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, SensorTest.DISABLE_MESSAGE);
|
||||
if (!runTest) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; (System.currentTimeMillis() - startTime) / MILLI_SECOND_IN_ONE_MINUTE < MINUTES_FOR_EACH_TEST; i++) {
|
||||
for (int i = 0; (System.currentTimeMillis() - startTime) < TEST_DURATION_IN_MILLISECONDS; i++) {
|
||||
EndToEndTestUtils.startRecording();
|
||||
// Points in a tracks keep increasing.
|
||||
EndToEndTestUtils.sendGps(i * 10, 0, 10);
|
||||
EndToEndTestUtils.stopRecording(true);
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
||||
trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount();
|
||||
if (trackNumber > 30) {
|
||||
numberOfTracks = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount();
|
||||
if (numberOfTracks > MAX_TRACK_NUMBER) {
|
||||
EndToEndTestUtils.deleteAllTracks();
|
||||
}
|
||||
logStatus(i);
|
||||
@@ -83,55 +83,88 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates screen when display map view.
|
||||
* Rotates screen when display map view. Keeps sending different GPS locations
|
||||
* in each track, making it closer to the real stress.
|
||||
*/
|
||||
public void testRotateMapViewInTrackDetailActivity() {
|
||||
if (!testStress) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, SensorTest.DISABLE_MESSAGE);
|
||||
if (!runTest) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
EndToEndTestUtils.startRecording();
|
||||
for (int i = 0; (System.currentTimeMillis() - startTime) / MILLI_SECOND_IN_ONE_MINUTE < MINUTES_FOR_EACH_TEST; i++) {
|
||||
for (int i = 0; (System.currentTimeMillis() - startTime) < TEST_DURATION_IN_MILLISECONDS; i++) {
|
||||
EndToEndTestUtils.sendGps(10, i * 10);
|
||||
EndToEndTestUtils.rotateCurrentActivity();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches view between CHART, MAP and STAT.
|
||||
* Switches view between MAP, CHART and STAT.
|
||||
*/
|
||||
public void testSwitchTabs() {
|
||||
if (!testStress) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, SensorTest.DISABLE_MESSAGE);
|
||||
if (!runTest) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
EndToEndTestUtils.startRecording();
|
||||
int i = 0;
|
||||
while ((System.currentTimeMillis() - startTime) / MILLI_SECOND_IN_ONE_MINUTE < MINUTES_FOR_EACH_TEST) {
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_map_tab));
|
||||
while ((System.currentTimeMillis() - startTime) < TEST_DURATION_IN_MILLISECONDS) {
|
||||
EndToEndTestUtils.SOLO
|
||||
.clickOnText(trackListActivity.getString(R.string.track_detail_map_tab));
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
EndToEndTestUtils.SOLO.clickOnText(trackListActivity
|
||||
.getString(R.string.track_detail_chart_tab));
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
||||
EndToEndTestUtils.SOLO.clickOnText(trackListActivity
|
||||
.getString(R.string.track_detail_stats_tab));
|
||||
instrumentation.waitForIdleSync();
|
||||
logStatus(++i);
|
||||
}
|
||||
EndToEndTestUtils.stopRecording(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays log message.
|
||||
*
|
||||
* @param times this test has been run
|
||||
* Switches view between MAP, CHART and STAT. And create way points, pause and
|
||||
* resume the track during recording.
|
||||
*/
|
||||
private void logStatus(int times) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, "This test has run "
|
||||
+ times
|
||||
+ " times and will be finished in "
|
||||
+ (MINUTES_FOR_EACH_TEST - (System.currentTimeMillis() - startTime)
|
||||
/ MILLI_SECOND_IN_ONE_MINUTE) + " minutes!");
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, "There are " + trackNumber + " tracks!");
|
||||
public void testSwitchTabs_wayPoints() {
|
||||
if (!runTest) {
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
EndToEndTestUtils.startRecording();
|
||||
|
||||
int i = 0;
|
||||
while ((System.currentTimeMillis() - startTime) < TEST_DURATION_IN_MILLISECONDS) {
|
||||
// Create one way points.
|
||||
EndToEndTestUtils.sendGps(10, 10 * i);
|
||||
EndToEndTestUtils.createWaypoint(i);
|
||||
EndToEndTestUtils.pauseRecording();
|
||||
|
||||
EndToEndTestUtils.SOLO
|
||||
.clickOnText(trackListActivity.getString(R.string.track_detail_map_tab));
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.SOLO.clickOnText(trackListActivity
|
||||
.getString(R.string.track_detail_chart_tab));
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.SOLO.clickOnText(trackListActivity
|
||||
.getString(R.string.track_detail_stats_tab));
|
||||
instrumentation.waitForIdleSync();
|
||||
EndToEndTestUtils.resumeRecording();
|
||||
logStatus(++i);
|
||||
}
|
||||
EndToEndTestUtils.stopRecording(true);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Logs status.
|
||||
*
|
||||
* @param times the number of times this test has been run
|
||||
*/
|
||||
private void logStatus(int times) {
|
||||
int minutes = (int) (TEST_DURATION_IN_MILLISECONDS - (System.currentTimeMillis() - startTime)) / 60 / 1000;
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, String.format(
|
||||
"This test has run %d times and will be finished in %d minutes!", times, minutes));
|
||||
Log.i(EndToEndTestUtils.LOG_TAG, String.format("There are %d tracks!", numberOfTracks));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user