Add test case to check whether track/marker properties can be exported and imported.

This commit is contained in:
youtaol
2013-01-05 15:07:14 +08:00
parent e6b67d941e
commit 3eb2d1afc9
3 changed files with 104 additions and 26 deletions
@@ -117,7 +117,7 @@ public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListA
public void testCreateTrackWithMarkers() {
EndToEndTestUtils.startRecording();
instrumentation.waitForIdleSync();
// Send Gps before send marker.
// Send Gps before creating marker.
EndToEndTestUtils.sendGps(2);
if (EndToEndTestUtils.hasActionBar) {
// Check the title is Recording.
@@ -56,7 +56,7 @@ public class EndToEndTestUtils {
private static final String ANDROID_LOCAL_IP = "10.0.2.2";
// usually 5554.
public static int emulatorPort = 5568;
public static int emulatorPort = 5556;
private static final int ORIENTATION_PORTRAIT = 1;
private static final int ORIENTATION_LANDSCAPE = 0;
@@ -65,7 +65,9 @@ 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";
static final String WAYPOINT_NAME = "testWaypoint";
static final String WAYPOINT_TYPE = "testWaypoinType";
static final String WAYPOINT_DESC = "testWaypointDesc";
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";
@@ -73,14 +75,16 @@ public class EndToEndTestUtils {
static final String DEFAULTACTIVITYTYPE = "TestActivity";
public static String activityType = DEFAULTACTIVITYTYPE;
static String trackName;
static final String TRACK_NAME_PREFIX = "testTrackName";
static String trackDesc;
static final String TRACK_DESC_PREFIX = "testTrackDesc";
static final String GPX = "gpx";
static final String KML = "kml";
static final String CSV = "csv";
static final String TCX = "tcx";
static final String BACKUPS = "backups";
static final String MENU_MORE = "More";
static String trackName;
// Following is some check strings in English and Chinese
private static final HashMap<String, String> RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL = new HashMap<String, String>();
@@ -484,10 +488,13 @@ public class EndToEndTestUtils {
SOLO.waitForText(activityMytracks.getString(R.string.generic_save), 1, 5000);
// Make every track name is unique to make sure every check can be
// trusted.
trackName = TRACK_NAME_PREFIX + System.currentTimeMillis();
long currentMillis = System.currentTimeMillis();
trackName = TRACK_NAME_PREFIX + currentMillis;
trackDesc = TRACK_DESC_PREFIX + currentMillis;
SOLO.sendKey(KeyEvent.KEYCODE_DEL);
enterTextAvoidSoftKeyBoard(0, trackName);
enterTextAvoidSoftKeyBoard(1, activityType);
enterTextAvoidSoftKeyBoard(2, trackDesc);
SOLO.clickOnText(activityMytracks.getString(R.string.generic_save));
instrumentation.waitForIdleSync();
}
@@ -647,6 +654,7 @@ public class EndToEndTestUtils {
* @return true if find this menu
*/
public static boolean findMenuItem(String menuName, boolean click) {
instrumentation.waitForIdleSync();
boolean findResult = false;
boolean isMoreMenuOpened = false;
@@ -663,7 +671,7 @@ public class EndToEndTestUtils {
return findResult;
}
showMenuItem();
findResult = SOLO.searchText(menuName, 1, true);
findResult = SOLO.waitForText(menuName, 1, NORMAL_WAIT_TIME, true);
} else {
// Non-ICS phone.
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
@@ -961,7 +969,9 @@ public class EndToEndTestUtils {
.getString(R.string.marker_list_empty_message)));
}
findMenuItem(activityMytracks.getString(R.string.menu_insert_marker), true);
enterTextAvoidSoftKeyBoard(0, WAYPOINT_NAME);
enterTextAvoidSoftKeyBoard(0, WAYPOINT_NAME + (markerNumber + 1));
enterTextAvoidSoftKeyBoard(1, WAYPOINT_TYPE + (markerNumber + 1));
enterTextAvoidSoftKeyBoard(2, WAYPOINT_DESC + (markerNumber + 1));
SOLO.clickOnButton(activityMytracks.getString(R.string.generic_add));
instrumentation.waitForIdleSync();
if (hasGpsSingal) {
@@ -47,7 +47,7 @@ public class ExportAndImportTest extends ActivityInstrumentationTestCase2<TrackL
}
/**
* Tests export and import tracks after creating a track with Gps signal and
* Tests export and import tracks after creating a track with Gps signal and
* an empty track.
*/
public void testExportAndImportTracks() {
@@ -59,18 +59,84 @@ public class ExportAndImportTest extends ActivityInstrumentationTestCase2<TrackL
instrumentation.waitForIdleSync();
checkExportAndImport();
}
/**
* Tests export and import tracks after creating a track with Gps signal and
* Tests export and import track. Then check the properties of this track.
*/
public void testExportAndImportTrack_properties() {
EndToEndTestUtils.deleteAllTracks();
// Create a new track with two markers.
EndToEndTestUtils.startRecording();
instrumentation.waitForIdleSync();
// Send Gps before creating marker.
EndToEndTestUtils.sendGps(2);
EndToEndTestUtils.createWaypoint(0);
EndToEndTestUtils.sendGps(2, 2);
EndToEndTestUtils.createWaypoint(1);
EndToEndTestUtils.sendGps(2, 4);
// Back to tracks list.
EndToEndTestUtils.SOLO.goBack();
instrumentation.waitForIdleSync();
EndToEndTestUtils.stopRecording(true);
// Export this track and then delete it.
EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.GPX);
// Click to export tracks(At least one track) to Gpx files.
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_save_all), true);
EndToEndTestUtils.SOLO
.clickOnText(String.format(activityMyTracks.getString(R.string.menu_save_format),
EndToEndTestUtils.GPX.toUpperCase()));
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.external_storage_save_success));
EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
EndToEndTestUtils.deleteAllTracks();
// Import this tracks.
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_import), true);
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(
R.string.external_storage_import_success_count).split("%")[0]);
// Check import tracks should be equal with the sum of trackNumber and
// gpxFilesNumber;
EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
instrumentation.waitForIdleSync();
// Check the track name, activity and description.
assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.trackName));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.trackName);
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_edit), true);
instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackName));
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.activityType));
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackDesc));
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_cancel));
// Check the markers.
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_markers), true);
// The first marker.
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_NAME + 1));
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_TYPE + 1));
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_DESC + 1));
// The second marker.
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_NAME + 2));
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_TYPE + 2));
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_DESC + 2));
}
/**
* Tests export and import tracks after creating a track with Gps signal and
* an empty track. Both tracks are paused during recording.
*/
public void testExportAndImportTracks_pause() {
public void testExportAndImportTracks_pausedTrack() {
EndToEndTestUtils.deleteAllTracks();
// Create a new track with 3 gps data.
EndToEndTestUtils.createTrackWithPause(3);
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.SOLO.goBack();
// Create a empty track.
EndToEndTestUtils.createTrackWithPause(0);
instrumentation.waitForIdleSync();
@@ -78,7 +144,7 @@ public class ExportAndImportTest extends ActivityInstrumentationTestCase2<TrackL
instrumentation.waitForIdleSync();
checkExportAndImport();
}
/**
* Tests export and import tracks.
* <ul>
@@ -108,17 +174,18 @@ public class ExportAndImportTest extends ActivityInstrumentationTestCase2<TrackL
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(
R.string.external_storage_import_error_no_file,
FileUtils.buildExternalDirectoryPath(EndToEndTestUtils.GPX)));
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
// Click to export tracks(At least one track) to Gpx files.
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_save_all), true);
EndToEndTestUtils.SOLO
.clickOnText(String.format(activityMyTracks.getString(R.string.menu_save_format),
EndToEndTestUtils.GPX.toUpperCase()));
EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.external_storage_save_success));
EndToEndTestUtils.getButtonOnScreen(
activityMyTracks.getString(R.string.generic_ok), true, true);
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.external_storage_save_success));
EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
// Check export file.
assertEquals(gpxFilesNumber + trackNumber,
EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length);
@@ -132,11 +199,12 @@ public class ExportAndImportTest extends ActivityInstrumentationTestCase2<TrackL
EndToEndTestUtils.rotateAllActivities();
// Wait for the prefix of import success string is much faster than wait
// the whole string.
EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.external_storage_import_success_count).split("%")[0]);
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(
R.string.external_storage_import_success_count).split("%")[0]);
// Check import tracks should be equal with the sum of trackNumber and
// gpxFilesNumber;
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
instrumentation.waitForIdleSync();
assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.trackName));
assertEquals(trackNumber + gpxFilesNumber, EndToEndTestUtils.SOLO.getCurrentListViews().get(0)
@@ -149,10 +217,10 @@ public class ExportAndImportTest extends ActivityInstrumentationTestCase2<TrackL
EndToEndTestUtils.SOLO
.clickOnText(String.format(activityMyTracks.getString(R.string.menu_save_format),
EndToEndTestUtils.KML.toUpperCase()));
EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.external_storage_save_success));
EndToEndTestUtils.getButtonOnScreen(
activityMyTracks.getString(R.string.generic_ok), true, true);
EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.external_storage_save_success));
EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
// Check export files.
assertEquals(gpxFilesNumber, EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length);
assertEquals(trackNumber, EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.KML).length);