diff --git a/MyTracks/res/values/strings.xml b/MyTracks/res/values/strings.xml
index e51ba1a79..b6a28e4dd 100644
--- a/MyTracks/res/values/strings.xml
+++ b/MyTracks/res/values/strings.xml
@@ -2196,7 +2196,7 @@ limitations under the License.
- You don\'t have any recorded tracks. Click on the record button to start a new recording.
+ Click on the record button to start recording your next adventure.
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 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 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 = 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);
+ }
+
+}
diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainterTest.java
new file mode 100644
index 000000000..1679c547a
--- /dev/null
+++ b/MyTracksTest/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainterTest.java
@@ -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 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 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 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);
+ }
+}
diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/maps/TrackPathPainterTestCase.java b/MyTracksTest/src/com/google/android/apps/mytracks/maps/TrackPathPainterTestCase.java
index 59ceb94fd..b53909b6e 100644
--- a/MyTracksTest/src/com/google/android/apps/mytracks/maps/TrackPathPainterTestCase.java
+++ b/MyTracksTest/src/com/google/android/apps/mytracks/maps/TrackPathPainterTestCase.java
@@ -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 createCachedLocations(int number, double latitude, float speed) {
+ List points = new ArrayList();
+ 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;
+ }
}