From a4849635720ce47e2afdfcfcd3b1311e764eae79 Mon Sep 17 00:00:00 2001 From: youtaol Date: Thu, 11 Jul 2013 17:13:40 +0800 Subject: [PATCH] Add test case to check the track details during export and import(Only check the altitude in this case). --- .../common/ExportAllAndImportAllTest.java | 240 ++++++++++++++---- 1 file changed, 188 insertions(+), 52 deletions(-) diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/ExportAllAndImportAllTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/ExportAllAndImportAllTest.java index 74f34477a..7d7f05f6f 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/ExportAllAndImportAllTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/ExportAllAndImportAllTest.java @@ -18,13 +18,17 @@ package com.google.android.apps.mytracks.endtoendtest.common; import com.google.android.apps.mytracks.TrackListActivity; import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; import com.google.android.apps.mytracks.util.FileUtils; +import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.maps.mytracks.R; import android.app.Instrumentation; import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; import android.widget.ListView; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; /** * Tests the import and export of MyTracks. @@ -36,6 +40,10 @@ public class ExportAllAndImportAllTest extends ActivityInstrumentationTestCase2< private Instrumentation instrumentation; private TrackListActivity activityMyTracks; private int trackNumber = 0; + + private final static String tracksName = "testTrackName1373523959524"; + private final static String maxAltitude = "33.3"; + private final static String minAltitude = "33.3"; public ExportAllAndImportAllTest() { super(TrackListActivity.class); @@ -46,7 +54,7 @@ public class ExportAllAndImportAllTest extends ActivityInstrumentationTestCase2< super.setUp(); instrumentation = getInstrumentation(); activityMyTracks = getActivity(); - EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks); + EndToEndTestUtils.setupForDebug(instrumentation, activityMyTracks); trackNumber = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount(); EndToEndTestUtils.createTrackIfEmpty(1, true); } @@ -108,13 +116,7 @@ public class ExportAllAndImportAllTest extends ActivityInstrumentationTestCase2< EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.GPX); // Click to export tracks(At least one track) to Gpx files. - EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_export_all), true); - EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.GPX.toUpperCase()); - EndToEndTestUtils.getButtonOnScreen( - EndToEndTestUtils.activityMytracks.getString(R.string.generic_ok), true, true); - EndToEndTestUtils.SOLO.waitForText(getSaveSuccessMessage(1, EndToEndTestUtils.GPX)); - EndToEndTestUtils - .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); + exportTracks(EndToEndTestUtils.GPX); EndToEndTestUtils.deleteAllTracks(); // Import this tracks. @@ -207,13 +209,7 @@ public class ExportAllAndImportAllTest extends ActivityInstrumentationTestCase2< .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_export_all), true); - EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.GPX.toUpperCase()); - EndToEndTestUtils.getButtonOnScreen( - EndToEndTestUtils.activityMytracks.getString(R.string.generic_ok), true, true); - EndToEndTestUtils.SOLO.waitForText(getSaveSuccessMessage(1, EndToEndTestUtils.GPX)); - EndToEndTestUtils - .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); + exportTracks(EndToEndTestUtils.GPX); // Check export Gpx file. assertEquals(gpxFilesNumber + trackNumber, @@ -226,21 +222,8 @@ public class ExportAllAndImportAllTest extends ActivityInstrumentationTestCase2< importTracks(EndToEndTestUtils.GPX); EndToEndTestUtils.rotateCurrentActivity(); + checkImport(); - /* - * Wait for the prefix of import success string is much faster than wait the - * whole string. - */ - EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.import_success).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(); assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.trackName)); assertEquals(trackNumber + gpxFilesNumber, EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount()); @@ -248,13 +231,8 @@ public class ExportAllAndImportAllTest extends ActivityInstrumentationTestCase2< // Click to export tracks(At least two tracks) to KML files. gpxFilesNumber = EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length; trackNumber = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount(); - EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_export_all), true); - EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.KML.toUpperCase()); - EndToEndTestUtils.getButtonOnScreen( - EndToEndTestUtils.activityMytracks.getString(R.string.generic_ok), true, true); - EndToEndTestUtils.SOLO.waitForText(getSaveSuccessMessage(2, EndToEndTestUtils.KM)); - EndToEndTestUtils - .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); + + exportTracks(EndToEndTestUtils.KML); // Check export files. assertEquals(gpxFilesNumber, EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length); @@ -266,23 +244,8 @@ public class ExportAllAndImportAllTest extends ActivityInstrumentationTestCase2< trackNumber = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount(); importTracks(EndToEndTestUtils.KML); + checkImport(); - /* - * Wait for the prefix of import success string is much faster than wait the - * whole string. - */ - EndToEndTestUtils.waitTextToDisappear(activityMyTracks - .getString(R.string.generic_progress_title)); - EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.import_success).split( - "%")[0]); - - /* - * Check import KML tracks should be equal with the sum of trackNumber and - * KMLFilesNumber; - */ - EndToEndTestUtils - .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); - instrumentation.waitForIdleSync(); assertEquals(trackNumber + KMLFilesNumber, EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount()); } @@ -324,4 +287,177 @@ public class ExportAllAndImportAllTest extends ActivityInstrumentationTestCase2< EndToEndTestUtils.getButtonOnScreen( EndToEndTestUtils.activityMytracks.getString(R.string.generic_ok), true, true); } + + /** + * Exports tracks to external storage. + * + * @param fileType the file type, can be GPX/KML/TCX/CSV currently + */ + private void exportTracks(String fileType) { + EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_export_all), true); + EndToEndTestUtils.SOLO.clickOnText(fileType.toUpperCase()); + EndToEndTestUtils.getButtonOnScreen( + EndToEndTestUtils.activityMytracks.getString(R.string.generic_ok), true, true); + EndToEndTestUtils.SOLO.waitForText(getSaveSuccessMessage(2, fileType)); + EndToEndTestUtils + .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); + } + + /** + * Test export/import one track and checks the detail of this track. + */ + public void testExportImportCheckTrackDetails() { + EndToEndTestUtils.deleteAllTracks(); + EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.GPX); + EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.KML); + EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.TCX); + EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.CSV); + writeGPXTrackFile(); + + importTracks(EndToEndTestUtils.GPX); + checkImport(); + checkSingleTrack(true); + EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.GPX); + + exportTracks(EndToEndTestUtils.KML); + exportTracks(EndToEndTestUtils.GPX); + exportTracks(EndToEndTestUtils.TCX); + exportTracks(EndToEndTestUtils.CSV); + + EndToEndTestUtils.deleteAllTracks(); + importTracks(EndToEndTestUtils.GPX); + checkImport(); + checkSingleTrack(false); + EndToEndTestUtils.deleteAllTracks(); + importTracks(EndToEndTestUtils.KML); + checkImport(); + checkSingleTrack(false); + } + + /** + * Checks the status of import. + */ + private void checkImport() { + /* + * Wait for the prefix of import success string is much faster than wait the + * whole string. + */ + EndToEndTestUtils.waitTextToDisappear(activityMyTracks + .getString(R.string.generic_progress_title)); + EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.import_success).split( + "%")[0]); + + /* + * Check import KML tracks should be equal with the sum of trackNumber and + * KMLFilesNumber; + */ + EndToEndTestUtils + .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); + instrumentation.waitForIdleSync(); + } + + /** + * Checks the detail of one track. + */ + private void checkSingleTrack(boolean isSettingStat) { + ListView listTracks = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0); + assertEquals(1, listTracks.getCount()); + EndToEndTestUtils.SOLO.clickOnText(tracksName); + EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab)); + + if (isSettingStat) { + EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true); + EndToEndTestUtils.SOLO.clickOnText(activityMyTracks + .getString(R.string.track_detail_stats_tab)); + assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks + .getString(R.string.settings_stats_units_title))); + + // Change preferred units. + EndToEndTestUtils.SOLO.clickOnText(activityMyTracks + .getString(R.string.settings_stats_units_title)); + EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.unit_kilometer)); + PreferencesUtils.setBoolean(activityMyTracks, R.string.stats_show_grade_elevation_key, true); + EndToEndTestUtils.SOLO.goBack(); + EndToEndTestUtils.SOLO.goBack(); + } + + assertTrue(EndToEndTestUtils.SOLO.searchText(maxAltitude)); + assertTrue(EndToEndTestUtils.SOLO.searchText(minAltitude)); + + } + + /** + * Writes a GPX track file to MyTracks folder. + */ + private void writeGPXTrackFile() { + String fileName = tracksName + ".gpx"; + String fileContent = " " + + " " + + " " + " " + + " " + " " + " " + + " " + + " " + + " " + + "c0c0c0 " + " " + + " " + " " + + minAltitude + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + maxAltitude + + "" + + " " + + " " + " " + ""; + + try { + File file = new File(FileUtils.getDirectoryPath(EndToEndTestUtils.GPX.toLowerCase()) + + File.separator + fileName); + FileOutputStream fop = new FileOutputStream(file); + // if file doesnt exists, then create it + if (!file.exists()) { + file.createNewFile(); + } + // get the content in bytes + byte[] contentInBytes = fileContent.getBytes(); + fop.write(contentInBytes); + fop.flush(); + fop.close(); + Log.i(EndToEndTestUtils.LOG_TAG, file.getAbsolutePath()); + } catch (IOException e) { + fail(); + } + + } + }