Add test case to check the track details during export and import(Only check the altitude in this case).

This commit is contained in:
youtaol
2013-07-11 17:13:40 +08:00
parent dad09f4a87
commit a484963572
@@ -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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> "
+ "<gpx "
+ "version=\"1.1\" "
+ "creator=\"Created by Google My Tracks on Android.\" "
+ "xmlns=\"http://www.topografix.com/GPX/1/1\" "
+ "xmlns:topografix=\"http://www.topografix.com/GPX/Private/TopoGrafix/0/1\" "
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.topografix.com/GPX/Private/TopoGrafix/0/1 http://www.topografix.com/GPX/Private/TopoGrafix/0/1/topografix.xsd\"> "
+ "<metadata> " + "<name><![CDATA[testTrackName1373523959524]]></name> "
+ "<desc><![CDATA[testTrackDesc1373523959524]]></desc> " + "</metadata> " + "<trk> "
+ "<name><![CDATA[testTrackName1373523959524]]></name> "
+ "<desc><![CDATA[testTrackDesc1373523959524]]></desc> "
+ "<type><![CDATA[TestActivity]]></type> "
+ "<extensions><topografix:color>c0c0c0</topografix:color></extensions> " + "<trkseg> "
+ "<trkpt lat=\"39.299998\" lon=\"116\"> " + "<time>2013-07-10T08:00:00.000Z</time> <ele>"
+ minAltitude
+ "</ele>"
+ "</trkpt> "
+ "<trkpt lat=\"39.299498\" lon=\"116.000499\"> "
+ "<time>2013-07-10T08:00:01.000Z</time> "
+ "</trkpt> "
+ "<trkpt lat=\"39.298998\" lon=\"116.001\"> "
+ "<time>2013-07-10T08:00:02.000Z</time> "
+ "</trkpt> "
+ "<trkpt lat=\"39.298498\" lon=\"116.0015\"> "
+ "<time>2013-07-10T08:00:03.000Z</time> "
+ "</trkpt> "
+ "<trkpt lat=\"39.297998\" lon=\"116.001999\"> "
+ "<time>2013-07-10T08:00:04.000Z</time> "
+ "</trkpt> "
+ "<trkpt lat=\"39.297498\" lon=\"116.002499\"> "
+ "<time>2013-07-10T08:00:05.000Z</time> "
+ "</trkpt> "
+ "<trkpt lat=\"39.296998\" lon=\"116.003\"> "
+ "<time>2013-07-10T08:00:06.000Z</time> "
+ "</trkpt> "
+ "<trkpt lat=\"39.296498\" lon=\"116.0035\"> "
+ "<time>2013-07-10T08:00:07.000Z</time> "
+ "</trkpt> "
+ "<trkpt lat=\"39.295998\" lon=\"116.004\"> "
+ "<time>2013-07-10T08:00:08.000Z</time> "
+ "</trkpt> "
+ "<trkpt lat=\"39.295498\" lon=\"116.0045\"> "
+ "<time>2013-07-10T08:00:09.000Z</time> <ele>"
+ maxAltitude
+ "</ele>"
+ "</trkpt> "
+ "</trkseg> " + "</trk> " + "</gpx>";
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();
}
}
}