forked from upstream-mirrors/OpenTracks
Change code style. Add test case about ANT+ sensors.
This commit is contained in:
+101
-41
@@ -23,95 +23,155 @@ 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.
|
* Set to false as default. True to run the test. Default to false since this
|
||||||
|
* test can take a long time.
|
||||||
*/
|
*/
|
||||||
public static boolean testSensor = false;
|
public static boolean runTest = 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";
|
public static final String DISABLE_MESSAGE = "This test is disabled";
|
||||||
|
public static final String ZEPHYR_NAME = "HXM";
|
||||||
|
public static final String POLAR_NAME = "Polar";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
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. 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() {
|
||||||
if (!testSensor) {
|
if (!runTest) {
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE);
|
Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
bluetoothSensorTest(trackListActivity.getString(R.string.settings_sensor_type_zephyr), ZEPHYR_NAME);
|
||||||
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 Polar Bluetooth sensor. Before this test, a Polar
|
||||||
* sensor must has been paired with the device.
|
* sensor must be paired with the device.
|
||||||
*/
|
*/
|
||||||
public void testConnectPolarBluetoothSensor() {
|
public void testConnectPolarBluetoothSensor() {
|
||||||
if (!testSensor) {
|
if (!runTest) {
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE);
|
Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
|
bluetoothSensorTest(trackListActivity.getString(R.string.settings_sensor_type_polar), POLAR_NAME);
|
||||||
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));
|
* Set the paired sensor.
|
||||||
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
|
*
|
||||||
.getString(R.string.settings_sensor_bluetooth_sensor));
|
* @param sensorTypeString the type of paired sensors
|
||||||
assertTrue(getPairedSensorsNumber() > 0);
|
* @param nameString part of the sensor name string which can distinguish
|
||||||
EndToEndTestUtils.SOLO.goBack();
|
* different Bluetooth sensors.
|
||||||
|
*/
|
||||||
|
private void bluetoothSensorTest(String sensorTypeString, String nameString) {
|
||||||
|
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(sensorTypeString);
|
||||||
|
checkPairedSensorsNumber(nameString);
|
||||||
|
// Set the paired sensor.
|
||||||
|
EndToEndTestUtils.SOLO.clickOnText(nameString);
|
||||||
EndToEndTestUtils.SOLO.goBack();
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
EndToEndTestUtils.SOLO.goBack();
|
EndToEndTestUtils.SOLO.goBack();
|
||||||
assertTrue(checkSensorsStatus());
|
assertTrue(checkSensorsStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of paired sensors.
|
* Checks the number of paired sensors.
|
||||||
*
|
|
||||||
* @return the number of paired sensors
|
|
||||||
*/
|
*/
|
||||||
private int getPairedSensorsNumber() {
|
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;
|
||||||
|
}
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests connecting to a cadence ANT+ sensor.
|
||||||
|
*/
|
||||||
|
public void testConnectANTSensor_Cadence() {
|
||||||
|
if (!runTest) {
|
||||||
|
Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
useANTSeonsor();
|
||||||
|
assertTrue(checkSensorsStatus());
|
||||||
|
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, DISABLE_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
useANTSeonsor();
|
||||||
|
assertTrue(checkSensorsStatus());
|
||||||
|
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 the string to check which is not equal None
|
||||||
|
*/
|
||||||
|
private void checkANTSensorsStatus(int viewID) {
|
||||||
|
TextView sensorValue = ((TextView) EndToEndTestUtils.SOLO.getCurrentActivity().findViewById(
|
||||||
|
viewID));
|
||||||
|
assertNotNull(sensorValue);
|
||||||
|
String realValue = sensorValue.getText().toString();
|
||||||
|
String noneValue = trackListActivity.getString(R.string.settings_sensor_type_none);
|
||||||
|
assertEquals(-1, realValue.indexOf(noneValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,15 +182,15 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
|
|||||||
private boolean checkSensorsStatus() {
|
private boolean checkSensorsStatus() {
|
||||||
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();
|
||||||
|
|||||||
+36
-34
@@ -24,58 +24,61 @@ 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> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to false as default.
|
* Set to false as default. True to run the test. Default to false since this
|
||||||
|
* test can take a long time.
|
||||||
*/
|
*/
|
||||||
public static boolean testStress = false;
|
public static boolean runTest = true;
|
||||||
public static final int MINUTES_FOR_EACH_TEST = 30;
|
public static final int TEST_DURATION_IN_MILLISECONDS = 30 * 60 * 1000;
|
||||||
public static final int MILLI_SECOND_IN_ONE_MINUTE = 60 * 1000;
|
private static final int MAX_TRACK_NUMBER = 30;
|
||||||
long startTime = 0;
|
private long startTime = 0;
|
||||||
int trackNumber;
|
private int numberOfTracks;
|
||||||
|
|
||||||
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 {
|
||||||
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;
|
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, SensorTest.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,37 +86,39 @@ 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, SensorTest.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, SensorTest.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);
|
||||||
@@ -121,17 +126,14 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays log message.
|
* Logs status.
|
||||||
*
|
*
|
||||||
* @param times this test has been run
|
* @param times the number of times this test has been run
|
||||||
*/
|
*/
|
||||||
private void logStatus(int times) {
|
private void logStatus(int times) {
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, "This test has run "
|
Log.i(EndToEndTestUtils.LOG_TAG, String.format(
|
||||||
+ times
|
"This test has run d% times and will be finished in d% millis seconds!", times,
|
||||||
+ " times and will be finished in "
|
TEST_DURATION_IN_MILLISECONDS - (System.currentTimeMillis() - startTime)));
|
||||||
+ (MINUTES_FOR_EACH_TEST - (System.currentTimeMillis() - startTime)
|
Log.i(EndToEndTestUtils.LOG_TAG, String.format("There are %d tracks!", numberOfTracks));
|
||||||
/ MILLI_SECOND_IN_ONE_MINUTE) + " minutes!");
|
|
||||||
Log.i(EndToEndTestUtils.LOG_TAG, "There are " + trackNumber + " tracks!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user