forked from upstream-mirrors/OpenTracks
merge heads
This commit is contained in:
@@ -87,9 +87,9 @@ public class CsvTrackWriter implements TrackFormatWriter {
|
||||
|
||||
@Override
|
||||
public void writeHeader() {
|
||||
writeCommaSeparatedLine(context.getString(R.string.track_detail_track_name),
|
||||
context.getString(R.string.track_detail_activity_type_hint),
|
||||
context.getString(R.string.track_detail_track_description));
|
||||
writeCommaSeparatedLine(context.getString(R.string.track_edit_name),
|
||||
context.getString(R.string.track_edit_activity_type_hint),
|
||||
context.getString(R.string.track_edit_description));
|
||||
writeCommaSeparatedLine(track.getName(), track.getCategory(), track.getDescription());
|
||||
writeCommaSeparatedLine();
|
||||
}
|
||||
|
||||
+9
-1
@@ -21,6 +21,7 @@ import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesUtils;
|
||||
import com.google.android.apps.mytracks.io.maps.SendMapsUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
@@ -48,6 +49,7 @@ public class UploadResultActivity extends Activity {
|
||||
private SendRequest sendRequest;
|
||||
private Track track;
|
||||
private String shareUrl;
|
||||
private Dialog dialog;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -167,7 +169,8 @@ public class UploadResultActivity extends Activity {
|
||||
}
|
||||
});
|
||||
}
|
||||
return builder.create();
|
||||
dialog = builder.create();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,4 +189,9 @@ public class UploadResultActivity extends Activity {
|
||||
shareUrlOnly ? url : getString(R.string.share_track_url_body_format, url));
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.share_track_picker_title)));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Dialog getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.android.apps.mytracks.MapOverlay.CachedLocation;
|
||||
import com.google.android.maps.GeoPoint;
|
||||
import com.google.android.maps.Projection;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
@@ -138,4 +139,14 @@ public class DynamicSpeedTrackPathPainter implements TrackPathPainter {
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns coloredPaths.
|
||||
*
|
||||
* @return coloredPaths
|
||||
*/
|
||||
@VisibleForTesting
|
||||
List<ColoredPath> getColoredPaths() {
|
||||
return coloredPaths;
|
||||
}
|
||||
}
|
||||
+35
-20
@@ -19,6 +19,7 @@ import com.google.android.apps.mytracks.MapOverlay.CachedLocation;
|
||||
import com.google.android.maps.GeoPoint;
|
||||
import com.google.android.maps.Projection;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
@@ -29,16 +30,15 @@ import android.graphics.Rect;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* A path painter that not variates the path colors.
|
||||
*
|
||||
* @author Vangelis S.
|
||||
*
|
||||
* @author Vangelis S.
|
||||
*/
|
||||
public class SingleColorTrackPathPainter implements TrackPathPainter {
|
||||
private final Paint selectedTrackPaint;
|
||||
private Path path;
|
||||
|
||||
|
||||
public SingleColorTrackPathPainter(Context context) {
|
||||
selectedTrackPaint = TrackPathUtilities.getPaint(R.color.red, context);
|
||||
}
|
||||
@@ -47,49 +47,64 @@ public class SingleColorTrackPathPainter implements TrackPathPainter {
|
||||
public void drawTrack(Canvas canvas) {
|
||||
canvas.drawPath(path, selectedTrackPaint);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updatePath(Projection projection, Rect viewRect, int startLocationIdx,
|
||||
Boolean alwaysVisible, List<CachedLocation> points) {
|
||||
path = new Path();
|
||||
updatePath(projection, viewRect, startLocationIdx, alwaysVisible, points, path);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the path.
|
||||
*
|
||||
* @param projection The Canvas to draw upon.
|
||||
* @param viewRect The Path to be drawn.
|
||||
* @param startLocationIdx The start point from where update the path.
|
||||
* @param alwaysVisible Flag for always visible.
|
||||
* @param points The list of points used to update the path.
|
||||
* @param pathToUpdate The path to be created.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void updatePath(Projection projection, Rect viewRect, int startLocationIdx,
|
||||
Boolean alwaysVisible, List<CachedLocation> points, Path pathToUpdate) {
|
||||
pathToUpdate.incReserve(points.size());
|
||||
// Whether to start a new segment on new valid and visible point.
|
||||
boolean newSegment = startLocationIdx <= 0 || !points.get(startLocationIdx - 1).valid;
|
||||
boolean newSegment = startLocationIdx <= 0 || !points.get(startLocationIdx - 1).valid;
|
||||
boolean lastVisible = !newSegment;
|
||||
final Point pt = new Point();
|
||||
// Loop over track points.
|
||||
int numPoints = points.size();
|
||||
path = newPath();
|
||||
path.incReserve(numPoints);
|
||||
|
||||
for (int i = startLocationIdx; i < numPoints ; ++i) {
|
||||
for (int i = startLocationIdx; i < points.size(); ++i) {
|
||||
CachedLocation loc = points.get(i);
|
||||
|
||||
|
||||
// Check if valid, if not then indicate a new segment.
|
||||
if (!loc.valid) {
|
||||
newSegment = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
final GeoPoint geoPoint = loc.geoPoint;
|
||||
// Check if this breaks the existing segment.
|
||||
boolean visible = alwaysVisible
|
||||
boolean visible = alwaysVisible
|
||||
|| viewRect.contains(geoPoint.getLongitudeE6(), geoPoint.getLatitudeE6());
|
||||
if (!visible && !lastVisible) {
|
||||
// This is a point outside view not connected to a visible one.
|
||||
newSegment = true;
|
||||
}
|
||||
lastVisible = visible;
|
||||
|
||||
|
||||
// Either move to beginning of a new segment or continue the old one.
|
||||
projection.toPixels(geoPoint, pt);
|
||||
if (newSegment) {
|
||||
path.moveTo(pt.x, pt.y);
|
||||
pathToUpdate.moveTo(pt.x, pt.y);
|
||||
newSegment = false;
|
||||
} else {
|
||||
path.lineTo(pt.x, pt.y);
|
||||
pathToUpdate.lineTo(pt.x, pt.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
path = null;
|
||||
@@ -99,12 +114,12 @@ public class SingleColorTrackPathPainter implements TrackPathPainter {
|
||||
public boolean needsRedraw() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Path getLastPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
// Visible for testing
|
||||
public Path newPath() {
|
||||
return new Path();
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 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.services.ServiceUtils;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.net.Uri;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* A unit test for {@link TrackDetailActivity}.
|
||||
*
|
||||
* @author Bartlomiej Niechwiej
|
||||
*/
|
||||
public class TrackDetailActivityTest extends ActivityInstrumentationTestCase2<TrackDetailActivity>{
|
||||
private SharedPreferences sharedPreferences;
|
||||
private TrackRecordingServiceConnection serviceConnection;
|
||||
|
||||
public TrackDetailActivityTest() {
|
||||
super(TrackDetailActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
clearSelectedAndRecordingTracks();
|
||||
waitForIdle();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testInitialization_mainAction() {
|
||||
// Make sure we can start MyTracks and the activity doesn't start recording.
|
||||
assertInitialized();
|
||||
|
||||
// Check if not recording.
|
||||
assertFalse(isRecording());
|
||||
assertEquals(-1, getRecordingTrackId());
|
||||
}
|
||||
|
||||
public void testInitialization_viewActionWithNoData() {
|
||||
// Simulate start with ACTION_VIEW intent.
|
||||
Intent startIntent = new Intent();
|
||||
startIntent.setAction(Intent.ACTION_VIEW);
|
||||
setActivityIntent(startIntent);
|
||||
|
||||
assertInitialized();
|
||||
|
||||
// Check if not recording.
|
||||
assertFalse(isRecording());
|
||||
assertEquals(-1, getRecordingTrackId());
|
||||
}
|
||||
|
||||
public void testInitialization_viewActionWithValidData() throws Exception {
|
||||
// Simulate start with ACTION_VIEW intent.
|
||||
Intent startIntent = new Intent();
|
||||
startIntent.setAction(Intent.ACTION_VIEW);
|
||||
Uri uri = Uri.fromFile(File.createTempFile("valid", ".gpx", getActivity().getFilesDir()));
|
||||
|
||||
// TODO: Add a valid GPX.
|
||||
|
||||
startIntent.setData(uri);
|
||||
setActivityIntent(startIntent);
|
||||
|
||||
assertInitialized();
|
||||
|
||||
// Check if not recording.
|
||||
assertFalse(isRecording());
|
||||
assertEquals(-1, getRecordingTrackId());
|
||||
|
||||
// TODO: Finish this test.
|
||||
}
|
||||
|
||||
public void testInitialization_viewActionWithInvalidData() throws Exception {
|
||||
// Simulate start with ACTION_VIEW intent.
|
||||
Intent startIntent = new Intent();
|
||||
startIntent.setAction(Intent.ACTION_VIEW);
|
||||
Uri uri = Uri.fromFile(File.createTempFile("invalid", ".gpx", getActivity().getFilesDir()));
|
||||
startIntent.setData(uri);
|
||||
setActivityIntent(startIntent);
|
||||
|
||||
assertInitialized();
|
||||
|
||||
// Check if not recording.
|
||||
assertFalse(isRecording());
|
||||
assertEquals(-1, getRecordingTrackId());
|
||||
|
||||
// TODO: Finish this test.
|
||||
}
|
||||
|
||||
private void assertInitialized() {
|
||||
assertNotNull(getActivity());
|
||||
|
||||
serviceConnection = new TrackRecordingServiceConnection(getActivity(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits until the UI thread becomes idle.
|
||||
*/
|
||||
private void waitForIdle() throws InterruptedException {
|
||||
// Note: We can't use getInstrumentation().waitForIdleSync() here.
|
||||
final Object semaphore = new Object();
|
||||
synchronized (semaphore) {
|
||||
final AtomicBoolean isIdle = new AtomicBoolean();
|
||||
getInstrumentation().waitForIdle(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (semaphore) {
|
||||
isIdle.set(true);
|
||||
semaphore.notify();
|
||||
}
|
||||
}
|
||||
});
|
||||
while (!isIdle.get()) {
|
||||
semaphore.wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears {selected,recording}TrackId in the {@link #getSharedPreferences()}.
|
||||
*/
|
||||
private void clearSelectedAndRecordingTracks() {
|
||||
Editor editor = getSharedPreferences().edit();
|
||||
editor.putLong(getActivity().getString(R.string.selected_track_key), -1);
|
||||
editor.putLong(getActivity().getString(R.string.recording_track_key), -1);
|
||||
|
||||
editor.clear();
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits until the recording state changes to the given status.
|
||||
*
|
||||
* @param timeout the maximum time to wait, in milliseconds.
|
||||
* @param isRecording the final status to await.
|
||||
* @return the recording track ID.
|
||||
*/
|
||||
private long awaitRecordingStatus(long timeout, boolean isRecording)
|
||||
throws TimeoutException, InterruptedException {
|
||||
long startTime = System.nanoTime();
|
||||
while (isRecording() != isRecording) {
|
||||
if (System.nanoTime() - startTime > timeout * 1000000) {
|
||||
throw new TimeoutException("Timeout while waiting for recording!");
|
||||
}
|
||||
Thread.sleep(20);
|
||||
}
|
||||
waitForIdle();
|
||||
assertEquals(isRecording, isRecording());
|
||||
return getRecordingTrackId();
|
||||
}
|
||||
|
||||
private long getRecordingTrackId() {
|
||||
return getSharedPreferences().getLong(getActivity().getString(R.string.recording_track_key), -1);
|
||||
}
|
||||
|
||||
private SharedPreferences getSharedPreferences() {
|
||||
if (sharedPreferences == null) {
|
||||
sharedPreferences = getActivity().getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
}
|
||||
return sharedPreferences;
|
||||
}
|
||||
|
||||
private boolean isRecording() {
|
||||
return ServiceUtils.isRecording(getActivity(),
|
||||
serviceConnection.getServiceIfBound(), getSharedPreferences());
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -65,7 +65,7 @@ public class DescriptionGeneratorImplTest extends AndroidTestCase {
|
||||
+ "Max speed: 360.00 km/h (223.7 mi/h)<br>"
|
||||
+ "Average pace: 0.50 min/km (0.8 min/mi)<br>"
|
||||
+ "Average moving pace: 0.25 min/km (0.4 min/mi)<br>"
|
||||
+ "Min pace: 0.17 min/km (0.3 min/mi)<br>"
|
||||
+ "Fastest pace: 0.17 min/km (0.3 min/mi)<br>"
|
||||
+ "Max elevation: 550 m (1804 ft)<br>"
|
||||
+ "Min elevation: -500 m (-1640 ft)<br>"
|
||||
+ "Elevation gain: 6000 m (19685 ft)<br>"
|
||||
@@ -101,7 +101,7 @@ public class DescriptionGeneratorImplTest extends AndroidTestCase {
|
||||
+ "Max speed: 360.00 km/h (223.7 mi/h)\n"
|
||||
+ "Average pace: 0.50 min/km (0.8 min/mi)\n"
|
||||
+ "Average moving pace: 0.25 min/km (0.4 min/mi)\n"
|
||||
+ "Min pace: 0.17 min/km (0.3 min/mi)\n"
|
||||
+ "Fastest pace: 0.17 min/km (0.3 min/mi)\n"
|
||||
+ "Max elevation: 550 m (1804 ft)\n"
|
||||
+ "Min elevation: -500 m (-1640 ft)\n"
|
||||
+ "Elevation gain: 6000 m (19685 ft)\n"
|
||||
|
||||
@@ -29,7 +29,7 @@ public class CsvTrackWriterTest extends TrackFormatWriterTest {
|
||||
|
||||
public void testCsvOutput() throws Exception {
|
||||
String expectedTrackHeader = getExpectedLine(
|
||||
"Track name", "Activity type", "Track description");
|
||||
"Name", "Activity type", "Description");
|
||||
String expectedTrack = getExpectedLine(TRACK_NAME, TRACK_CATEGORY, TRACK_DESCRIPTION);
|
||||
String expectedMarkerHeader = getExpectedLine("Marker name", "Marker type",
|
||||
"Marker description", "Latitude (deg)", "Longitude (deg)", "Altitude (m)", "Bearing (deg)",
|
||||
|
||||
+21
-79
@@ -13,38 +13,26 @@
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.google.android.apps.mytracks.io.sendtogoogle;
|
||||
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.jayway.android.robotium.solo.Solo;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Tests the {@link UploadResultActivity}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class UploadResultActivityTest extends
|
||||
ActivityInstrumentationTestCase2<UploadResultActivity> {
|
||||
public class UploadResultActivityTest
|
||||
extends ActivityInstrumentationTestCase2<UploadResultActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private UploadResultActivity uploadResultActivity;
|
||||
private Solo solo;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
solo = new Solo(instrumentation);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is necessary for ActivityInstrumentationTestCase2.
|
||||
@@ -58,27 +46,9 @@ public class UploadResultActivityTest extends
|
||||
*/
|
||||
public void testAllSuccess() {
|
||||
initialActivity(true, true, true, true, true, true);
|
||||
|
||||
HashSet<String> stringHashSet = new HashSet<String>();
|
||||
ArrayList<View> view = solo.getViews();
|
||||
for (View oneView : view) {
|
||||
if (oneView instanceof TextView && oneView.isShown()) {
|
||||
stringHashSet.add((String) ((TextView) oneView).getText());
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.generic_success_title)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_maps)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_fusion_tables)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_docs)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_success_footer)));
|
||||
|
||||
assertFalse(stringHashSet
|
||||
.contains(uploadResultActivity.getString(R.string.generic_error_title)));
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_error)));
|
||||
Dialog dialog = uploadResultActivity.getDialog();
|
||||
TextView textView = (TextView) dialog.findViewById(R.id.upload_result_success_footer);
|
||||
assertTrue(textView.isShown());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,26 +57,9 @@ public class UploadResultActivityTest extends
|
||||
public void testAllFailed() {
|
||||
// Send all kinds but all failed.
|
||||
initialActivity(true, true, true, false, false, false);
|
||||
HashSet<String> stringHashSet = new HashSet<String>();
|
||||
ArrayList<View> view = solo.getViews();
|
||||
for (View oneView : view) {
|
||||
if (oneView instanceof TextView && oneView.isShown()) {
|
||||
stringHashSet.add((String) ((TextView) oneView).getText());
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(stringHashSet.contains((Object) uploadResultActivity
|
||||
.getString(R.string.generic_error_title)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_maps)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_fusion_tables)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_docs)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_error)));
|
||||
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.generic_success_title)));
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_success_footer)));
|
||||
Dialog dialog = uploadResultActivity.getDialog();
|
||||
TextView textView = (TextView) dialog.findViewById(R.id.upload_result_error_footer);
|
||||
assertTrue(textView.isShown());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,26 +72,16 @@ public class UploadResultActivityTest extends
|
||||
*/
|
||||
public void testPartialSuccess() {
|
||||
initialActivity(true, false, true, true, false, false);
|
||||
|
||||
HashSet<String> stringHashSet = new HashSet<String>();
|
||||
ArrayList<View> view = solo.getViews();
|
||||
for (View oneView : view) {
|
||||
if (oneView instanceof TextView && oneView.isShown()) {
|
||||
stringHashSet.add((String) ((TextView) oneView).getText());
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.generic_error_title)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_maps)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_docs)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_error)));
|
||||
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_fusion_tables)));
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.generic_success_title)));
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_success_footer)));
|
||||
Dialog dialog = uploadResultActivity.getDialog();
|
||||
TextView textView = (TextView) dialog.findViewById(R.id.upload_result_error_footer);
|
||||
assertTrue(textView.isShown());
|
||||
LinearLayout mapsResult = (LinearLayout) dialog.findViewById(R.id.upload_result_maps_result);
|
||||
assertTrue(mapsResult.isShown());
|
||||
LinearLayout fusionTablesResult = (LinearLayout) dialog.findViewById(
|
||||
R.id.upload_result_fusion_tables_result);
|
||||
assertFalse(fusionTablesResult.isShown());
|
||||
LinearLayout docsResult = (LinearLayout) dialog.findViewById(R.id.upload_result_docs_result);
|
||||
assertTrue(docsResult.isShown());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,5 +108,4 @@ public class UploadResultActivityTest extends
|
||||
setActivityIntent(intent);
|
||||
uploadResultActivity = this.getActivity();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.ColoredPath;
|
||||
import com.google.android.apps.mytracks.MapOverlay.CachedLocation;
|
||||
import com.google.android.apps.mytracks.TrackStubUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.android.testing.mocking.AndroidMock;
|
||||
import com.google.android.testing.mocking.UsesMocks;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests for the {@link DynamicSpeedTrackPathPainter}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class DynamicSpeedTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
|
||||
private DynamicSpeedTrackPathPainter dynamicSpeedTrackPathPainter;
|
||||
private TrackPathDescriptor trackPathDescriptor;
|
||||
// This number must bigger than 10 to meet the requirement of test.
|
||||
private static final int NUMBER_OF_LOCATIONS = 100;
|
||||
private static final int LOCATIONS_PER_SEGMENT = 25;
|
||||
// The maximum speed(KM/H) which is considered slow.
|
||||
private static final int SLOW_SPEED_KMH = 30;
|
||||
// The maximum speed(KM/H) which is considered normal.
|
||||
private static final int NORMAL_SPEED_KMH = 50;
|
||||
|
||||
// Convert from kilometers per hour to meters per second
|
||||
private static final double KMH_TO_MS = 1 / 3.6;
|
||||
private static final int SLOW_SPEED_MS = (int) (SLOW_SPEED_KMH * KMH_TO_MS);
|
||||
private static final int NORMAL_SPEED_MS = (int) (NORMAL_SPEED_KMH * KMH_TO_MS);
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
initialTrackPathDescriptorMock();
|
||||
dynamicSpeedTrackPathPainter = new DynamicSpeedTrackPathPainter(getContext(),
|
||||
trackPathDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link DynamicSpeedTrackPathPainter#updatePath(com.google.android.maps.Projection, android.graphics.Rect, int, Boolean, java.util.List)}
|
||||
* when all locations are invalid.
|
||||
*/
|
||||
public void testUpdatePath_AllInvalidLocation() {
|
||||
List<CachedLocation> points = createCachedLocations(NUMBER_OF_LOCATIONS, INVALID_LATITUDE, -1);
|
||||
dynamicSpeedTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), 1, true, points);
|
||||
AndroidMock.verify(trackPathDescriptor);
|
||||
// Should be zero for there is no valid locations.
|
||||
assertEquals(0, dynamicSpeedTrackPathPainter.getColoredPaths().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link DynamicSpeedTrackPathPainter#updatePath(com.google.android.maps.Projection, android.graphics.Rect, int, Boolean, java.util.List)}
|
||||
* when all locations are valid.
|
||||
*/
|
||||
public void testUpdatePath_AllValidLocation() {
|
||||
List<CachedLocation> points = createCachedLocations(NUMBER_OF_LOCATIONS,
|
||||
TrackStubUtils.INITIAL_LATITUDE, -1);
|
||||
|
||||
// Gets a number as the start index of points.
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
dynamicSpeedTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points);
|
||||
|
||||
AndroidMock.verify(trackPathDescriptor);
|
||||
assertEquals(NUMBER_OF_LOCATIONS - startLocationIdx, dynamicSpeedTrackPathPainter
|
||||
.getColoredPaths().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link DynamicSpeedTrackPathPainter#updatePath(com.google.android.maps.Projection, android.graphics.Rect, int, Boolean, java.util.List)}
|
||||
* when all locations are valid. This test setups 4 segments with 25 points
|
||||
* each. The first segment has slow speed, the second segment has normal
|
||||
* speed, the third segment has fast speed, and the fourth segment has slow
|
||||
* speed.
|
||||
*/
|
||||
public void testUpdatePath_CheckColoredPath() {
|
||||
// Gets the slow speed. Divide SLOW_SPEED by 2 to make it smaller than
|
||||
// SLOW_SPEED. Speed in MyTracksLocation use MS, but speed in CachedLocation
|
||||
// use KMH.
|
||||
int slowSpeed = SLOW_SPEED_MS / 2;
|
||||
// Gets the normal speed. Makes it smaller than SLOW_SPEED and bigger than
|
||||
// NORMAL_SPEED. Speed in MyTracksLocation use MS, but speed in
|
||||
// CachedLocation use KMH.
|
||||
int normalSpeed = (SLOW_SPEED_MS + NORMAL_SPEED_MS) / 2;
|
||||
// Gets the fast speed. Multiply it by 2 to make it bigger than
|
||||
// NORMAL_SPEED. Speed in MyTracksLocation use MS, but speed in
|
||||
// CachedLocation use KMH.
|
||||
int fastSpeed = NORMAL_SPEED_MS * 2;
|
||||
|
||||
// Get a number of startLocationIdx. And divide NUMBER_OF_LOCATIONS by 8 to
|
||||
// make sure it is less than numberOfFirstThreeSegments.
|
||||
int startLocationIdx = LOCATIONS_PER_SEGMENT / 2;
|
||||
|
||||
List<CachedLocation> points = createCachedLocations(LOCATIONS_PER_SEGMENT,
|
||||
TrackStubUtils.INITIAL_LATITUDE, slowSpeed);
|
||||
points.addAll(createCachedLocations(LOCATIONS_PER_SEGMENT, TrackStubUtils.INITIAL_LATITUDE,
|
||||
normalSpeed));
|
||||
points.addAll(createCachedLocations(LOCATIONS_PER_SEGMENT, TrackStubUtils.INITIAL_LATITUDE,
|
||||
fastSpeed));
|
||||
points.addAll(createCachedLocations(LOCATIONS_PER_SEGMENT, TrackStubUtils.INITIAL_LATITUDE,
|
||||
slowSpeed));
|
||||
|
||||
dynamicSpeedTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points);
|
||||
|
||||
AndroidMock.verify(trackPathDescriptor);
|
||||
List<ColoredPath> coloredPath = dynamicSpeedTrackPathPainter.getColoredPaths();
|
||||
assertEquals(NUMBER_OF_LOCATIONS - startLocationIdx, coloredPath.size());
|
||||
|
||||
// Checks different speeds with different color in the coloredPath.
|
||||
for (int i = 0; i < NUMBER_OF_LOCATIONS - startLocationIdx; i++) {
|
||||
if (i < LOCATIONS_PER_SEGMENT - startLocationIdx) {
|
||||
// Slow.
|
||||
assertEquals(getContext().getResources().getColor(R.color.slow_path), coloredPath.get(i)
|
||||
.getPathPaint().getColor());
|
||||
} else if (i < LOCATIONS_PER_SEGMENT * 2 - startLocationIdx) {
|
||||
// Normal.
|
||||
assertEquals(getContext().getResources().getColor(R.color.normal_path), coloredPath.get(i)
|
||||
.getPathPaint().getColor());
|
||||
} else if (i < LOCATIONS_PER_SEGMENT * 3 - startLocationIdx) {
|
||||
// Fast.
|
||||
assertEquals(getContext().getResources().getColor(R.color.fast_path), coloredPath.get(i)
|
||||
.getPathPaint().getColor());
|
||||
} else {
|
||||
// Slow.
|
||||
assertEquals(getContext().getResources().getColor(R.color.slow_path), coloredPath.get(i)
|
||||
.getPathPaint().getColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initials a mocked TrackPathDescriptor object.
|
||||
*/
|
||||
@UsesMocks(TrackPathDescriptor.class)
|
||||
private void initialTrackPathDescriptorMock() {
|
||||
trackPathDescriptor = AndroidMock.createMock(TrackPathDescriptor.class);
|
||||
AndroidMock.expect(trackPathDescriptor.getSlowSpeed()).andReturn(SLOW_SPEED_KMH);
|
||||
AndroidMock.expect(trackPathDescriptor.getNormalSpeed()).andReturn(NORMAL_SPEED_KMH);
|
||||
AndroidMock.replay(trackPathDescriptor);
|
||||
}
|
||||
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.MapOverlay.CachedLocation;
|
||||
import com.google.android.apps.mytracks.TrackStubUtils;
|
||||
import com.google.android.testing.mocking.AndroidMock;
|
||||
import com.google.android.testing.mocking.UsesMocks;
|
||||
|
||||
import android.graphics.Path;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests for the {@link SingleColorTrackPathPainter}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
|
||||
private SingleColorTrackPathPainter singleColorTrackPathPainter;
|
||||
private Path pathMock;
|
||||
private static final int NUMBER_OF_LOCATIONS = 100;
|
||||
|
||||
/**
|
||||
* Initials a mocked TrackPathDescriptor object and
|
||||
* singleColorTrackPathPainter.
|
||||
*/
|
||||
@Override
|
||||
@UsesMocks(Path.class)
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
pathMock = AndroidMock.createStrictMock(Path.class);
|
||||
singleColorTrackPathPainter = new SingleColorTrackPathPainter(getContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link SingleColorTrackPathPainter#updatePath(com.google.android.maps.Projection, android.graphics.Rect, int, Boolean, List, Path)}
|
||||
* method when all locations are valid.
|
||||
*/
|
||||
public void testUpdatePath_AllValidLocation() {
|
||||
pathMock.incReserve(NUMBER_OF_LOCATIONS);
|
||||
List<CachedLocation> points = createCachedLocations(NUMBER_OF_LOCATIONS,
|
||||
TrackStubUtils.INITIAL_LATITUDE, -1);
|
||||
// Gets a number as the start index of points.
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
|
||||
for (int i = startLocationIdx; i < NUMBER_OF_LOCATIONS; i++) {
|
||||
pathMock.lineTo(0, 0);
|
||||
}
|
||||
|
||||
AndroidMock.replay(pathMock);
|
||||
singleColorTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points, pathMock);
|
||||
AndroidMock.verify(pathMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link SingleColorTrackPathPainter#updatePath(com.google.android.maps.Projection, android.graphics.Rect, int, Boolean, List, Path)}
|
||||
* method when all locations are invalid.
|
||||
*/
|
||||
public void testUpdatePath_AllInvalidLocation() {
|
||||
pathMock.incReserve(NUMBER_OF_LOCATIONS);
|
||||
List<CachedLocation> points = createCachedLocations(NUMBER_OF_LOCATIONS, INVALID_LATITUDE, -1);
|
||||
// Gets a random number from 1 to numberOfLocations.
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
AndroidMock.replay(pathMock);
|
||||
singleColorTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points, pathMock);
|
||||
AndroidMock.verify(pathMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link SingleColorTrackPathPainter#updatePath(com.google.android.maps.Projection, android.graphics.Rect, int, Boolean, List, Path)}
|
||||
* method when there are three segments.
|
||||
*/
|
||||
public void testUpdatePath_ThreeSegments() {
|
||||
// First segment.
|
||||
List<CachedLocation> points = createCachedLocations(NUMBER_OF_LOCATIONS,
|
||||
TrackStubUtils.INITIAL_LATITUDE, -1);
|
||||
points.addAll(createCachedLocations(1, INVALID_LATITUDE, -1));
|
||||
// Second segment.
|
||||
points.addAll(createCachedLocations(NUMBER_OF_LOCATIONS, TrackStubUtils.INITIAL_LATITUDE, -1));
|
||||
points.addAll(createCachedLocations(1, INVALID_LATITUDE, -1));
|
||||
// Third segment.
|
||||
points.addAll(createCachedLocations(NUMBER_OF_LOCATIONS, TrackStubUtils.INITIAL_LATITUDE, -1));
|
||||
// Gets a random number from 1 to numberOfLocations.
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
pathMock.incReserve(NUMBER_OF_LOCATIONS *3 + 1 +1);
|
||||
for (int i = 0; i < NUMBER_OF_LOCATIONS - startLocationIdx; i++) {
|
||||
pathMock.lineTo(0, 0);
|
||||
}
|
||||
pathMock.moveTo(0, 0);
|
||||
for (int i = 0; i < NUMBER_OF_LOCATIONS - 1; i++) {
|
||||
pathMock.lineTo(0, 0);
|
||||
}
|
||||
pathMock.moveTo(0, 0);
|
||||
for (int i = 0; i < NUMBER_OF_LOCATIONS - 1; i++) {
|
||||
pathMock.lineTo(0, 0);
|
||||
}
|
||||
|
||||
AndroidMock.replay(pathMock);
|
||||
singleColorTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points, pathMock);
|
||||
AndroidMock.verify(pathMock);
|
||||
}
|
||||
}
|
||||
@@ -15,22 +15,32 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.MapOverlay;
|
||||
import com.google.android.apps.mytracks.MapOverlay.CachedLocation;
|
||||
import com.google.android.apps.mytracks.MockMyTracksOverlay;
|
||||
import com.google.android.apps.mytracks.TrackStubUtils;
|
||||
import com.google.android.maps.MapView;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.location.Location;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests for the MyTracks track path descriptors and painters.
|
||||
*
|
||||
* @author Vangelis S.
|
||||
*/
|
||||
public class TrackPathPainterTestCase extends AndroidTestCase {
|
||||
|
||||
protected Canvas canvas;
|
||||
protected MockMyTracksOverlay myTracksOverlay;
|
||||
protected MapView mockView;
|
||||
|
||||
final int INVALID_LATITUDE = 100;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -40,4 +50,27 @@ public class TrackPathPainterTestCase extends AndroidTestCase {
|
||||
myTracksOverlay.setTrackDrawingEnabled(true);
|
||||
mockView = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list of CachedLocations.
|
||||
*
|
||||
* @param number the number of locations
|
||||
* @param latitude the latitude value of locations.
|
||||
* @param speed the speed(meter per second) of locations, and will give a default valid value if
|
||||
* less than zero
|
||||
* @return the simulated locations
|
||||
*/
|
||||
List<CachedLocation> createCachedLocations(int number, double latitude, float speed) {
|
||||
List<CachedLocation> points = new ArrayList<MapOverlay.CachedLocation>();
|
||||
for (int i = 0; i < number; ++i) {
|
||||
Location location = TrackStubUtils.createMyTracksLocation(latitude,
|
||||
TrackStubUtils.INITIAL_LONGITUDE, TrackStubUtils.INITIAL_ALTITUDE);
|
||||
if (speed > 0) {
|
||||
location.setSpeed(speed);
|
||||
}
|
||||
CachedLocation cachedLocation = new CachedLocation(location);
|
||||
points.add(cachedLocation);
|
||||
}
|
||||
return points;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-9
@@ -1,8 +1,6 @@
|
||||
package com.google.android.apps.mytracks.services.sensors;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.services.sensors.ant.AntDirectSensorManager;
|
||||
import com.google.android.apps.mytracks.services.sensors.ant.AntSrmBridgeSensorManager;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -35,13 +33,8 @@ public class SensorManagerFactoryTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testCreateAnt() throws Exception {
|
||||
assertClassForName(AntDirectSensorManager.class, R.string.sensor_type_value_ant);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testCreateAntSRM() throws Exception {
|
||||
assertClassForName(AntSrmBridgeSensorManager.class, R.string.sensor_type_value_srm_ant_bridge);
|
||||
public void testCreatePolar() throws Exception {
|
||||
assertClassForName(PolarSensorManager.class, R.string.sensor_type_value_polar);
|
||||
}
|
||||
|
||||
private void assertClassForName(Class<?> c, int i) {
|
||||
|
||||
Reference in New Issue
Block a user