forked from upstream-mirrors/OpenTracks
merge heads
This commit is contained in:
+1
-19
@@ -32,7 +32,6 @@ import java.util.ArrayList;
|
|||||||
*/
|
*/
|
||||||
public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||||
|
|
||||||
private static final String WAYPOINT_NAME = "testWaypoint";
|
|
||||||
private Instrumentation instrumentation;
|
private Instrumentation instrumentation;
|
||||||
private TrackListActivity activityMyTracks;
|
private TrackListActivity activityMyTracks;
|
||||||
|
|
||||||
@@ -126,7 +125,7 @@ public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListA
|
|||||||
.getString(R.string.generic_recording)));
|
.getString(R.string.generic_recording)));
|
||||||
}
|
}
|
||||||
|
|
||||||
createWaypoint();
|
EndToEndTestUtils.createWaypoint(0);
|
||||||
EndToEndTestUtils.sendGps(2, 2);
|
EndToEndTestUtils.sendGps(2, 2);
|
||||||
// Back to tracks list.
|
// Back to tracks list.
|
||||||
EndToEndTestUtils.SOLO.goBack();
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
@@ -207,23 +206,6 @@ public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListA
|
|||||||
EndToEndTestUtils.stopRecording(true);
|
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
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||||
|
|||||||
+29
-5
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.apps.mytracks.endtoendtest;
|
package com.google.android.apps.mytracks.endtoendtest;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.endtoendtest.others.BigTestUtils;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.test.InstrumentationTestRunner;
|
import android.test.InstrumentationTestRunner;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -31,12 +33,34 @@ public class EndToEndTestRunner extends InstrumentationTestRunner {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle arguments) {
|
public void onCreate(Bundle arguments) {
|
||||||
try {
|
String portNumber = arguments.getString("port");
|
||||||
EndToEndTestUtils.emulatorPort = Integer.parseInt(arguments.getString("port"));
|
if (portNumber != null) {
|
||||||
} catch (Exception e) {
|
try {
|
||||||
Log.e(EndToEndTestUtils.LOG_TAG, "Unable to get port parameter, use default value." + EndToEndTestUtils.emulatorPort, e);
|
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);
|
super.onCreate(arguments);
|
||||||
}
|
}
|
||||||
|
|||||||
+65
-11
@@ -56,7 +56,7 @@ public class EndToEndTestUtils {
|
|||||||
|
|
||||||
private static final String ANDROID_LOCAL_IP = "10.0.2.2";
|
private static final String ANDROID_LOCAL_IP = "10.0.2.2";
|
||||||
// usually 5554.
|
// usually 5554.
|
||||||
public static int emulatorPort = 5554;
|
public static int emulatorPort = 5558;
|
||||||
|
|
||||||
private static final int ORIENTATION_PORTRAIT = 1;
|
private static final int ORIENTATION_PORTRAIT = 1;
|
||||||
private static final int ORIENTATION_LANDSCAPE = 0;
|
private static final int ORIENTATION_LANDSCAPE = 0;
|
||||||
@@ -66,9 +66,12 @@ public class EndToEndTestUtils {
|
|||||||
static final double START_LATITUDE = -1.3f;
|
static final double START_LATITUDE = -1.3f;
|
||||||
static final double DELTA_LONGITUDE = 0.0005f;
|
static final double DELTA_LONGITUDE = 0.0005f;
|
||||||
static final double DELTA_LADITUDE = 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 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 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";
|
static final String DEFAULTACTIVITYTYPE = "TestActivity";
|
||||||
public static String activityType = DEFAULTACTIVITYTYPE;
|
public static String activityType = DEFAULTACTIVITYTYPE;
|
||||||
@@ -248,6 +251,9 @@ public class EndToEndTestUtils {
|
|||||||
EndToEndTestUtils.instrumentation = instrumentation;
|
EndToEndTestUtils.instrumentation = instrumentation;
|
||||||
EndToEndTestUtils.activityMytracks = activityMyTracks;
|
EndToEndTestUtils.activityMytracks = activityMyTracks;
|
||||||
SOLO = new Solo(EndToEndTestUtils.instrumentation, EndToEndTestUtils.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");
|
Log.e(LOG_TAG, "Need update Google Play Services");
|
||||||
}
|
}
|
||||||
setIsEmulator();
|
setIsEmulator();
|
||||||
if ((getButtonOnScreen(EndToEndTestUtils.activityMytracks.getString(R.string.eula_accept),
|
if ((getButtonOnScreen(activityMytracks.getString(R.string.eula_accept),
|
||||||
false, false) != null)) {
|
false, false) != null)) {
|
||||||
verifyFirstLaunch();
|
verifyFirstLaunch();
|
||||||
} else if (SOLO.waitForText(
|
} else if (SOLO.waitForText(
|
||||||
@@ -297,7 +303,7 @@ public class EndToEndTestUtils {
|
|||||||
if (!isEmulator) {
|
if (!isEmulator) {
|
||||||
GoToMyLocationTest.findAndClickMyLocation(activityMyTracks);
|
GoToMyLocationTest.findAndClickMyLocation(activityMyTracks);
|
||||||
hasGpsSingal = !SOLO.waitForText(NO_GPS_MESSAGE_PREFIX, 1,
|
hasGpsSingal = !SOLO.waitForText(NO_GPS_MESSAGE_PREFIX, 1,
|
||||||
EndToEndTestUtils.SHORT_WAIT_TIME);
|
SHORT_WAIT_TIME);
|
||||||
SOLO.goBack();
|
SOLO.goBack();
|
||||||
}
|
}
|
||||||
} else if (SOLO.waitForText(
|
} else if (SOLO.waitForText(
|
||||||
@@ -663,8 +669,8 @@ public class EndToEndTestUtils {
|
|||||||
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
if (SOLO.searchText(menuName, 1, true)) {
|
if (SOLO.searchText(menuName, 1, true)) {
|
||||||
findResult = true;
|
findResult = true;
|
||||||
} else if (SOLO.searchText(MENU_MORE, 1, true)) {
|
} else if (getMoreOptionView() != null) {
|
||||||
SOLO.clickOnText(MENU_MORE);
|
SOLO.clickOnView(getMoreOptionView());
|
||||||
findResult = SOLO.searchText(menuName, 1, true);
|
findResult = SOLO.searchText(menuName, 1, true);
|
||||||
isMoreMenuOpened = true;
|
isMoreMenuOpened = true;
|
||||||
}
|
}
|
||||||
@@ -728,18 +734,30 @@ public class EndToEndTestUtils {
|
|||||||
* Finds the more option menu. It should match following conditions:
|
* Finds the more option menu. It should match following conditions:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>The view extends ImageButton.</li>
|
* <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>
|
* </ul>
|
||||||
* @return the more option view. Null means can not find it.
|
* @return the more option view. Null means can not find it.
|
||||||
*/
|
*/
|
||||||
private static View getMoreOptionView() {
|
private static View getMoreOptionView() {
|
||||||
ArrayList<View> allViews = SOLO.getViews();
|
View viewResult = null;
|
||||||
for (View view : allViews) {
|
if (hasActionBar) {
|
||||||
if (view instanceof ImageButton && view.getClass().getName().equals(MOREOPTION_CLASSNAME)) {
|
ArrayList<View> allViews = SOLO.getViews();
|
||||||
return view;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -922,4 +940,40 @@ public class EndToEndTestUtils {
|
|||||||
Assert.assertTrue(totalTimeOld.equalsIgnoreCase(totalTimeNew));
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -195,14 +195,18 @@ public class MenuItemsTest extends ActivityInstrumentationTestCase2<TrackListAct
|
|||||||
EndToEndTestUtils.findMenuItem(GPSStatus ? activityMyTracks.getString(R.string.menu_stop_gps)
|
EndToEndTestUtils.findMenuItem(GPSStatus ? activityMyTracks.getString(R.string.menu_stop_gps)
|
||||||
: activityMyTracks.getString(R.string.menu_start_gps), true);
|
: activityMyTracks.getString(R.string.menu_start_gps), true);
|
||||||
GPSStatus = !GPSStatus;
|
GPSStatus = !GPSStatus;
|
||||||
assertEquals(GPSStatus, EndToEndTestUtils.findMenuItem(
|
EndToEndTestUtils.waitTextToDisappear(GPSStatus ? activityMyTracks
|
||||||
activityMyTracks.getString(R.string.menu_stop_gps), false));
|
.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)
|
EndToEndTestUtils.findMenuItem(GPSStatus ? activityMyTracks.getString(R.string.menu_stop_gps)
|
||||||
: activityMyTracks.getString(R.string.menu_start_gps), true);
|
: activityMyTracks.getString(R.string.menu_start_gps), true);
|
||||||
GPSStatus = !GPSStatus;
|
GPSStatus = !GPSStatus;
|
||||||
assertEquals(GPSStatus, EndToEndTestUtils.findMenuItem(
|
EndToEndTestUtils.waitTextToDisappear(GPSStatus ? activityMyTracks
|
||||||
activityMyTracks.getString(R.string.menu_stop_gps), false));
|
.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
|
@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";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+159
-55
@@ -23,114 +23,218 @@ import android.app.Instrumentation;
|
|||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Connect to Sensors.
|
* Tests connecting to sensors.
|
||||||
*
|
*
|
||||||
* @author Youtao Liu
|
* @author Youtao Liu
|
||||||
*/
|
*/
|
||||||
public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||||
|
|
||||||
/**
|
|
||||||
* Set to false as default.
|
|
||||||
*/
|
|
||||||
public static boolean testSensor = false;
|
|
||||||
|
|
||||||
public SensorTest() {
|
public SensorTest() {
|
||||||
super(TrackListActivity.class);
|
super(TrackListActivity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Instrumentation instrumentation;
|
private Instrumentation instrumentation;
|
||||||
private TrackListActivity activityMyTracks;
|
private TrackListActivity trackListActivity;
|
||||||
public static final String DISABLE_MESSAGE = "This test is disabled";
|
private boolean runTest = false;
|
||||||
|
private static final String ZEPHYR_NAME = "HXM";
|
||||||
|
private static final String POLAR_NAME = "Polar";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
runTest = BigTestUtils.runSensorTest;
|
||||||
super.setUp();
|
super.setUp();
|
||||||
if (!testSensor) {
|
if (!runTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
instrumentation = getInstrumentation();
|
instrumentation = getInstrumentation();
|
||||||
activityMyTracks = getActivity();
|
trackListActivity = getActivity();
|
||||||
EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks);
|
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests connecting to a Zephyr Bluetooth sensor. Before this test, a Zephyr
|
* Tests connecting to a Zephyr Bluetooth sensor while not recording. Before this test, a Zephyr
|
||||||
* sensor must has been paired with the device.
|
* sensor must be paired with the device.
|
||||||
*/
|
*/
|
||||||
public void testConnectZephyrBluetoothSensor() {
|
public void testConnectZephyrBluetoothSensor_notRecording() {
|
||||||
if (!testSensor) {
|
if (!runTest) {
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE);
|
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
bluetoothSensorTest(R.string.settings_sensor_type_zephyr, ZEPHYR_NAME, false);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests connecting to a Polar Bluetooth sensor. Before this test, a Polar
|
* Tests connecting to a Zephyr Bluetooth sensor while under recording. Before this test, a Zephyr
|
||||||
* sensor must has been paired with the device.
|
* sensor must be paired with the device.
|
||||||
*/
|
*/
|
||||||
public void testConnectPolarBluetoothSensor() {
|
public void testConnectZephyrBluetoothSensor_underRecording() {
|
||||||
if (!testSensor) {
|
if (!runTest) {
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE);
|
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
bluetoothSensorTest(R.string.settings_sensor_type_zephyr, ZEPHYR_NAME, 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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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();
|
ArrayList<ListView> allListViews = EndToEndTestUtils.SOLO.getCurrentListViews();
|
||||||
int number = allListViews.get(0).getCount();
|
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
|
* @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.instrumentation.waitForIdleSync();
|
||||||
EndToEndTestUtils.createTrackIfEmpty(0, false);
|
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(
|
return EndToEndTestUtils.SOLO.waitForText(
|
||||||
activityMyTracks.getString(R.string.sensor_state_connected), 1,
|
trackListActivity.getString(R.string.sensor_state_connected), 1,
|
||||||
EndToEndTestUtils.NORMAL_WAIT_TIME);
|
EndToEndTestUtils.LONG_WAIT_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
if (!testSensor) {
|
if (!runTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
EndToEndTestUtils.SOLO.finishOpenedActivities();
|
||||||
|
|||||||
+74
-41
@@ -24,58 +24,58 @@ import android.test.ActivityInstrumentationTestCase2;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Rotation of MyTracks.
|
* Stress test of MyTracks.
|
||||||
*
|
*
|
||||||
* @author Youtao Liu
|
* @author Youtao Liu
|
||||||
*/
|
*/
|
||||||
public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
|
||||||
|
|
||||||
/**
|
private static final int TEST_DURATION_IN_MILLISECONDS = 30 * 60 * 1000;
|
||||||
* Set to false as default.
|
private static final int MAX_TRACK_NUMBER = 30;
|
||||||
*/
|
private boolean runTest = false;
|
||||||
public static boolean testStress = false;
|
|
||||||
public static final int MINUTES_FOR_EACH_TEST = 30;
|
private long startTime = 0;
|
||||||
public static final int MILLI_SECOND_IN_ONE_MINUTE = 60 * 1000;
|
private int numberOfTracks;
|
||||||
long startTime = 0;
|
|
||||||
int trackNumber;
|
|
||||||
|
|
||||||
public StressTest() {
|
public StressTest() {
|
||||||
super(TrackListActivity.class);
|
super(TrackListActivity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Instrumentation instrumentation;
|
private Instrumentation instrumentation;
|
||||||
private TrackListActivity activityMyTracks;
|
private TrackListActivity trackListActivity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
runTest = BigTestUtils.runStressTest;
|
||||||
super.setUp();
|
super.setUp();
|
||||||
if (!testStress) {
|
if (!runTest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
instrumentation = getInstrumentation();
|
instrumentation = getInstrumentation();
|
||||||
activityMyTracks = getActivity();
|
trackListActivity = getActivity();
|
||||||
EndToEndTestUtils.setupForDebug(instrumentation, activityMyTracks);
|
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
|
||||||
startTime = System.currentTimeMillis();
|
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() {
|
public void testRecordAndDeleteTracks() {
|
||||||
if (!testStress) {
|
if (!runTest) {
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, SensorTest.DISABLE_MESSAGE);
|
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||||
return;
|
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();
|
EndToEndTestUtils.startRecording();
|
||||||
// Points in a tracks keep increasing.
|
// Points in a tracks keep increasing.
|
||||||
EndToEndTestUtils.sendGps(i * 10, 0, 10);
|
EndToEndTestUtils.sendGps(i * 10, 0, 10);
|
||||||
EndToEndTestUtils.stopRecording(true);
|
EndToEndTestUtils.stopRecording(true);
|
||||||
EndToEndTestUtils.SOLO.goBack();
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
EndToEndTestUtils.instrumentation.waitForIdleSync();
|
||||||
trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount();
|
numberOfTracks = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount();
|
||||||
if (trackNumber > 30) {
|
if (numberOfTracks > MAX_TRACK_NUMBER) {
|
||||||
EndToEndTestUtils.deleteAllTracks();
|
EndToEndTestUtils.deleteAllTracks();
|
||||||
}
|
}
|
||||||
logStatus(i);
|
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() {
|
public void testRotateMapViewInTrackDetailActivity() {
|
||||||
if (!testStress) {
|
if (!runTest) {
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, SensorTest.DISABLE_MESSAGE);
|
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.startRecording();
|
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.sendGps(10, i * 10);
|
||||||
EndToEndTestUtils.rotateCurrentActivity();
|
EndToEndTestUtils.rotateCurrentActivity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switches view between CHART, MAP and STAT.
|
* Switches view between MAP, CHART and STAT.
|
||||||
*/
|
*/
|
||||||
public void testSwitchTabs() {
|
public void testSwitchTabs() {
|
||||||
if (!testStress) {
|
if (!runTest) {
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, SensorTest.DISABLE_MESSAGE);
|
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.startRecording();
|
EndToEndTestUtils.startRecording();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while ((System.currentTimeMillis() - startTime) / MILLI_SECOND_IN_ONE_MINUTE < MINUTES_FOR_EACH_TEST) {
|
while ((System.currentTimeMillis() - startTime) < TEST_DURATION_IN_MILLISECONDS) {
|
||||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_map_tab));
|
EndToEndTestUtils.SOLO
|
||||||
|
.clickOnText(trackListActivity.getString(R.string.track_detail_map_tab));
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
EndToEndTestUtils.SOLO.clickOnText(trackListActivity
|
||||||
.getString(R.string.track_detail_chart_tab));
|
.getString(R.string.track_detail_chart_tab));
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
EndToEndTestUtils.SOLO.clickOnText(trackListActivity
|
||||||
.getString(R.string.track_detail_stats_tab));
|
.getString(R.string.track_detail_stats_tab));
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
logStatus(++i);
|
logStatus(++i);
|
||||||
}
|
}
|
||||||
|
EndToEndTestUtils.stopRecording(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays log message.
|
* Switches view between MAP, CHART and STAT. And create way points, pause and
|
||||||
*
|
* resume the track during recording.
|
||||||
* @param times this test has been run
|
|
||||||
*/
|
*/
|
||||||
private void logStatus(int times) {
|
public void testSwitchTabs_wayPoints() {
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, "This test has run "
|
if (!runTest) {
|
||||||
+ times
|
Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE);
|
||||||
+ " times and will be finished in "
|
return;
|
||||||
+ (MINUTES_FOR_EACH_TEST - (System.currentTimeMillis() - startTime)
|
}
|
||||||
/ MILLI_SECOND_IN_ONE_MINUTE) + " minutes!");
|
EndToEndTestUtils.startRecording();
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, "There are " + trackNumber + " tracks!");
|
|
||||||
|
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