mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
sync from main
This commit is contained in:
@@ -31,6 +31,7 @@ import com.google.android.apps.mytracks.stats.TripStatisticsBuilder;
|
||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
@@ -258,7 +259,8 @@ public class ChartActivity extends Activity implements TrackDataListener {
|
||||
* @param location the location to get data for (this method takes ownership of that location)
|
||||
* @param result the resulting point to fill out
|
||||
*/
|
||||
private void fillDataPoint(Location location, double result[]) {
|
||||
@VisibleForTesting
|
||||
void fillDataPoint(Location location, double result[]) {
|
||||
double timeOrDistance = Double.NaN,
|
||||
elevation = Double.NaN,
|
||||
speed = Double.NaN,
|
||||
@@ -290,7 +292,6 @@ public class ChartActivity extends Activity implements TrackDataListener {
|
||||
Mode mode = chartView.getMode();
|
||||
switch (mode) {
|
||||
case BY_DISTANCE:
|
||||
timeOrDistance = profileLength * UnitConversions.M_TO_KM;
|
||||
if (lastLocation != null) {
|
||||
double d = lastLocation.distanceTo(location);
|
||||
if (metricUnits) {
|
||||
@@ -299,6 +300,7 @@ public class ChartActivity extends Activity implements TrackDataListener {
|
||||
profileLength += d * UnitConversions.KM_TO_MI;
|
||||
}
|
||||
}
|
||||
timeOrDistance = profileLength * UnitConversions.M_TO_KM;
|
||||
break;
|
||||
case BY_TIME:
|
||||
if (startTime == -1) {
|
||||
@@ -478,4 +480,19 @@ public class ChartActivity extends Activity implements TrackDataListener {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ChartView getChartView() {
|
||||
return chartView;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
MenuItem getChartSettingsMenuItem() {
|
||||
return chartSettingsMenuItem;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setTrackMaxSpeed(double maxSpeed) {
|
||||
trackMaxSpeed = maxSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.android.apps.mytracks.stats.ExtremityMonitor;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -885,4 +886,14 @@ public class ChartView extends View {
|
||||
public void setChartValueSeriesEnabled(int index, boolean enabled) {
|
||||
series[index].setEnabled(enabled);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getZoomLevel() {
|
||||
return zoomLevel;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getMaxZoomLevel() {
|
||||
return maxZoomLevel;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-4
@@ -20,6 +20,7 @@ import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.SystemUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
@@ -48,6 +49,7 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
private static final int SERVICE_PICKER_DIALOG = 1;
|
||||
|
||||
private SendRequest sendRequest;
|
||||
private Dialog dialog;
|
||||
|
||||
private TableRow mapsTableRow;
|
||||
private TableRow fusionTablesTableRow;
|
||||
@@ -80,7 +82,7 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
switch (id) {
|
||||
case SERVICE_PICKER_DIALOG:
|
||||
final Dialog dialog = new Dialog(this);
|
||||
dialog = new Dialog(this);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(R.layout.upload_service_chooser);
|
||||
dialog.setCancelable(true);
|
||||
@@ -146,7 +148,8 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
/**
|
||||
* Initializes the UI state based on the shared preferences.
|
||||
*/
|
||||
private void initState() {
|
||||
@VisibleForTesting
|
||||
void initState() {
|
||||
SharedPreferences prefs = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
boolean pickExistingMap = prefs.getBoolean(getString(R.string.pick_existing_map_key), false);
|
||||
|
||||
@@ -188,7 +191,8 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
/**
|
||||
* Saves the UI state to the shared preferences.
|
||||
*/
|
||||
private void saveState() {
|
||||
@VisibleForTesting
|
||||
void saveState() {
|
||||
SharedPreferences prefs = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(
|
||||
@@ -225,7 +229,8 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
/**
|
||||
* Starts the next activity, {@link AccountChooserActivity}.
|
||||
*/
|
||||
private void startNextActivity() {
|
||||
@VisibleForTesting
|
||||
protected void startNextActivity() {
|
||||
sendStats();
|
||||
sendRequest.setSendMaps(sendMaps());
|
||||
sendRequest.setSendFusionTables(sendFusionTables());
|
||||
@@ -256,4 +261,14 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
tracker.dispatch();
|
||||
tracker.stop();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Dialog getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
SendRequest getSendRequest() {
|
||||
return sendRequest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,5 +10,6 @@
|
||||
</classpathentry>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/MyTracks"/>
|
||||
<classpathentry kind="lib" path="libs/AndroidMockGenerator.jar"/>
|
||||
<classpathentry kind="lib" path="libs/robotium-solo-2.1.jar" />
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,425 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksLocation;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.apps.mytracks.content.Sensor.SensorDataSet;
|
||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.jayway.android.robotium.solo.Solo;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.location.Location;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ZoomControls;
|
||||
|
||||
/**
|
||||
* Tests {@link ChartActivity}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class ChartActivityTest extends ActivityInstrumentationTestCase2<ChartActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private ChartActivity chartActivity;
|
||||
private Solo solo;
|
||||
private View zoomIn;
|
||||
private View zoomOut;
|
||||
private int currentZoomLevel;
|
||||
|
||||
private final String LOCATION_PROVIDER = "gps";
|
||||
private final double INITIAL_LONGTITUDE = 22;
|
||||
private final double INITIAL_LATITUDE = 22;
|
||||
private final double INITIAL_ALTITUDE = 22;
|
||||
private final float INITIAL_ACCURACY = 5;
|
||||
private final float INITIAL_SPEED = 10;
|
||||
private final float INITIAL_BEARING = 3.0f;
|
||||
// 10 is same with the default value in ChartView
|
||||
private final int MAX_ZOOM_LEVEL = 10;
|
||||
private final int MIN_ZOOM_LEVEL = 1;
|
||||
// The ratio from meter/second to kilometer/hour, the conversion is 60 * 60 /
|
||||
// 1000 = 3.6.
|
||||
private final double METER_PER_SECOND_TO_KILOMETER_PER_HOUR = 3.6;
|
||||
private final double KILOMETER_TO_METER = 1000.0;
|
||||
private final double HOURS_PER_UNIT = 60;
|
||||
|
||||
public ChartActivityTest() {
|
||||
super(ChartActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
chartActivity = getActivity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link ChartActivity#zoomIn()} and {@link ChartActivity#zoomOut()}.
|
||||
*/
|
||||
public void testZoomInAndZoomOut() {
|
||||
currentZoomLevel = chartActivity.getChartView().getZoomLevel();
|
||||
chartActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ZoomControls zoomControls = (ZoomControls) chartActivity.findViewById(R.id.elevation_zoom);
|
||||
zoomIn = zoomControls.getChildAt(0);
|
||||
zoomOut = zoomControls.getChildAt(1);
|
||||
// Invoke following two methods method to initial the display of
|
||||
// ZoomControls.
|
||||
zoomControls.setIsZoomInEnabled(chartActivity.getChartView().canZoomIn());
|
||||
zoomControls.setIsZoomOutEnabled(chartActivity.getChartView().canZoomOut());
|
||||
// Click zoomIn button to disable.
|
||||
for (int i = currentZoomLevel; i > MIN_ZOOM_LEVEL; i--) {
|
||||
zoomIn.performClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertEquals(false, zoomIn.isEnabled());
|
||||
assertEquals(true, zoomOut.isEnabled());
|
||||
chartActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Click to the second max zoom level
|
||||
for (int i = MIN_ZOOM_LEVEL; i < MAX_ZOOM_LEVEL - 1; i++) {
|
||||
zoomOut.performClick();
|
||||
assertEquals(true, zoomIn.isEnabled());
|
||||
assertEquals(true, zoomOut.isEnabled());
|
||||
}
|
||||
zoomOut.performClick();
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertEquals(true, zoomIn.isEnabled());
|
||||
assertEquals(false, zoomOut.isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* There are two parts in this test. Tests
|
||||
* {@link ChartActivity#OnCreateDialog()} which includes the logic to create
|
||||
* {@link ChartSettingsDialog}.
|
||||
*/
|
||||
public void testCreateSettingDialog() {
|
||||
solo = new Solo(instrumentation, chartActivity);
|
||||
// Part1, tests {@link ChartActivity#onCreateOptionsMenu()}. Check if
|
||||
// optional menu is created.
|
||||
assertNull(chartActivity.getChartSettingsMenuItem());
|
||||
sendKeys(KeyEvent.KEYCODE_MENU);
|
||||
assertNotNull(chartActivity.getChartSettingsMenuItem());
|
||||
|
||||
// Part2, tests {@link ChartActivity#onOptionsItemSelected()}. Clicks on the
|
||||
// "Chart settings", and then verify that the dialog contains the
|
||||
// "By distance" text.
|
||||
solo.clickOnText(chartActivity.getString(R.string.menu_chart_view_chart_settings));
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(solo.searchText(chartActivity.getString(R.string.chart_settings_by_distance)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to get the incorrect values of sensor in {@link
|
||||
* ChartActivity#fillDataPoint(Location location, double result[])}.
|
||||
*/
|
||||
public void testFillDataPoint_sensorIncorrect() {
|
||||
MyTracksLocation myTracksLocation = getMyTracksLocation();
|
||||
// No input.
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation, false);
|
||||
assertEquals(Double.NaN, point[3]);
|
||||
assertEquals(Double.NaN, point[4]);
|
||||
assertEquals(Double.NaN, point[5]);
|
||||
|
||||
// Input incorrect state.
|
||||
// Creates SensorData.
|
||||
Sensor.SensorData.Builder powerData = Sensor.SensorData.newBuilder().setValue(20)
|
||||
.setState(Sensor.SensorState.NONE);
|
||||
Sensor.SensorData.Builder cadenceData = Sensor.SensorData.newBuilder().setValue(20)
|
||||
.setState(Sensor.SensorState.NONE);
|
||||
Sensor.SensorData.Builder heartRateData = Sensor.SensorData.newBuilder().setValue(20)
|
||||
.setState(Sensor.SensorState.NONE);
|
||||
// Creates SensorDataSet.
|
||||
SensorDataSet sensorDataSet = myTracksLocation.getSensorDataSet();
|
||||
sensorDataSet = sensorDataSet.toBuilder().setPower(powerData).setCadence(cadenceData)
|
||||
.setHeartRate(heartRateData).build();
|
||||
myTracksLocation.setSensorData(sensorDataSet);
|
||||
// Test.
|
||||
point = fillDataPointTestHelper(myTracksLocation, false);
|
||||
assertEquals(Double.NaN, point[3]);
|
||||
assertEquals(Double.NaN, point[4]);
|
||||
assertEquals(Double.NaN, point[5]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to get the correct values of sensor in {@link
|
||||
* ChartActivity#fillDataPoint(Location location, double result[])}.
|
||||
*/
|
||||
public void testFillDataPoint_sensorCorrect() {
|
||||
MyTracksLocation myTracksLocation = getMyTracksLocation();
|
||||
// No input.
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation, false);
|
||||
assertEquals(Double.NaN, point[3]);
|
||||
assertEquals(Double.NaN, point[4]);
|
||||
assertEquals(Double.NaN, point[5]);
|
||||
|
||||
// Creates SensorData.
|
||||
Sensor.SensorData.Builder powerData = Sensor.SensorData.newBuilder().setValue(20)
|
||||
.setState(Sensor.SensorState.SENDING);
|
||||
Sensor.SensorData.Builder cadenceData = Sensor.SensorData.newBuilder().setValue(20)
|
||||
.setState(Sensor.SensorState.SENDING);
|
||||
Sensor.SensorData.Builder heartRateData = Sensor.SensorData.newBuilder().setValue(20)
|
||||
.setState(Sensor.SensorState.SENDING);
|
||||
// Creates SensorDataSet.
|
||||
SensorDataSet sensorDataSet = myTracksLocation.getSensorDataSet();
|
||||
sensorDataSet = sensorDataSet.toBuilder().setPower(powerData).setCadence(cadenceData)
|
||||
.setHeartRate(heartRateData).build();
|
||||
myTracksLocation.setSensorData(sensorDataSet);
|
||||
// Test.
|
||||
point = fillDataPointTestHelper(myTracksLocation, false);
|
||||
assertEquals(20.0, point[3]);
|
||||
assertEquals(20.0, point[4]);
|
||||
assertEquals(20.0, point[5]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to get the value of metric Distance in
|
||||
* {@link #fillDataPoint}.
|
||||
*/
|
||||
public void testFillDataPoint_distanceMetric() {
|
||||
// By distance.
|
||||
chartActivity.getChartView().setMode(ChartView.Mode.BY_DISTANCE);
|
||||
// Resets last location and writes first location.
|
||||
MyTracksLocation myTracksLocation1 = getMyTracksLocation();
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation1, true);
|
||||
assertEquals(0.0, point[0]);
|
||||
|
||||
// The second is a same location, just different time.
|
||||
MyTracksLocation myTracksLocation2 = getMyTracksLocation();
|
||||
point = fillDataPointTestHelper(myTracksLocation2, false);
|
||||
assertEquals(0.0, point[0]);
|
||||
|
||||
// The third location is a new location, and use metric.
|
||||
MyTracksLocation myTracksLocation3 = getMyTracksLocation();
|
||||
myTracksLocation3.setLatitude(23);
|
||||
point = fillDataPointTestHelper(myTracksLocation3, false);
|
||||
// Computes the distance between Latitude 22 and 23.
|
||||
float[] results = new float[4];
|
||||
Location.distanceBetween(myTracksLocation2.getLatitude(), myTracksLocation2.getLongitude(),
|
||||
myTracksLocation3.getLatitude(), myTracksLocation3.getLongitude(), results);
|
||||
double distance1 = results[0];
|
||||
assertEquals(distance1 / KILOMETER_TO_METER, point[0]);
|
||||
|
||||
// The fourth location is a new location, and use metric.
|
||||
MyTracksLocation myTracksLocation4 = getMyTracksLocation();
|
||||
myTracksLocation4.setLatitude(24);
|
||||
point = fillDataPointTestHelper(myTracksLocation4, false);
|
||||
// Computes the distance between Latitude 23 and 24.
|
||||
|
||||
Location.distanceBetween(myTracksLocation3.getLatitude(), myTracksLocation3.getLongitude(),
|
||||
myTracksLocation4.getLatitude(), myTracksLocation4.getLongitude(), results);
|
||||
double distance2 = results[0];
|
||||
assertEquals((distance1 + distance2) / KILOMETER_TO_METER, point[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to get the value of imperial Distance in
|
||||
* {@link #fillDataPoint}.
|
||||
*/
|
||||
public void testFillDataPoint_distanceImperial() {
|
||||
// Setups to use imperial.
|
||||
chartActivity.onUnitsChanged(false);
|
||||
|
||||
// The first is a same location, just different time.
|
||||
MyTracksLocation myTracksLocation1 = getMyTracksLocation();
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation1, true);
|
||||
assertEquals(0.0, point[0]);
|
||||
|
||||
// The second location is a new location, and use imperial.
|
||||
MyTracksLocation myTracksLocation2 = getMyTracksLocation();
|
||||
myTracksLocation2.setLatitude(23);
|
||||
point = fillDataPointTestHelper(myTracksLocation2, false);
|
||||
/*
|
||||
* Computes the distance between Latitude 22 and 23. And for we set using
|
||||
* imperial, the distance should be multiplied by UnitConversions.KM_TO_MI.
|
||||
*/
|
||||
float[] results = new float[4];
|
||||
Location.distanceBetween(myTracksLocation1.getLatitude(), myTracksLocation1.getLongitude(),
|
||||
myTracksLocation2.getLatitude(), myTracksLocation2.getLongitude(), results);
|
||||
double distance1 = results[0] * UnitConversions.KM_TO_MI;
|
||||
assertEquals(distance1 / KILOMETER_TO_METER, point[0]);
|
||||
|
||||
// The third location is a new location, and use imperial.
|
||||
MyTracksLocation myTracksLocation3 = getMyTracksLocation();
|
||||
myTracksLocation3.setLatitude(24);
|
||||
point = fillDataPointTestHelper(myTracksLocation3, false);
|
||||
/*
|
||||
* Computes the distance between Latitude 23 and 24. And for we set using
|
||||
* imperial, the distance should be multiplied by UnitConversions.KM_TO_MI.
|
||||
*/
|
||||
|
||||
Location.distanceBetween(myTracksLocation2.getLatitude(), myTracksLocation2.getLongitude(),
|
||||
myTracksLocation3.getLatitude(), myTracksLocation3.getLongitude(), results);
|
||||
double distance2 = results[0] * UnitConversions.KM_TO_MI;
|
||||
assertEquals((distance1 + distance2) / KILOMETER_TO_METER, point[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to get the values of time in {@link #fillDataPoint}.
|
||||
*/
|
||||
public void testFillDataPoint_time() {
|
||||
// By time
|
||||
chartActivity.getChartView().setMode(ChartView.Mode.BY_TIME);
|
||||
MyTracksLocation myTracksLocation1 = getMyTracksLocation();
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation1, true);
|
||||
assertEquals(0.0, point[0]);
|
||||
long timeSpan = 222;
|
||||
MyTracksLocation myTracksLocation2 = getMyTracksLocation();
|
||||
myTracksLocation2.setTime(myTracksLocation1.getTime() + timeSpan);
|
||||
point = fillDataPointTestHelper(myTracksLocation2, false);
|
||||
assertEquals((double) timeSpan, point[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to get the value of elevation in
|
||||
* {@link ChartActivity#fillDataPoint} by one and two points.
|
||||
*/
|
||||
public void testFillDataPoint_elevation() {
|
||||
MyTracksLocation myTracksLocation1 = getMyTracksLocation();
|
||||
/*
|
||||
* At first, clear old points of elevation, so give true to the second
|
||||
* parameter. Then only one value INITIALLONGTITUDE in buffer.
|
||||
*/
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation1, true);
|
||||
assertEquals(INITIAL_ALTITUDE, point[1]);
|
||||
/*
|
||||
* Send another value to buffer, now there are two values, INITIALALTITUDE
|
||||
* and INITIALALTITUDE * 2.
|
||||
*/
|
||||
MyTracksLocation myTracksLocation2 = getMyTracksLocation();
|
||||
myTracksLocation2.setAltitude(INITIAL_ALTITUDE * 2);
|
||||
point = fillDataPointTestHelper(myTracksLocation2, false);
|
||||
assertEquals((INITIAL_ALTITUDE + INITIAL_ALTITUDE * 2) / 2.0, point[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to get the value of speed in
|
||||
* {@link ChartActivity#fillDataPoint}. In this test, firstly remove all
|
||||
* points in memory, and then fill in two points one by one. The speed values
|
||||
* of these points are 129, 130.
|
||||
*/
|
||||
public void testFillDataPoint_speed() {
|
||||
// Set max speed to make the speed of points are valid.
|
||||
chartActivity.setTrackMaxSpeed(200.0);
|
||||
/*
|
||||
* At first, clear old points of speed, so give true to the second
|
||||
* parameter. It will not be filled in to the speed buffer.
|
||||
*/
|
||||
MyTracksLocation myTracksLocation1 = getMyTracksLocation();
|
||||
myTracksLocation1.setSpeed(129);
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation1, true);
|
||||
assertEquals(0.0, point[2]);
|
||||
|
||||
/*
|
||||
* Tests the logic when both metricUnits and reportSpeed are true.This
|
||||
* location will be filled into speed buffer.
|
||||
*/
|
||||
MyTracksLocation myTracksLocation2 = getMyTracksLocation();
|
||||
// Add a time span here to make sure the second point is valid, the value
|
||||
// 222 here is doesn't matter.
|
||||
myTracksLocation2.setTime(myTracksLocation1.getTime() + 222);
|
||||
myTracksLocation2.setSpeed(130);
|
||||
point = fillDataPointTestHelper(myTracksLocation2, false);
|
||||
assertEquals(130.0 * METER_PER_SECOND_TO_KILOMETER_PER_HOUR, point[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to compute speed when use Imperial.
|
||||
*/
|
||||
public void testFillDataPoint_speedImperial() {
|
||||
// Setups to use imperial.
|
||||
chartActivity.onUnitsChanged(false);
|
||||
MyTracksLocation myTracksLocation = getMyTracksLocation();
|
||||
myTracksLocation.setSpeed(132);
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation, true);
|
||||
assertEquals(132.0 * METER_PER_SECOND_TO_KILOMETER_PER_HOUR * UnitConversions.KM_TO_MI,
|
||||
point[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to get pace value when reportSpeed is false.
|
||||
*/
|
||||
public void testFillDataPoint_pace_nonZeroSpeed() {
|
||||
// Setups reportSpeed to false.
|
||||
chartActivity.onReportSpeedChanged(false);
|
||||
MyTracksLocation myTracksLocation = getMyTracksLocation();
|
||||
myTracksLocation.setSpeed(134);
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation, true);
|
||||
assertEquals(HOURS_PER_UNIT / (134.0 * METER_PER_SECOND_TO_KILOMETER_PER_HOUR), point[2]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to get pace value when reportSpeed is false and average
|
||||
* speed is zero.
|
||||
*/
|
||||
public void testFillDataPoint_pace_zeroSpeed() {
|
||||
// Setups reportSpeed to false.
|
||||
chartActivity.onReportSpeedChanged(false);
|
||||
MyTracksLocation myTracksLocation = getMyTracksLocation();
|
||||
myTracksLocation.setSpeed(0);
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation, true);
|
||||
assertEquals(Double.NaN, point[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates a MyTracksLocation for test.
|
||||
*
|
||||
* @return a simulated location.
|
||||
*/
|
||||
private MyTracksLocation getMyTracksLocation() {
|
||||
// Initial Location
|
||||
Location loc = new Location(LOCATION_PROVIDER);
|
||||
loc.setLongitude(INITIAL_LONGTITUDE);
|
||||
loc.setLatitude(INITIAL_LATITUDE);
|
||||
loc.setAltitude(INITIAL_ALTITUDE);
|
||||
loc.setAccuracy(INITIAL_ACCURACY);
|
||||
loc.setSpeed(INITIAL_SPEED);
|
||||
loc.setTime(System.currentTimeMillis());
|
||||
loc.setBearing(INITIAL_BEARING);
|
||||
SensorDataSet sd = SensorDataSet.newBuilder().build();
|
||||
MyTracksLocation myTracksLocation = new MyTracksLocation(loc, sd);
|
||||
|
||||
return myTracksLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to test fillDataPoint.
|
||||
*
|
||||
* @param location location to fill
|
||||
* @param operation a flag to do some operations
|
||||
* @return data of this location
|
||||
*/
|
||||
private double[] fillDataPointTestHelper(Location location, boolean isNeedClear) {
|
||||
if (isNeedClear) {
|
||||
chartActivity.clearTrackPoints();
|
||||
}
|
||||
double[] point = new double[6];
|
||||
chartActivity.fillDataPoint(location, point);
|
||||
return point;
|
||||
}
|
||||
|
||||
}
|
||||
+333
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
* 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.io.sendtogoogle;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
/**
|
||||
* Tests the {@link SendRequest}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class SendRequestTest extends AndroidTestCase {
|
||||
private SendRequest sendRequest;
|
||||
|
||||
final static private String ACCOUNTNAME = "testAccount1";
|
||||
final static private String ACCOUNTYPE = "testType1";
|
||||
final static private String MAPID = "mapId1";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
sendRequest = new SendRequest(1, true, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#getTrackId()}. The value should be set
|
||||
* to 1 when it is initialed in setup method.
|
||||
*/
|
||||
public void testGetTrackId() {
|
||||
assertEquals(1, sendRequest.getTrackId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isShowMaps()}. The value should be set
|
||||
* to true when it is initialed in setup method.
|
||||
*/
|
||||
public void testIsShowMaps() {
|
||||
assertEquals(true, sendRequest.isShowMaps());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isShowFusionTables()}. The value should
|
||||
* be set to true when it is initialed in setup method.
|
||||
*/
|
||||
public void testIsShowFusionTables() {
|
||||
assertEquals(true, sendRequest.isShowFusionTables());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isShowDocs()}. The value should be set
|
||||
* to true when it is initialed in setup method.
|
||||
*/
|
||||
public void testIsShowDocs() {
|
||||
assertEquals(true, sendRequest.isShowDocs());
|
||||
}
|
||||
|
||||
public void testIsShowAll() {
|
||||
assertEquals(true, sendRequest.isShowAll());
|
||||
sendRequest = new SendRequest(1, false, true, true);
|
||||
assertEquals(false, sendRequest.isShowAll());
|
||||
sendRequest = new SendRequest(1, true, false, true);
|
||||
assertEquals(false, sendRequest.isShowAll());
|
||||
sendRequest = new SendRequest(1, true, true, false);
|
||||
assertEquals(false, sendRequest.isShowAll());
|
||||
sendRequest = new SendRequest(1, false, true, false);
|
||||
assertEquals(false, sendRequest.isShowAll());
|
||||
sendRequest = new SendRequest(1, false, false, false);
|
||||
assertEquals(false, sendRequest.isShowAll());
|
||||
}
|
||||
|
||||
public void testIsSendMaps() {
|
||||
assertEquals(false, sendRequest.isSendMaps());
|
||||
sendRequest.setSendMaps(true);
|
||||
assertEquals(true, sendRequest.isSendMaps());
|
||||
}
|
||||
|
||||
public void testIsSendFusionTables() {
|
||||
assertEquals(false, sendRequest.isSendFusionTables());
|
||||
sendRequest.setSendFusionTables(true);
|
||||
assertEquals(true, sendRequest.isSendFusionTables());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isSendDocs()}. The value should be set
|
||||
* to false which is its default value when it is initialed in setup method.
|
||||
*/
|
||||
public void testIsSendDocs() {
|
||||
assertEquals(false, sendRequest.isSendDocs());
|
||||
sendRequest.setSendDocs(true);
|
||||
assertEquals(true, sendRequest.isSendDocs());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isNewMap()}. The value should be set to
|
||||
* false which is its default value when it is initialed in setup method.
|
||||
*/
|
||||
public void testIsNewMap() {
|
||||
assertEquals(false, sendRequest.isNewMap());
|
||||
sendRequest.setNewMap(true);
|
||||
assertEquals(true, sendRequest.isNewMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#getAccount()}. The value should be set
|
||||
* to null which is its default value when it is initialed in setup method.
|
||||
*/
|
||||
public void testGetAccount() {
|
||||
assertEquals(null, sendRequest.getAccount());
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
sendRequest.setAccount(account);
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#getMapId()}. The value should be set to
|
||||
* null which is its default value when it is initialed in setup method.
|
||||
*/
|
||||
public void testGetMapId() {
|
||||
assertEquals(null, sendRequest.getMapId());
|
||||
sendRequest.setMapId("1");
|
||||
assertEquals("1", "1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isMapsSuccess()}. The value should be
|
||||
* set to false which is its default value when it is initialed in setup
|
||||
* method.
|
||||
*/
|
||||
public void testIsMapsSuccess() {
|
||||
assertEquals(false, sendRequest.isMapsSuccess());
|
||||
sendRequest.setMapsSuccess(true);
|
||||
assertEquals(true, sendRequest.isMapsSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isFusionTablesSuccess()}. The value
|
||||
* should be set to false which is its default value when it is initialed in
|
||||
* setup method.
|
||||
*/
|
||||
public void testIsFusionTablesSuccess() {
|
||||
assertEquals(false, sendRequest.isFusionTablesSuccess());
|
||||
sendRequest.setFusionTablesSuccess(true);
|
||||
assertEquals(true, sendRequest.isFusionTablesSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isDocsSuccess()}. The value should be
|
||||
* set to false which is its default value when it is initialed in setup
|
||||
* method.
|
||||
*/
|
||||
public void testIsDocsSuccess() {
|
||||
assertEquals(false, sendRequest.isDocsSuccess());
|
||||
sendRequest.setDocsSuccess(true);
|
||||
assertEquals(true, sendRequest.isDocsSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendRequest#SendRequest(Parcel in)} when all values are true.
|
||||
*/
|
||||
public void testCreateFromParcel_true() {
|
||||
Parcel sourceParcel = Parcel.obtain();
|
||||
sourceParcel.setDataPosition(0);
|
||||
sourceParcel.writeLong(2);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
sourceParcel.writeParcelable(account, 0);
|
||||
sourceParcel.writeString(MAPID);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.setDataPosition(0);
|
||||
sendRequest = SendRequest.CREATOR.createFromParcel(sourceParcel);
|
||||
assertEquals(2, sendRequest.getTrackId());
|
||||
assertEquals(true, sendRequest.isShowMaps());
|
||||
assertEquals(true, sendRequest.isShowFusionTables());
|
||||
assertEquals(true, sendRequest.isShowDocs());
|
||||
assertEquals(true, sendRequest.isSendMaps());
|
||||
assertEquals(true, sendRequest.isSendFusionTables());
|
||||
assertEquals(true, sendRequest.isSendDocs());
|
||||
assertEquals(true, sendRequest.isNewMap());
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
assertEquals(MAPID, sendRequest.getMapId());
|
||||
assertEquals(true, sendRequest.isMapsSuccess());
|
||||
assertEquals(true, sendRequest.isFusionTablesSuccess());
|
||||
assertEquals(true, sendRequest.isDocsSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendRequest#SendRequest(Parcel in)} when all values are false.
|
||||
*/
|
||||
public void testCreateFromParcel_false() {
|
||||
Parcel sourceParcel = Parcel.obtain();
|
||||
sourceParcel.setDataPosition(0);
|
||||
sourceParcel.writeLong(4);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
sourceParcel.writeParcelable(account, 0);
|
||||
sourceParcel.writeString(MAPID);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.setDataPosition(0);
|
||||
sendRequest = SendRequest.CREATOR.createFromParcel(sourceParcel);
|
||||
assertEquals(4, sendRequest.getTrackId());
|
||||
assertEquals(false, sendRequest.isShowMaps());
|
||||
assertEquals(false, sendRequest.isShowFusionTables());
|
||||
assertEquals(false, sendRequest.isShowDocs());
|
||||
assertEquals(false, sendRequest.isSendMaps());
|
||||
assertEquals(false, sendRequest.isSendFusionTables());
|
||||
assertEquals(false, sendRequest.isSendDocs());
|
||||
assertEquals(false, sendRequest.isNewMap());
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
assertEquals(MAPID, sendRequest.getMapId());
|
||||
assertEquals(false, sendRequest.isMapsSuccess());
|
||||
assertEquals(false, sendRequest.isFusionTablesSuccess());
|
||||
assertEquals(false, sendRequest.isDocsSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendRequest#writeToParcel(Parcel in)} when all input values
|
||||
* are true or affirmative.
|
||||
*/
|
||||
public void testWriteToParcel_allTrue() {
|
||||
sendRequest = new SendRequest(1, false, false, false);
|
||||
Parcel parcelWrite1st = Parcel.obtain();
|
||||
parcelWrite1st.setDataPosition(0);
|
||||
sendRequest.writeToParcel(parcelWrite1st, 1);
|
||||
parcelWrite1st.setDataPosition(0);
|
||||
long trackId = parcelWrite1st.readLong();
|
||||
boolean showMaps = parcelWrite1st.readByte() == 1;
|
||||
boolean showFusionTables = parcelWrite1st.readByte() == 1;
|
||||
boolean showDocs = parcelWrite1st.readByte() == 1;
|
||||
boolean sendMaps = parcelWrite1st.readByte() == 1;
|
||||
boolean sendFusionTables = parcelWrite1st.readByte() == 1;
|
||||
boolean sendDocs = parcelWrite1st.readByte() == 1;
|
||||
boolean newMap = parcelWrite1st.readByte() == 1;
|
||||
Parcelable account = parcelWrite1st.readParcelable(null);
|
||||
String mapId = parcelWrite1st.readString();
|
||||
boolean mapsSuccess = parcelWrite1st.readByte() == 1;
|
||||
boolean fusionTablesSuccess = parcelWrite1st.readByte() == 1;
|
||||
boolean docsSuccess = parcelWrite1st.readByte() == 1;
|
||||
assertEquals(1, trackId);
|
||||
assertEquals(false, showMaps);
|
||||
assertEquals(false, showFusionTables);
|
||||
assertEquals(false, showDocs);
|
||||
assertEquals(false, sendMaps);
|
||||
assertEquals(false, sendFusionTables);
|
||||
assertEquals(false, sendDocs);
|
||||
assertEquals(false, newMap);
|
||||
assertEquals(null, account);
|
||||
assertEquals(null, mapId);
|
||||
assertEquals(false, mapsSuccess);
|
||||
assertEquals(false, fusionTablesSuccess);
|
||||
assertEquals(false, docsSuccess);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendRequest#writeToParcel(Parcel in)} when all input values
|
||||
* are false or negative.
|
||||
*/
|
||||
public void testWriteToParcel_allFalse() {
|
||||
sendRequest = new SendRequest(4, true, true, true);
|
||||
sendRequest.setSendMaps(true);
|
||||
sendRequest.setSendFusionTables(true);
|
||||
sendRequest.setSendDocs(true);
|
||||
sendRequest.setNewMap(true);
|
||||
Account accountNew = new Account(ACCOUNTNAME + "2", ACCOUNTYPE + "2");
|
||||
sendRequest.setAccount(accountNew);
|
||||
sendRequest.setMapId(MAPID);
|
||||
sendRequest.setMapsSuccess(true);
|
||||
sendRequest.setFusionTablesSuccess(true);
|
||||
sendRequest.setDocsSuccess(true);
|
||||
Parcel parcelWrite2nd = Parcel.obtain();
|
||||
parcelWrite2nd.setDataPosition(0);
|
||||
sendRequest.writeToParcel(parcelWrite2nd, 1);
|
||||
parcelWrite2nd.setDataPosition(0);
|
||||
long trackId = parcelWrite2nd.readLong();
|
||||
boolean showMaps = parcelWrite2nd.readByte() == 1;
|
||||
boolean showFusionTables = parcelWrite2nd.readByte() == 1;
|
||||
boolean showDocs = parcelWrite2nd.readByte() == 1;
|
||||
boolean sendMaps = parcelWrite2nd.readByte() == 1;
|
||||
boolean sendFusionTables = parcelWrite2nd.readByte() == 1;
|
||||
boolean sendDocs = parcelWrite2nd.readByte() == 1;
|
||||
boolean newMap = parcelWrite2nd.readByte() == 1;
|
||||
Parcelable account = parcelWrite2nd.readParcelable(null);
|
||||
String mapId = parcelWrite2nd.readString();
|
||||
boolean mapsSuccess = parcelWrite2nd.readByte() == 1;
|
||||
boolean fusionTablesSuccess = parcelWrite2nd.readByte() == 1;
|
||||
boolean docsSuccess = parcelWrite2nd.readByte() == 1;
|
||||
assertEquals(4, trackId);
|
||||
assertEquals(true, showMaps);
|
||||
assertEquals(true, showFusionTables);
|
||||
assertEquals(true, showDocs);
|
||||
assertEquals(true, sendMaps);
|
||||
assertEquals(true, sendFusionTables);
|
||||
assertEquals(true, sendDocs);
|
||||
assertEquals(true, newMap);
|
||||
assertEquals(accountNew, account);
|
||||
assertEquals(MAPID, mapId);
|
||||
assertEquals(true, mapsSuccess);
|
||||
assertEquals(true, fusionTablesSuccess);
|
||||
assertEquals(true, docsSuccess);
|
||||
}
|
||||
|
||||
}
|
||||
+309
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* 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.io.sendtogoogle;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
/**
|
||||
* Tests the {@link UploadServiceChooserActivity}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class UploadServiceChooserActivityTest extends
|
||||
ActivityInstrumentationTestCase2<UploadServiceChooserActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private UploadServiceChooserActivity uploadServiceChooserActivity;
|
||||
|
||||
public UploadServiceChooserActivityTest() {
|
||||
super(UploadServiceChooserActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to control display all send options. This test cover code
|
||||
* in method {@link UploadServiceChooserActivity#onCreateDialog()},
|
||||
* {@link UploadServiceChooserActivity#updateStateBySendRequest()} and
|
||||
* {@link UploadServiceChooserActivity#updateStateBySelection()}.
|
||||
*/
|
||||
public void testOnCreateDialog_displayAll() {
|
||||
// Initials activity to display all send items.
|
||||
initialActivity(true, true, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getFusionTablesCheckBox().isShown());
|
||||
assertTrue(getDocsCheckBox().isShown());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
|
||||
// Clicks to disable all send items.
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (getMapsCheckBox().isChecked()) {
|
||||
getMapsCheckBox().performClick();
|
||||
}
|
||||
if (getFusionTablesCheckBox().isChecked()) {
|
||||
getFusionTablesCheckBox().performClick();
|
||||
}
|
||||
if (getDocsCheckBox().isChecked()) {
|
||||
getDocsCheckBox().performClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getFusionTablesCheckBox().isShown());
|
||||
assertTrue(getDocsCheckBox().isShown());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
|
||||
assertFalse(getNewMapRadioButton().isShown());
|
||||
assertFalse(getExistingMapRadioButton().isShown());
|
||||
assertFalse(getSendButton().isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to check the send to Google Maps option. This test cover
|
||||
* code in method {@link UploadServiceChooserActivity#onCreateDialog()},
|
||||
* {@link UploadServiceChooserActivity#updateStateBySendRequest()} and
|
||||
* {@link UploadServiceChooserActivity#updateStateBySelection()}.
|
||||
*/
|
||||
public void testOnCreateDialog_displayOne() {
|
||||
// Initials activity to display all send items.
|
||||
initialActivity(true, false, false);
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
|
||||
// Clicks to enable this items.
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (!getMapsCheckBox().isChecked()) {
|
||||
getMapsCheckBox().performClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getNewMapRadioButton().isShown());
|
||||
assertTrue(getExistingMapRadioButton().isShown());
|
||||
assertTrue(getSendButton().isEnabled());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to control display none. This test cover code in method
|
||||
* {@link UploadServiceChooserActivity#onCreateDialog()},
|
||||
* {@link UploadServiceChooserActivity#updateStateBySendRequest()} and
|
||||
* {@link UploadServiceChooserActivity#updateStateBySelection()}.
|
||||
*/
|
||||
public void testOnCreateDialog_displayNone() {
|
||||
initialActivity(false, false, false);
|
||||
assertFalse(getMapsCheckBox().isShown());
|
||||
assertFalse(getFusionTablesCheckBox().isShown());
|
||||
assertFalse(getDocsCheckBox().isShown());
|
||||
assertFalse(getSendButton().isEnabled());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to initial state of check box to unchecked. This test cover
|
||||
* code in method {@link UploadServiceChooserActivity#onCreateDialog()},
|
||||
* {@link UploadServiceChooserActivity#initState()}.
|
||||
*/
|
||||
public void testOnCreateDialog_initStateUnchecked() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to false in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), false);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
false);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), false);
|
||||
editor.commit();
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertFalse(getMapsCheckBox().isChecked());
|
||||
assertFalse(getFusionTablesCheckBox().isChecked());
|
||||
assertFalse(getDocsCheckBox().isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to initial state of check box to checked. This test cover
|
||||
* code in method {@link UploadServiceChooserActivity#onCreateDialog()},
|
||||
* {@link UploadServiceChooserActivity#initState()}.
|
||||
*/
|
||||
public void testOnCreateDialog_initStateChecked() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to true in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.pick_existing_map_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), true);
|
||||
editor.commit();
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(getMapsCheckBox().isChecked());
|
||||
assertTrue(getFusionTablesCheckBox().isChecked());
|
||||
assertTrue(getDocsCheckBox().isChecked());
|
||||
assertTrue(getExistingMapRadioButton().isChecked());
|
||||
|
||||
assertFalse(getNewMapRadioButton().isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic of saveState when click send button. This test cover code
|
||||
* in method {@link UploadServiceChooserActivity#saveState()},
|
||||
* {@link UploadServiceChooserActivity#initState()} ,
|
||||
* {@link UploadServiceChooserActivity#sendMaps()},
|
||||
* {@link UploadServiceChooserActivity#sendFusionTables()}, and
|
||||
* {@link UploadServiceChooserActivity#sendDocs()}.
|
||||
*/
|
||||
public void testOnCreateDialog_saveState() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to true in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), true);
|
||||
editor.commit();
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
uploadServiceChooserActivity.saveState();
|
||||
// All values in SharedPreferences must be changed.
|
||||
assertTrue(prefs.getBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key),
|
||||
false));
|
||||
assertTrue(prefs.getBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key),
|
||||
false));
|
||||
assertTrue(prefs.getBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key),
|
||||
false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic of startNextActivity when click send button. This test
|
||||
* cover code in method
|
||||
* {@link UploadServiceChooserActivity#startNextActivity()} ,
|
||||
* {@link UploadServiceChooserActivity#initState()} ,
|
||||
* {@link UploadServiceChooserActivity#sendMaps()},
|
||||
* {@link UploadServiceChooserActivity#sendFusionTables()}, and
|
||||
* {@link UploadServiceChooserActivity#sendDocs()}.
|
||||
*/
|
||||
public void testOnCreateDialog_startNextActivity() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to true or false in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
false);
|
||||
editor.commit();
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
uploadServiceChooserActivity.startNextActivity();
|
||||
// All values in SendRequest must be same as set above.
|
||||
assertTrue(uploadServiceChooserActivity.getSendRequest().isSendMaps());
|
||||
assertTrue(uploadServiceChooserActivity.getSendRequest().isSendDocs());
|
||||
|
||||
assertFalse(uploadServiceChooserActivity.getSendRequest().isSendFusionTables());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initials a activity to be tested.
|
||||
*
|
||||
* @param showMaps
|
||||
* @param showFusionTables
|
||||
* @param showDocs
|
||||
*/
|
||||
private void initialActivity(boolean showMaps, boolean showFusionTables, boolean showDocs) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(1L, showMaps, showFusionTables,
|
||||
showDocs));
|
||||
setActivityIntent(intent);
|
||||
uploadServiceChooserActivity = this.getActivity();
|
||||
}
|
||||
|
||||
private Button getSendButton() {
|
||||
return (Button) uploadServiceChooserActivity.getDialog()
|
||||
.findViewById(R.id.send_google_send_now);
|
||||
}
|
||||
|
||||
Button getCancelButton() {
|
||||
return (Button) uploadServiceChooserActivity.getDialog().findViewById(R.id.send_google_cancel);
|
||||
}
|
||||
|
||||
private CheckBox getMapsCheckBox() {
|
||||
return (CheckBox) uploadServiceChooserActivity.getDialog().findViewById(R.id.send_google_maps);
|
||||
}
|
||||
|
||||
private CheckBox getFusionTablesCheckBox() {
|
||||
return (CheckBox) uploadServiceChooserActivity.getDialog().findViewById(
|
||||
R.id.send_google_fusion_tables);
|
||||
}
|
||||
|
||||
private CheckBox getDocsCheckBox() {
|
||||
return (CheckBox) uploadServiceChooserActivity.getDialog().findViewById(R.id.send_google_docs);
|
||||
}
|
||||
|
||||
private RadioButton getNewMapRadioButton() {
|
||||
return (RadioButton) uploadServiceChooserActivity.getDialog().findViewById(
|
||||
R.id.send_google_new_map);
|
||||
}
|
||||
|
||||
private RadioButton getExistingMapRadioButton() {
|
||||
return (RadioButton) uploadServiceChooserActivity.getDialog().findViewById(
|
||||
R.id.send_google_existing_map);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user