forked from upstream-mirrors/OpenTracks
Change code style, remove useless method of MyTracksSmokeTest
This commit is contained in:
+50
-75
@@ -53,9 +53,10 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
private Instrumentation instrumentation;
|
private Instrumentation instrumentation;
|
||||||
private TrackListActivity activityMyTracks;
|
private TrackListActivity activityMyTracks;
|
||||||
private Solo solo;
|
private Solo solo;
|
||||||
private boolean checkFirstOpenFlag = false;
|
private boolean isFirstLaunch = false;
|
||||||
// Check whether the version of Android is ICS.
|
// Check whether the UI has an action bar which is related with the version of
|
||||||
private boolean ICSFlag = false;
|
// Android OS.
|
||||||
|
private boolean hasActionBar = false;
|
||||||
private String trackName;
|
private String trackName;
|
||||||
|
|
||||||
public MyTracksSmokeTest() {
|
public MyTracksSmokeTest() {
|
||||||
@@ -70,12 +71,12 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
solo = new Solo(instrumentation, activityMyTracks);
|
solo = new Solo(instrumentation, activityMyTracks);
|
||||||
// Checks if open MyTracks first time after install. If so, there would be a
|
// Checks if open MyTracks first time after install. If so, there would be a
|
||||||
// welcome view with accept buttons. And makes sure only check once.
|
// welcome view with accept buttons. And makes sure only check once.
|
||||||
if (checkFirstOpenFlag == false) {
|
if (!isFirstLaunch) {
|
||||||
if ((getButtonOnScreen(activityMyTracks.getString(R.string.eula_accept)) != null)) {
|
if ((getButtonOnScreen(activityMyTracks.getString(R.string.eula_accept)) != null)) {
|
||||||
verifyFirstLaunch();
|
verifyFirstLaunch();
|
||||||
}
|
}
|
||||||
setVersionOfOS();
|
setHasActionBar();
|
||||||
checkFirstOpenFlag = true;
|
isFirstLaunch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makes every track name is unique to make sure every check can be trusted.
|
// Makes every track name is unique to make sure every check can be trusted.
|
||||||
@@ -89,6 +90,9 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
*/
|
*/
|
||||||
public void testSwitchViewsAndMenusOfView() {
|
public void testSwitchViewsAndMenusOfView() {
|
||||||
createSimpleTrack(3);
|
createSimpleTrack(3);
|
||||||
|
|
||||||
|
solo.goBack();
|
||||||
|
solo.clickOnText(trackName);
|
||||||
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.track_detail_chart_tab));
|
solo.clickOnText(activityMyTracks.getString(R.string.track_detail_chart_tab));
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
@@ -126,8 +130,7 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
solo.clickOnText(activityMyTracks
|
solo.clickOnText(activityMyTracks.getString(R.string.send_google_send_now));
|
||||||
.getString(R.string.send_google_send_now));
|
|
||||||
assertTrue(solo.waitForText(activityMyTracks
|
assertTrue(solo.waitForText(activityMyTracks
|
||||||
.getString(R.string.send_google_no_service_selected)));
|
.getString(R.string.send_google_no_service_selected)));
|
||||||
// Stop here for do not really send.
|
// Stop here for do not really send.
|
||||||
@@ -138,7 +141,7 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
*/
|
*/
|
||||||
public void testSaveToSDCard_GPX() {
|
public void testSaveToSDCard_GPX() {
|
||||||
createSimpleTrack(0);
|
createSimpleTrack(0);
|
||||||
saveTrackToSDCard(GPX);
|
saveTrackToSdCard(GPX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,7 +149,7 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
*/
|
*/
|
||||||
public void testSaveToSDCard_KML() {
|
public void testSaveToSDCard_KML() {
|
||||||
createSimpleTrack(0);
|
createSimpleTrack(0);
|
||||||
saveTrackToSDCard(KML);
|
saveTrackToSdCard(KML);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,7 +157,7 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
*/
|
*/
|
||||||
public void testSaveToSDCard_CSV() {
|
public void testSaveToSDCard_CSV() {
|
||||||
createSimpleTrack(0);
|
createSimpleTrack(0);
|
||||||
saveTrackToSDCard(CSV);
|
saveTrackToSdCard(CSV);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,7 +165,7 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
*/
|
*/
|
||||||
public void testSaveToSDCard_TCX() {
|
public void testSaveToSDCard_TCX() {
|
||||||
createSimpleTrack(0);
|
createSimpleTrack(0);
|
||||||
saveTrackToSDCard(TCX);
|
saveTrackToSdCard(TCX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -249,6 +252,11 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
* Creates one track with a two locations, a way point and a statistics point.
|
* Creates one track with a two locations, a way point and a statistics point.
|
||||||
*/
|
*/
|
||||||
public void testCreateTrackWithMarkers() {
|
public void testCreateTrackWithMarkers() {
|
||||||
|
solo.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
|
findMenuItem(activityMyTracks.getString(R.string.menu_delete_all), true);
|
||||||
|
solo.clickOnButton(activityMyTracks.getString(R.string.generic_ok));
|
||||||
|
instrumentation.waitForIdleSync();
|
||||||
|
|
||||||
startRecording();
|
startRecording();
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
SmokeTestUtils.sendGps(2);
|
SmokeTestUtils.sendGps(2);
|
||||||
@@ -378,41 +386,27 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Switches to satellite mode if it's map mode now..
|
// Switches to satellite mode if it's map mode now..
|
||||||
if (isMapMode) {
|
solo.clickOnText(activityMyTracks.getString(isMapMode ? R.string.menu_satellite_mode
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.menu_satellite_mode));
|
: R.string.menu_map_mode));
|
||||||
} else {
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.menu_map_mode));
|
|
||||||
}
|
|
||||||
|
|
||||||
isMapMode = !isMapMode;
|
isMapMode = !isMapMode;
|
||||||
ArrayList<View> allViews = solo.getViews();
|
ArrayList<View> allViews = solo.getViews();
|
||||||
for (View view : allViews) {
|
for (View view : allViews) {
|
||||||
if (view instanceof MapView) {
|
if (view instanceof MapView) {
|
||||||
if (isMapMode) {
|
assertFalse(isMapMode ? ((MapView) view).isSatellite() : !(((MapView) view).isSatellite()));
|
||||||
assertFalse(((MapView) view).isSatellite());
|
|
||||||
} else {
|
|
||||||
assertTrue(((MapView) view).isSatellite());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
// Switches back.
|
// Switches back.
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
if (isMapMode) {
|
solo.clickOnText(activityMyTracks.getString(isMapMode ? R.string.menu_satellite_mode
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.menu_satellite_mode));
|
: R.string.menu_map_mode));
|
||||||
} else {
|
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.menu_map_mode));
|
|
||||||
}
|
|
||||||
isMapMode = !isMapMode;
|
isMapMode = !isMapMode;
|
||||||
allViews = solo.getViews();
|
allViews = solo.getViews();
|
||||||
for (View view : allViews) {
|
for (View view : allViews) {
|
||||||
if (view instanceof MapView) {
|
if (view instanceof MapView) {
|
||||||
if (isMapMode) {
|
assertFalse(isMapMode ? ((MapView) view).isSatellite() : !(((MapView) view).isSatellite()));
|
||||||
assertFalse(((MapView) view).isSatellite());
|
|
||||||
} else {
|
|
||||||
assertTrue(((MapView) view).isSatellite());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,23 +445,6 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
stopRecording(true);
|
stopRecording(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the long distance and more than 100000 points.
|
|
||||||
*/
|
|
||||||
public void testBigTrack() {
|
|
||||||
/*
|
|
||||||
* System.out.println(activityMyTracks.getString(R.string.
|
|
||||||
* announcement_frequency_key)); sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
* solo.clickOnText(activityMyTracks.getString(R.string.menu_record_track));
|
|
||||||
* SmokeTestUtils.PAUSE = 0; SmokeTestUtils.sendGps(120000);
|
|
||||||
* createWaypointAndStatistics(); SmokeTestUtils.sendGps(2);
|
|
||||||
* sendKeys(KeyEvent.KEYCODE_MENU);
|
|
||||||
* solo.clickOnText(activityMyTracks.getString
|
|
||||||
* (R.string.menu_stop_recording)); solo.enterText(0, trackName);
|
|
||||||
* solo.clickOnButton(activityMyTracks.getString(R.string.generic_save));
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a way point and a statistics during track recording.
|
* Creates a way point and a statistics during track recording.
|
||||||
*/
|
*/
|
||||||
@@ -512,7 +489,7 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
/**
|
/**
|
||||||
* Creates a simple track which can be used by subsequent test.
|
* Creates a simple track which can be used by subsequent test.
|
||||||
*
|
*
|
||||||
* @param numberOfGpsData number of simulated Gps data.
|
* @param numberOfGpsData number of simulated Gps data
|
||||||
*/
|
*/
|
||||||
private void createSimpleTrack(int numberOfGpsData) {
|
private void createSimpleTrack(int numberOfGpsData) {
|
||||||
startRecording();
|
startRecording();
|
||||||
@@ -524,13 +501,11 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
* Starts recoding track.
|
* Starts recoding track.
|
||||||
*/
|
*/
|
||||||
private void startRecording() {
|
private void startRecording() {
|
||||||
if (ICSFlag) {
|
if (hasActionBar) {
|
||||||
Button startButton = getButtonOnScreen(activityMyTracks.getString(R.string.menu_record_track));
|
Button startButton = getButtonOnScreen(activityMyTracks.getString(R.string.menu_record_track));
|
||||||
// In case a track is recording.
|
// In case a track is recording.
|
||||||
if (startButton == null) {
|
if (startButton == null) {
|
||||||
Button stopButton = getButtonOnScreen(activityMyTracks
|
stopRecording(true);
|
||||||
.getString(R.string.menu_stop_recording));
|
|
||||||
solo.clickOnView(stopButton);
|
|
||||||
startButton = getButtonOnScreen(activityMyTracks.getString(R.string.menu_record_track));
|
startButton = getButtonOnScreen(activityMyTracks.getString(R.string.menu_record_track));
|
||||||
}
|
}
|
||||||
solo.clickOnView(startButton);
|
solo.clickOnView(startButton);
|
||||||
@@ -542,7 +517,7 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
solo.goBack();
|
solo.goBack();
|
||||||
} else {
|
} else {
|
||||||
// In case a track is recording.
|
// In case a track is recording.
|
||||||
solo.clickOnText(activityMyTracks.getString(R.string.menu_stop_recording));
|
stopRecording(true);
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -552,13 +527,13 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop recoding track.
|
* Stops recoding track.
|
||||||
*
|
*
|
||||||
* @param isSave ture means should save this track.
|
* @param isSave ture means should save this track
|
||||||
*/
|
*/
|
||||||
private void stopRecording(boolean isSave) {
|
private void stopRecording(boolean isSave) {
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
if (ICSFlag) {
|
if (hasActionBar) {
|
||||||
solo.clickOnView(getButtonOnScreen(activityMyTracks.getString(R.string.menu_stop_recording)));
|
solo.clickOnView(getButtonOnScreen(activityMyTracks.getString(R.string.menu_stop_recording)));
|
||||||
} else {
|
} else {
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
@@ -566,6 +541,7 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
}
|
}
|
||||||
if (isSave) {
|
if (isSave) {
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
|
solo.enterText(0, trackName);
|
||||||
solo.clickLongOnText(activityMyTracks.getString(R.string.generic_save));
|
solo.clickLongOnText(activityMyTracks.getString(R.string.generic_save));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -596,19 +572,18 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
FileFilter filter = new FileFilter() {
|
FileFilter filter = new FileFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File pathname) {
|
public boolean accept(File pathname) {
|
||||||
if (pathname.getName().indexOf("." + trackKind) > 0) { return true; }
|
return pathname.getName().indexOf("." + trackKind) > 0;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return (new File(filePath)).listFiles(filter);
|
return (new File(filePath)).listFiles(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a track to a kind of file in SD card.
|
* Saves a track to a kind of file in SD card.
|
||||||
*
|
*
|
||||||
* @param trackKind the kind of track
|
* @param trackKind the kind of track
|
||||||
*/
|
*/
|
||||||
private void saveTrackToSDCard(String trackKind) {
|
private void saveTrackToSdCard(String trackKind) {
|
||||||
deleteExportedFiles(trackKind);
|
deleteExportedFiles(trackKind);
|
||||||
instrumentation.waitForIdleSync();
|
instrumentation.waitForIdleSync();
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
@@ -622,32 +597,34 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
/**
|
/**
|
||||||
* Checks if a button is existed in the screen.
|
* Checks if a button is existed in the screen.
|
||||||
*
|
*
|
||||||
* @param buttonName the name string of the button.
|
* @param buttonName the name string of the button
|
||||||
* @return the button to search, and null means can not find the button.
|
* @return the button to search, and null means can not find the button
|
||||||
*/
|
*/
|
||||||
private Button getButtonOnScreen(String buttonName) {
|
private Button getButtonOnScreen(String buttonName) {
|
||||||
ArrayList<Button> currentButtons = solo.getCurrentButtons();
|
ArrayList<Button> currentButtons = solo.getCurrentButtons();
|
||||||
Button resultButton = null;
|
|
||||||
for (Button button : currentButtons) {
|
for (Button button : currentButtons) {
|
||||||
if (((String) button.getText()).equalsIgnoreCase(buttonName)) { return button; }
|
if (((String) button.getText()).equalsIgnoreCase(buttonName)) {
|
||||||
|
return button;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return resultButton;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the version of Android is ICS.
|
* Checks whether an action bar is shown.
|
||||||
*/
|
*/
|
||||||
private void setVersionOfOS() {
|
private void setHasActionBar() {
|
||||||
// If can find record button without pressing Menu, it should be ICS.
|
// If can find record button without pressing Menu, it should be an action
|
||||||
|
// bar.
|
||||||
Button startButton = getButtonOnScreen(activityMyTracks.getString(R.string.menu_record_track));
|
Button startButton = getButtonOnScreen(activityMyTracks.getString(R.string.menu_record_track));
|
||||||
Button stopButton = getButtonOnScreen(activityMyTracks.getString(R.string.menu_stop_recording));
|
Button stopButton = getButtonOnScreen(activityMyTracks.getString(R.string.menu_stop_recording));
|
||||||
if (startButton != null || stopButton != null) {
|
if (startButton != null || stopButton != null) {
|
||||||
ICSFlag = true;
|
hasActionBar = true;
|
||||||
} else {
|
} else {
|
||||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||||
if (solo.searchText(activityMyTracks.getString(R.string.menu_record_track))
|
if (solo.searchText(activityMyTracks.getString(R.string.menu_record_track))
|
||||||
|| solo.searchText(activityMyTracks.getString(R.string.menu_stop_recording))) {
|
|| solo.searchText(activityMyTracks.getString(R.string.menu_stop_recording))) {
|
||||||
ICSFlag = false;
|
hasActionBar = false;
|
||||||
} else {
|
} else {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
@@ -656,7 +633,7 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find an item in the menu.
|
* Finds an item in the menu with the option to click the item.
|
||||||
*
|
*
|
||||||
* @param menuName the name of item
|
* @param menuName the name of item
|
||||||
* @param click true means need click this menu
|
* @param click true means need click this menu
|
||||||
@@ -669,8 +646,6 @@ public class MyTracksSmokeTest extends ActivityInstrumentationTestCase2<TrackLis
|
|||||||
} else if (solo.searchText(MENU_MORE)) {
|
} else if (solo.searchText(MENU_MORE)) {
|
||||||
solo.clickOnText(MENU_MORE);
|
solo.clickOnText(MENU_MORE);
|
||||||
findResult = solo.searchText(menuName);
|
findResult = solo.searchText(menuName);
|
||||||
} else {
|
|
||||||
findResult = false;
|
|
||||||
}
|
}
|
||||||
if (findResult && click) {
|
if (findResult && click) {
|
||||||
solo.clickOnText(menuName);
|
solo.clickOnText(menuName);
|
||||||
|
|||||||
@@ -37,33 +37,38 @@ public class SmokeTestUtils {
|
|||||||
private static final float DELTA_LADITUDE = 0.0005f;
|
private static final float DELTA_LADITUDE = 0.0005f;
|
||||||
|
|
||||||
private SmokeTestUtils() {}
|
private SmokeTestUtils() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends Gps data to emulator.
|
* Sends Gps data to emulator.
|
||||||
*
|
*
|
||||||
* @param number send times
|
* @param number send times
|
||||||
*/
|
*/
|
||||||
public static void sendGps(int number) {
|
public static void sendGps(int number) {
|
||||||
if (number < 1)
|
if (number < 1) return;
|
||||||
return;
|
PrintStream out = null;
|
||||||
try {
|
try {
|
||||||
Socket socket = new Socket(ANDROID_LOCAL_IP, ANDROID_LOCAL_PORT);
|
Socket socket = new Socket(ANDROID_LOCAL_IP, ANDROID_LOCAL_PORT);
|
||||||
PrintStream out = new PrintStream(socket.getOutputStream());
|
out = new PrintStream(socket.getOutputStream());
|
||||||
float longitude = START_LONGITUDE;
|
float longitude = START_LONGITUDE;
|
||||||
float latitude = START_LATITUDE;
|
float latitude = START_LATITUDE;
|
||||||
for (int i = 0; i < number; i++) {
|
for (int i = 0; i < number; i++) {
|
||||||
Thread.sleep(PAUSE);
|
Thread.sleep(PAUSE);
|
||||||
out.println("geo fix " + latitude + " " + longitude);
|
out.println("geo fix " + latitude + " " + longitude);
|
||||||
System.out.println("Number" +i + ":geo fix " + latitude + " " + longitude);
|
|
||||||
longitude += DELTA_LONGITUDE;
|
longitude += DELTA_LONGITUDE;
|
||||||
latitude += DELTA_LADITUDE;
|
latitude += DELTA_LADITUDE;
|
||||||
}
|
}
|
||||||
|
out.close();
|
||||||
|
socket.close();
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
|
} finally {
|
||||||
|
if (out != null) {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user