Merge heads

This commit is contained in:
youtaol
2012-08-09 13:32:59 +08:00
parent 61227b2d89
commit f983c93363
28 changed files with 1862 additions and 2088 deletions
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.content;
import com.google.android.apps.mytracks.content.MyTracksProvider.DatabaseHelper;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.test.AndroidTestCase;
/**
@@ -29,10 +30,13 @@ public class MyTracksProviderTest extends AndroidTestCase {
private SQLiteDatabase db;
private MyTracksProvider myTracksProvider;
private String DATABASE_NAME = "mytrackstest.db";
@Override
protected void setUp() throws Exception {
recreatedDatabase();
getContext().deleteDatabase(DATABASE_NAME);
db = (new DatabaseHelper(getContext(), DATABASE_NAME)).getWritableDatabase();
myTracksProvider = new MyTracksProvider();
super.setUp();
}
@@ -61,7 +65,7 @@ public class MyTracksProviderTest extends AndroidTestCase {
assertTrue(checkTable(TracksColumns.TABLE_NAME));
assertTrue(checkTable(WaypointsColumns.TABLE_NAME));
}
/**
* Tests the method
* {@link MyTracksProvider.DatabaseHelper#onUpgrade(SQLiteDatabase, int, int)}
@@ -69,18 +73,18 @@ public class MyTracksProviderTest extends AndroidTestCase {
*/
public void testDatabaseHelper_onUpgrade_Version17() {
DatabaseHelper databaseHelper = new DatabaseHelper(getContext());
// Make two table is only contains one normal integer column.
dropTable(TrackPointsColumns.TABLE_NAME);
dropTable(TracksColumns.TABLE_NAME);
createEmptyTable(TrackPointsColumns.TABLE_NAME);
createEmptyTable(TracksColumns.TABLE_NAME);
databaseHelper.onUpgrade(db, 17, 20);
assertTrue(checkColumn(TrackPointsColumns.TABLE_NAME, TrackPointsColumns.SENSOR));
assertTrue(checkColumn(TracksColumns.TABLE_NAME, TracksColumns.TABLEID));
assertTrue(checkColumn(TracksColumns.TABLE_NAME, TracksColumns.ICON));
assertTrue(isColumnExisted(TrackPointsColumns.TABLE_NAME, TrackPointsColumns.SENSOR));
assertTrue(isColumnExisted(TracksColumns.TABLE_NAME, TracksColumns.TABLEID));
assertTrue(isColumnExisted(TracksColumns.TABLE_NAME, TracksColumns.ICON));
}
/**
* Tests the method
* {@link MyTracksProvider.DatabaseHelper#onUpgrade(SQLiteDatabase, int, int)}
@@ -88,18 +92,18 @@ public class MyTracksProviderTest extends AndroidTestCase {
*/
public void testDatabaseHelper_onUpgrade_Version18() {
DatabaseHelper databaseHelper = new DatabaseHelper(getContext());
// Make two table is only contains one normal integer column.
dropTable(TrackPointsColumns.TABLE_NAME);
dropTable(TracksColumns.TABLE_NAME);
createEmptyTable(TrackPointsColumns.TABLE_NAME);
createEmptyTable(TracksColumns.TABLE_NAME);
databaseHelper.onUpgrade(db, 18, 20);
assertFalse(checkColumn(TrackPointsColumns.TABLE_NAME, TrackPointsColumns.SENSOR));
assertTrue(checkColumn(TracksColumns.TABLE_NAME, TracksColumns.TABLEID));
assertTrue(checkColumn(TracksColumns.TABLE_NAME, TracksColumns.ICON));
assertFalse(isColumnExisted(TrackPointsColumns.TABLE_NAME, TrackPointsColumns.SENSOR));
assertTrue(isColumnExisted(TracksColumns.TABLE_NAME, TracksColumns.TABLEID));
assertTrue(isColumnExisted(TracksColumns.TABLE_NAME, TracksColumns.ICON));
}
/**
* Tests the method
* {@link MyTracksProvider.DatabaseHelper#onUpgrade(SQLiteDatabase, int, int)}
@@ -107,16 +111,16 @@ public class MyTracksProviderTest extends AndroidTestCase {
*/
public void testDatabaseHelper_onUpgrade_Version19() {
DatabaseHelper databaseHelper = new DatabaseHelper(getContext());
// Make two table is only contains one normal integer column.
dropTable(TrackPointsColumns.TABLE_NAME);
dropTable(TracksColumns.TABLE_NAME);
createEmptyTable(TrackPointsColumns.TABLE_NAME);
createEmptyTable(TracksColumns.TABLE_NAME);
databaseHelper.onUpgrade(db, 19, 20);
assertFalse(checkColumn(TrackPointsColumns.TABLE_NAME, TrackPointsColumns.SENSOR));
assertFalse(checkColumn(TracksColumns.TABLE_NAME, TracksColumns.TABLEID));
assertTrue(checkColumn(TracksColumns.TABLE_NAME, TracksColumns.ICON));
assertFalse(isColumnExisted(TrackPointsColumns.TABLE_NAME, TrackPointsColumns.SENSOR));
assertFalse(isColumnExisted(TracksColumns.TABLE_NAME, TracksColumns.TABLEID));
assertTrue(isColumnExisted(TracksColumns.TABLE_NAME, TracksColumns.ICON));
}
/**
@@ -127,11 +131,14 @@ public class MyTracksProviderTest extends AndroidTestCase {
}
/**
* Recreates the database of MyTracks.
* Tests the method {@link MyTracksProvider#getType(Uri)}.
*/
private void recreatedDatabase() {
assertTrue(getContext().deleteDatabase(MyTracksProvider.DATABASE_NAME));
db = (new DatabaseHelper(getContext())).getWritableDatabase();
public void testGetType() {
assertEquals(TrackPointsColumns.CONTENT_TYPE,
myTracksProvider.getType(TrackPointsColumns.CONTENT_URI));
assertEquals(TracksColumns.CONTENT_TYPE, myTracksProvider.getType(TracksColumns.CONTENT_URI));
assertEquals(WaypointsColumns.CONTENT_TYPE,
myTracksProvider.getType(WaypointsColumns.CONTENT_URI));
}
/**
@@ -140,17 +147,18 @@ public class MyTracksProviderTest extends AndroidTestCase {
* @param table the name of table
*/
private void createEmptyTable(String table) {
db.execSQL( "CREATE TABLE " + table + " (test INTEGER)");
db.execSQL("CREATE TABLE " + table + " (test INTEGER)");
}
/**
* Drops a table in database.
*
* @param table
*/
private void dropTable(String table) {
db.execSQL("Drop TABLE " + table);
}
/**
* Checks whether a table is existed.
*
@@ -162,27 +170,27 @@ public class MyTracksProviderTest extends AndroidTestCase {
db.rawQuery("select count(*) from " + table, null);
return true;
} catch (Exception e) {
return false;
return false;
}
}
/**
* Checks whether a column in a table is existed.
* Checks whether a column in a table is existed by whether can order by the
* column.
*
* @param table the name of table
* @param column the name of column
* @return true means the column has existed
*/
private boolean checkColumn(String table, String column) {
private boolean isColumnExisted(String table, String column) {
try {
db.execSQL("ALTER TABLE " + table + " add " + column);
db.execSQL("SElECT count(*) from " + table + " order by " + column);
} catch (Exception e) {
if(e.getMessage().indexOf("duplicate column") > -1) {
return true;
if (e.getMessage().indexOf("no such column") > -1) {
return false;
}
}
return false;
return true;
}
}
}
@@ -430,7 +430,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
/**
* Tests the method {@link MyTracksProviderUtilsImpl#getLastWaypointId(long)}.
*/
public void testGetKLastWaypointId() {
public void testGetLastWaypointId() {
long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track);
@@ -448,7 +448,35 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
assertEquals(-1L, providerUtils.getLastWaypointId(-1));
assertEquals(3L, providerUtils.getLastWaypointId(trackId));
}
/**
* Tests the method
* {@link MyTracksProviderUtils#getLastStatisticsWaypoint(long)}.
*/
public void testGetLastStatisticsWaypoint() {
long trackId = System.currentTimeMillis();
Track track = getTrack(trackId, 10);
providerUtils.insertTrack(track);
Waypoint waypoint1 = new Waypoint();
waypoint1.setTrackId(trackId);
waypoint1.setType(Waypoint.TYPE_STATISTICS);
waypoint1.setDescription("Desc1");
Waypoint waypoint2 = new Waypoint();
waypoint2.setTrackId(trackId);
waypoint2.setType(Waypoint.TYPE_STATISTICS);
waypoint2.setDescription("Desc2");
Waypoint waypoint3 = new Waypoint();
waypoint3.setTrackId(trackId);
waypoint3.setType(Waypoint.TYPE_WAYPOINT);
waypoint3.setDescription("Desc3");
providerUtils.insertWaypoint(waypoint1);
providerUtils.insertWaypoint(waypoint2);
providerUtils.insertWaypoint(waypoint3);
assertEquals("Desc2", providerUtils.getLastStatisticsWaypoint(trackId).getDescription());
}
/**
* Tests the method {@link MyTracksProviderUtilsImpl#getNextMarkerNumber(long, boolean)}.
*/
@@ -246,7 +246,8 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
instrumentation.waitForIdleSync();
EndToEndTestUtils.stopRecording(false);
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_save));
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_save), true,
true);
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.goBack();
instrumentation.waitForIdleSync();
@@ -261,8 +262,9 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
/**
* Tests whether the split marker is created as setting.
* @throws InterruptedException
*/
public void testSplitSetting() {
public void testSplitSetting() throws InterruptedException {
EndToEndTestUtils.startRecording();
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_split_frequency), true);
@@ -276,9 +278,9 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
// Send Gps to give a distance more than one kilometer or one mile.
EndToEndTestUtils.sendGps(20);
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_markers), true);
EndToEndTestUtils.sendGps(20);
assertTrue(EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_markers),
true));
instrumentation.waitForIdleSync();
if (EndToEndTestUtils.hasGpsSingal) {
assertTrue(EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount() > 0);
@@ -297,12 +299,10 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2<Tra
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_markers), true);
EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.marker_list_empty_message));
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_insert_marker), true);
// Rotate when show insert page.
EndToEndTestUtils.rotateAllActivities();
EndToEndTestUtils.enterTextAvoidSoftKeyBoard(0, WAYPOINT_NAME);
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_add));
if (EndToEndTestUtils.hasGpsSingal) {
assertTrue(EndToEndTestUtils.SOLO.searchText(WAYPOINT_NAME));
assertTrue(EndToEndTestUtils.SOLO.waitForText(WAYPOINT_NAME, 1, EndToEndTestUtils.LONG_WAIT_TIME, true));
} else {
assertFalse(EndToEndTestUtils.SOLO.searchText(WAYPOINT_NAME));
}
@@ -0,0 +1,44 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.endtoendtest;
import android.os.Bundle;
import android.test.InstrumentationTestRunner;
import android.util.Log;
/**
* A test runner can be used to run end-to-end test.
*
* @author Youtao Liu
*/
public class EndToEndTestRunner extends InstrumentationTestRunner {
/**
* Gets the parameter port which is used to fix GPS signal to emulators.
*/
@Override
public void onCreate(Bundle arguments) {
try {
EndToEndTestUtils.emulatorPort = Integer.parseInt(arguments.getString("port"));
} catch (Exception e) {
Log.e(EndToEndTestUtils.LOG_TAG, "Unable to get port parameter, use default value." + EndToEndTestUtils.emulatorPort, e);
}
Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:" + EndToEndTestUtils.emulatorPort);
super.onCreate(arguments);
}
}
@@ -25,6 +25,7 @@ import android.app.Activity;
import android.app.Instrumentation;
import android.content.Context;
import android.content.res.Configuration;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
@@ -41,6 +42,7 @@ import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
/**
* Provides utilities to smoke test.
@@ -51,7 +53,7 @@ public class EndToEndTestUtils {
private static final String ANDROID_LOCAL_IP = "10.0.2.2";
// usually 5554.
private static final int ANDROID_LOCAL_PORT = 5554;
public static int emulatorPort = 5558;
private static final int ORIENTATION_PORTRAIT = 1;
private static final int ORIENTATION_LANDSCAPE = 0;
@@ -127,6 +129,7 @@ public class EndToEndTestUtils {
static boolean isEmulator = true;
static boolean hasGpsSingal = true;
static boolean isCheckedFirstLaunch = false;
public static final String LOG_TAG = "MyTracksTest";
private EndToEndTestUtils() {}
@@ -134,6 +137,14 @@ public class EndToEndTestUtils {
* Checks the language, then sets the fields with right string.
*/
private static void checkLanguage() {
Locale locale = null;
Configuration config=null;
config = activityMytracks.getBaseContext().getResources().getConfiguration();
locale = new Locale("en");
Locale.setDefault(locale);
config.locale = locale;
deviceLanguage = instrumentation.getContext().getResources().getConfiguration().locale.getLanguage();
if (RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL.get(deviceLanguage) != null) {
RELATIVE_STARTTIME_POSTFIX = RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL.get(deviceLanguage);
@@ -165,7 +176,7 @@ public class EndToEndTestUtils {
PrintStream out = null;
Socket socket = null;
try {
socket = new Socket(ANDROID_LOCAL_IP, ANDROID_LOCAL_PORT);
socket = new Socket(ANDROID_LOCAL_IP, emulatorPort);
out = new PrintStream(socket.getOutputStream());
float longitude = START_LONGITUDE;
float latitude = START_LATITUDE;
@@ -175,6 +186,8 @@ public class EndToEndTestUtils {
longitude += DELTA_LONGITUDE;
latitude += DELTA_LADITUDE;
}
// Wait the GPS signal can be obtained by MyTracks.
Thread.sleep(SHORT_WAIT_TIME);
} catch (UnknownHostException e) {
System.exit(-1);
} catch (IOException e) {
@@ -406,8 +419,8 @@ public class EndToEndTestUtils {
trackName = TRACK_NAME_PREFIX
+ System.currentTimeMillis();
SOLO.sendKey(KeyEvent.KEYCODE_DEL);
SOLO.enterText(0, trackName);
SOLO.enterText(1, DEFAULTACTIVITY);
enterTextAvoidSoftKeyBoard(0, trackName);
enterTextAvoidSoftKeyBoard(1, DEFAULTACTIVITY);
SOLO.clickOnText(activityMytracks.getString(R.string.generic_save));
instrumentation.waitForIdleSync();
}
@@ -485,6 +498,7 @@ public class EndToEndTestUtils {
SOLO.waitForText(buttonName);
}
// Find on action bar.
if (hasActionBar) {
ArrayList<View> allViews = SOLO.getViews();
for (View view : allViews) {
@@ -499,18 +513,25 @@ public class EndToEndTestUtils {
}
}
ArrayList<Button> currentButtons = SOLO.getCurrentButtons();
for (Button oneButton : currentButtons) {
String title = (String) oneButton.getText();
if (title.equalsIgnoreCase(buttonName)) {
button = oneButton;
// Get all buttons and find.
if(button == null) {
ArrayList<Button> currentButtons = SOLO.getCurrentButtons();
for (Button oneButton : currentButtons) {
String title = (String) oneButton.getText();
if (title.equalsIgnoreCase(buttonName)) {
button = oneButton;
}
}
}
if(isClick) {
if(button != null && isClick) {
SOLO.clickOnView(button);
}
if (button == null && isClick) {
Log.d(LOG_TAG, "Don't find the button " + buttonName);
}
return button;
}
@@ -556,48 +577,49 @@ public class EndToEndTestUtils {
* @param click true means need click this menu
* @return true if find this menu
*/
static boolean findMenuItem(String menuName, boolean click) {boolean findResult = false;
boolean isMoreMenuOpened = false;
// ICS phone.
if(hasActionBar) {
// Firstly find in action bar.
View button = getButtonOnScreen(menuName, false, false);
if (button != null) {
findResult = true;
if (click) {
SOLO.clickOnView(button);
instrumentation.waitForIdleSync();
static boolean findMenuItem(String menuName, boolean click) {
boolean findResult = false;
boolean isMoreMenuOpened = false;
// ICS phone.
if (hasActionBar) {
// Firstly find in action bar.
View button = getButtonOnScreen(menuName, false, false);
if (button != null) {
findResult = true;
if (click) {
SOLO.clickOnView(button);
instrumentation.waitForIdleSync();
}
return findResult;
}
return findResult;
}
showMenuItem();
findResult = SOLO.searchText(menuName);
} else {
// Non-ICS phone.
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
if (SOLO.searchText(menuName)) {
findResult = true;
} else if (SOLO.searchText(MENU_MORE)) {
SOLO.clickOnText(MENU_MORE);
showMenuItem();
findResult = SOLO.searchText(menuName);
isMoreMenuOpened = true;
} else {
// Non-ICS phone.
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
if (SOLO.searchText(menuName)) {
findResult = true;
} else if (SOLO.searchText(MENU_MORE)) {
SOLO.clickOnText(MENU_MORE);
findResult = SOLO.searchText(menuName);
isMoreMenuOpened = true;
}
}
}
if (findResult && click) {
SOLO.clickOnText(menuName);
instrumentation.waitForIdleSync();
} else {
// Quit more menu list if opened.
if (isMoreMenuOpened) {
if (findResult && click) {
SOLO.clickOnText(menuName);
instrumentation.waitForIdleSync();
} else {
// Quit more menu list if opened.
if (isMoreMenuOpened) {
SOLO.goBack();
}
// Quit menu list.
SOLO.goBack();
}
// Quit menu list.
SOLO.goBack();
return findResult;
}
return findResult;
}
/**
* Show menu item list.
@@ -62,7 +62,6 @@ import java.util.Locale;
* @author Youtao Liu
*/
public class GoogleUtils {
public static final String LOG_TAG = "MyTracksTest";
public static final String DOCUMENT_NAME_PREFIX = "My Tracks";
public static final String SPREADSHEET_NAME = DOCUMENT_NAME_PREFIX + "-" + EndToEndTestUtils.DEFAULTACTIVITY;
@@ -92,7 +91,7 @@ public class GoogleUtils {
authToken = AccountManager.get(context).blockingGetAuthToken(getAccount(context),
MapsConstants.SERVICE_NAME, false);
} catch (Exception e) {
Log.d(LOG_TAG, "Unable to get auth token", e);
Log.d(EndToEndTestUtils.LOG_TAG, "Unable to get auth token", e);
return mapData;
}
@@ -107,7 +106,7 @@ public class GoogleUtils {
mapData.add(MapsGDataConverter.getMapMetadataForEntry(entry));
}
} catch (Exception e) {
Log.d(LOG_TAG, "Unable to get maps", e);
Log.d(EndToEndTestUtils.LOG_TAG, "Unable to get maps", e);
} finally {
if (gDataParser != null) {
gDataParser.close();
@@ -139,7 +138,7 @@ public class GoogleUtils {
MapsConstants.SERVICE_NAME, false));
return true;
} catch (Exception e) {
Log.d(LOG_TAG, "Unable to drop map", e);
Log.d(EndToEndTestUtils.LOG_TAG, "Unable to drop map", e);
return false;
}
}
@@ -201,7 +200,7 @@ public class GoogleUtils {
}
}
} catch (Exception e) {
Log.d(LOG_TAG, "Unable to fetch spreadsheet.", e);
Log.d(EndToEndTestUtils.LOG_TAG, "Unable to fetch spreadsheet.", e);
}
return null;
}
@@ -219,7 +218,7 @@ public class GoogleUtils {
private static boolean searchTrackTitleInSpreadsheet(String title, Activity activity, String spreadsheetTitle, boolean isDelete) {
String spreadsheetId = searchSpreadsheetByTitle(spreadsheetTitle, activity).getId().replace(SendDocsUtils.SPREADSHEET_ID_PREFIX, "");
if(spreadsheetId == null) {
Log.d(LOG_TAG, "Unable to find the spreadsheet -- " + spreadsheetTitle);
Log.d(EndToEndTestUtils.LOG_TAG, "Unable to find the spreadsheet -- " + spreadsheetTitle);
return false;
}
Context context = activity.getApplicationContext();
@@ -247,7 +246,7 @@ public class GoogleUtils {
}
}
} catch (Exception e) {
Log.d(LOG_TAG, "Unable to fetch content of spreadsheet.", e);
Log.d(EndToEndTestUtils.LOG_TAG, "Unable to fetch content of spreadsheet.", e);
}
return false;
}
@@ -290,7 +289,7 @@ public class GoogleUtils {
return true;
}
} catch (Exception e) {
Log.d(LOG_TAG, "Unable to query fusion table.", e);
Log.d(EndToEndTestUtils.LOG_TAG, "Unable to query fusion table.", e);
}
return false;
}
@@ -320,7 +319,7 @@ public class GoogleUtils {
}
}
} catch (IOException e) {
Log.d(LOG_TAG, "Failed when delete all fusion tables.", e);
Log.d(EndToEndTestUtils.LOG_TAG, "Failed when delete all fusion tables.", e);
}
return false;
}
@@ -358,7 +357,7 @@ public class GoogleUtils {
response = request.execute();
return response;
} catch (Exception e) {
Log.d(LOG_TAG, "Failed when send fusion table query.", e);
Log.d(EndToEndTestUtils.LOG_TAG, "Failed when send fusion table query.", e);
return null;
}
}
@@ -73,7 +73,7 @@ public class MenuItemsTest extends ActivityInstrumentationTestCase2<TrackListAct
EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_help), true);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.help_about));
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.help_about), true, true);
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
}
@@ -153,9 +153,11 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
EndToEndTestUtils.createTrackIfEmpty(5, false);
EndToEndTestUtils.resetAllSettings(activityMyTracks, true);
ChangeStatsSettings(false, false, true, true, true);
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.track_detail_stats_tab));
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.stats_min_elevation)));
assertTrue(EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.stats_min_elevation), 1,
EndToEndTestUtils.NORMAL_WAIT_TIME, true));
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
.getString(R.string.stats_min_grade)));
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks
@@ -241,10 +243,10 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
// Write to SD card.
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup));
EndToEndTestUtils.SOLO
.clickOnText(activityMyTracks.getString(R.string.settings_backup_now));
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup_now));
assertTrue(EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.sd_card_save_success), 0, EndToEndTestUtils.SUPER_LONG_WAIT_TIME));
activityMyTracks.getString(R.string.sd_card_save_success), 0,
EndToEndTestUtils.SUPER_LONG_WAIT_TIME));
instrumentation.waitForIdleSync();
// Delete all tracks.
@@ -256,11 +258,13 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
// Read from SD card.
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true);
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_backup));
EndToEndTestUtils.SOLO.clickOnText(activityMyTracks
.getString(R.string.settings_backup_restore));
EndToEndTestUtils.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
EndToEndTestUtils.SOLO
.clickOnText(activityMyTracks.getString(R.string.settings_backup_restore));
EndToEndTestUtils
.getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true);
assertTrue(EndToEndTestUtils.SOLO.waitForText(
activityMyTracks.getString(R.string.sd_card_import_success), 0, EndToEndTestUtils.NORMAL_WAIT_TIME));
activityMyTracks.getString(R.string.sd_card_import_success), 0,
EndToEndTestUtils.SUPER_LONG_WAIT_TIME));
// Check restore track.
assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackName));
}
@@ -10,7 +10,7 @@ import junit.framework.TestCase;
/**
* Test the the function of the TripStatisticsBuilder class.
*
*
* @author Sandor Dornbush
*/
public class TripStatisticsBuilderTest extends TestCase {
@@ -25,55 +25,49 @@ public class TripStatisticsBuilderTest extends TestCase {
public void testAddLocationSimple() throws Exception {
builder = new TripStatisticsBuilder(1000);
TripStatistics stats = builder.getStatistics();
TripStatistics tripStatistics = builder.getTripStatistics();
assertEquals(0.0, builder.getSmoothedElevation());
assertEquals(Double.POSITIVE_INFINITY, stats.getMinElevation());
assertEquals(Double.NEGATIVE_INFINITY, stats.getMaxElevation());
assertEquals(0.0, stats.getMaxSpeed());
assertEquals(Double.POSITIVE_INFINITY, stats.getMinGrade());
assertEquals(Double.NEGATIVE_INFINITY, stats.getMaxGrade());
assertEquals(0.0, stats.getTotalElevationGain());
assertEquals(0, stats.getMovingTime());
assertEquals(0.0, stats.getTotalDistance());
assertEquals(Double.POSITIVE_INFINITY, tripStatistics.getMinElevation());
assertEquals(Double.NEGATIVE_INFINITY, tripStatistics.getMaxElevation());
assertEquals(0.0, tripStatistics.getMaxSpeed());
assertEquals(Double.POSITIVE_INFINITY, tripStatistics.getMinGrade());
assertEquals(Double.NEGATIVE_INFINITY, tripStatistics.getMaxGrade());
assertEquals(0.0, tripStatistics.getTotalElevationGain());
assertEquals(0, tripStatistics.getMovingTime());
assertEquals(0.0, tripStatistics.getTotalDistance());
for (int i = 0; i < 100; i++) {
Location l = new Location("test");
l.setAccuracy(1.0f);
l.setLongitude(45.0);
Location location = new Location("test");
location.setAccuracy(1.0f);
location.setLongitude(45.0);
// Going up by 5 meters each time.
l.setAltitude(i);
// Moving by .1% of a degree latitude.
l.setLatitude(i * .001);
l.setSpeed(11.1f);
// Going up by 1 meter each time.
location.setAltitude(i);
location.setLatitude(i * .001); // Moving by .001 degree latitude (111 meters)
location.setSpeed(11.1f);
// Each time slice is 10 seconds.
long time = 1000 + 10000 * i;
l.setTime(time);
boolean moving = builder.addLocation(l, time);
location.setTime(time);
boolean moving = builder.addLocation(location, time);
assertEquals((i != 0), moving);
stats = builder.getStatistics();
assertEquals(10000 * i, stats.getTotalTime());
assertEquals(10000 * i, stats.getMovingTime());
assertEquals(i, builder.getSmoothedElevation(),
Constants.ELEVATION_SMOOTHING_FACTOR / 2);
assertEquals(0.0, stats.getMinElevation());
assertEquals(i, stats.getMaxElevation(),
Constants.ELEVATION_SMOOTHING_FACTOR / 2);
assertEquals(i, stats.getTotalElevationGain(),
Constants.ELEVATION_SMOOTHING_FACTOR);
tripStatistics = builder.getTripStatistics();
assertEquals(10000 * i, tripStatistics.getTotalTime());
assertEquals(10000 * i, tripStatistics.getMovingTime());
assertEquals(i, builder.getSmoothedElevation(), Constants.ELEVATION_SMOOTHING_FACTOR / 2);
assertEquals(0.0, tripStatistics.getMinElevation());
assertEquals(i, tripStatistics.getMaxElevation(), Constants.ELEVATION_SMOOTHING_FACTOR / 2);
assertEquals(i, tripStatistics.getTotalElevationGain(), Constants.ELEVATION_SMOOTHING_FACTOR);
if (i > Constants.SPEED_SMOOTHING_FACTOR) {
assertEquals(11.1f, stats.getMaxSpeed(), 0.1);
assertEquals(11.1f, tripStatistics.getMaxSpeed(), 0.1);
}
if ((i > Constants.GRADE_SMOOTHING_FACTOR)
&& (i > Constants.ELEVATION_SMOOTHING_FACTOR)) {
assertEquals(0.009, stats.getMinGrade(), 0.0001);
assertEquals(0.009, stats.getMaxGrade(), 0.0001);
if (i > Constants.DISTANCE_SMOOTHING_FACTOR && i > Constants.ELEVATION_SMOOTHING_FACTOR) {
// 1 m / 111 m = .009
assertEquals(0.009, tripStatistics.getMinGrade(), 0.0001);
assertEquals(0.009, tripStatistics.getMaxGrade(), 0.0001);
}
// 1 degree = 111 km
// 1 timeslice = 0.001 degree = 111 m
assertEquals(111.0 * i, stats.getTotalDistance(), 100);
assertEquals(111.0 * i, tripStatistics.getTotalDistance(), 100);
}
}
@@ -86,7 +80,7 @@ public class TripStatisticsBuilderTest extends TestCase {
for (int j = 0; j < 100; j++) {
assertEquals(0.0, builder.updateElevation(elevation));
assertEquals(elevation, builder.getSmoothedElevation());
TripStatistics data = builder.getStatistics();
TripStatistics data = builder.getTripStatistics();
assertEquals(elevation, data.getMinElevation());
assertEquals(elevation, data.getMaxElevation());
assertEquals(0.0, data.getTotalElevationGain());
@@ -104,80 +98,71 @@ public class TripStatisticsBuilderTest extends TestCase {
} else {
expectedGain = 1.0;
}
assertEquals(expectedGain,
builder.updateElevation(i));
assertEquals(expectedGain, builder.updateElevation(i));
assertEquals(i, builder.getSmoothedElevation(), 20);
TripStatistics data = builder.getStatistics();
TripStatistics data = builder.getTripStatistics();
assertEquals(0.0, data.getMinElevation(), 0.0);
assertEquals(i, data.getMaxElevation(),
Constants.ELEVATION_SMOOTHING_FACTOR);
assertEquals(i, data.getTotalElevationGain(),
Constants.ELEVATION_SMOOTHING_FACTOR);
assertEquals(i, data.getMaxElevation(), Constants.ELEVATION_SMOOTHING_FACTOR);
assertEquals(i, data.getTotalElevationGain(), Constants.ELEVATION_SMOOTHING_FACTOR);
}
}
public void testGradeSimple() throws Exception {
for (double i = 0; i < 1000; i++) {
// The value of the elevation does not matter. This is just to fill the
// The value of the elevation does not matter. This is just to fill the
// buffer.
builder.updateElevation(i);
builder.updateGrade(100, 100);
if ((i > Constants.GRADE_SMOOTHING_FACTOR)
&& (i > Constants.ELEVATION_SMOOTHING_FACTOR)) {
assertEquals(1.0, builder.getStatistics().getMaxGrade());
assertEquals(1.0, builder.getStatistics().getMinGrade());
if ((i > Constants.GRADE_SMOOTHING_FACTOR) && (i > Constants.ELEVATION_SMOOTHING_FACTOR)) {
assertEquals(1.0, builder.getTripStatistics().getMaxGrade());
assertEquals(1.0, builder.getTripStatistics().getMinGrade());
}
}
for (double i = 0; i < 1000; i++) {
// The value of the elevation does not matter. This is just to fill the
// The value of the elevation does not matter. This is just to fill the
// buffer.
builder.updateElevation(i);
builder.updateGrade(100, -100);
if ((i > Constants.GRADE_SMOOTHING_FACTOR)
&& (i > Constants.ELEVATION_SMOOTHING_FACTOR)) {
assertEquals(1.0, builder.getStatistics().getMaxGrade());
assertEquals(-1.0, builder.getStatistics().getMinGrade());
if ((i > Constants.GRADE_SMOOTHING_FACTOR) && (i > Constants.ELEVATION_SMOOTHING_FACTOR)) {
assertEquals(1.0, builder.getTripStatistics().getMaxGrade());
assertEquals(-1.0, builder.getTripStatistics().getMinGrade());
}
}
}
public void testGradeIgnoreShort() throws Exception {
for (double i = 0; i < 100; i++) {
// The value of the elevation does not matter. This is just to fill the
// The value of the elevation does not matter. This is just to fill the
// buffer.
builder.updateElevation(i);
builder.updateGrade(1, 100);
assertEquals(Double.NEGATIVE_INFINITY, builder.getStatistics().getMaxGrade());
assertEquals(Double.POSITIVE_INFINITY, builder.getStatistics().getMinGrade());
assertEquals(Double.NEGATIVE_INFINITY, builder.getTripStatistics().getMaxGrade());
assertEquals(Double.POSITIVE_INFINITY, builder.getTripStatistics().getMinGrade());
}
}
public void testUpdateSpeedIncludeZero() {
for (int i = 0; i < 1000; i++) {
builder.updateSpeed(i + 1000, 0.0, i, 4.0);
assertEquals(0.0, builder.getStatistics().getMaxSpeed());
assertEquals((i + 1) * 1000, builder.getStatistics().getMovingTime());
assertEquals(0.0, builder.getTripStatistics().getMaxSpeed());
}
}
public void testUpdateSpeedIngoreErrorCode() {
builder.updateSpeed(12345000, 128.0, 12344000, 0.0);
assertEquals(0.0, builder.getStatistics().getMaxSpeed());
assertEquals(1000, builder.getStatistics().getMovingTime());
assertEquals(0.0, builder.getTripStatistics().getMaxSpeed());
}
public void testUpdateSpeedIngoreLargeAcceleration() {
builder.updateSpeed(12345000, 100.0, 12344000, 1.0);
assertEquals(0.0, builder.getStatistics().getMaxSpeed());
assertEquals(1000, builder.getStatistics().getMovingTime());
assertEquals(0.0, builder.getTripStatistics().getMaxSpeed());
}
public void testUpdateSpeed() {
for (int i = 0; i < 1000; i++) {
builder.updateSpeed(i + 1000, 4.0, i, 4.0);
assertEquals((i + 1) * 1000, builder.getStatistics().getMovingTime());
if (i > Constants.SPEED_SMOOTHING_FACTOR) {
assertEquals(4.0, builder.getStatistics().getMaxSpeed());
assertEquals(4.0, builder.getTripStatistics().getMaxSpeed());
}
}
}