forked from upstream-mirrors/OpenTracks
Merge Heads
This commit is contained in:
@@ -1,9 +1,23 @@
|
||||
// Copyright 2010 Google Inc. All Rights Reserved.
|
||||
/*
|
||||
* 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.io.file;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksLocation;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.apps.mytracks.util.FileUtils;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +25,7 @@ import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Tests for the GPX track exporter.
|
||||
* Tests for {@link TcxTrackWriter}.
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
@@ -37,42 +51,46 @@ public class TcxTrackWriterTest extends TrackFormatWriterTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given tags describe the given points, in the same order.
|
||||
* Asserts that the given tags describe the given locations in the same order.
|
||||
*
|
||||
* @param tags list of tags
|
||||
* @param locations list of locations
|
||||
*/
|
||||
private void assertTagsMatchPoints(List<Element> tags, MyTracksLocation... locs) {
|
||||
assertEquals(locs.length, tags.size());
|
||||
for (int i = 0; i < locs.length; i++) {
|
||||
Element tag = tags.get(i);
|
||||
MyTracksLocation loc = locs[i];
|
||||
|
||||
assertTagMatchesLocation(tag, loc);
|
||||
private void assertTagsMatchPoints(List<Element> tags, MyTracksLocation... locations) {
|
||||
assertEquals(locations.length, tags.size());
|
||||
for (int i = 0; i < locations.length; i++) {
|
||||
assertTagMatchesLocation(tags.get(i), locations[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given tag describes the given location.
|
||||
*
|
||||
* @param tag the tag
|
||||
* @param location the location
|
||||
*/
|
||||
private void assertTagMatchesLocation(Element tag, MyTracksLocation loc) {
|
||||
Element posTag = getChildElement(tag, "Position");
|
||||
assertEquals(Double.toString(loc.getLatitude()),
|
||||
getChildTextValue(posTag, "LatitudeDegrees"));
|
||||
assertEquals(Double.toString(loc.getLongitude()),
|
||||
getChildTextValue(posTag, "LongitudeDegrees"));
|
||||
private void assertTagMatchesLocation(Element tag, MyTracksLocation location) {
|
||||
assertEquals(StringUtils.formatDateTimeIso8601(location.getTime()), getChildTextValue(tag, "Time"));
|
||||
|
||||
assertEquals(FileUtils.FILE_TIMESTAMP_FORMAT.format(loc.getTime()),
|
||||
getChildTextValue(tag, "Time"));
|
||||
assertEquals(Double.toString(loc.getAltitude()),
|
||||
getChildTextValue(tag, "AltitudeMeters"));
|
||||
assertTrue(loc.getSensorDataSet() != null);
|
||||
Sensor.SensorDataSet sds = loc.getSensorDataSet();
|
||||
Element positionTag = getChildElement(tag, "Position");
|
||||
assertEquals(
|
||||
Double.toString(location.getLatitude()), getChildTextValue(positionTag, "LatitudeDegrees"));
|
||||
assertEquals(Double.toString(location.getLongitude()),
|
||||
getChildTextValue(positionTag, "LongitudeDegrees"));
|
||||
|
||||
List<Element> bpm = getChildElements(tag, "HeartRateBpm", 1);
|
||||
assertEquals(Double.toString(location.getAltitude()), getChildTextValue(tag, "AltitudeMeters"));
|
||||
assertTrue(location.getSensorDataSet() != null);
|
||||
Sensor.SensorDataSet sds = location.getSensorDataSet();
|
||||
|
||||
List<Element> heartRate = getChildElements(tag, "HeartRateBpm", 1);
|
||||
assertEquals(Integer.toString(sds.getHeartRate().getValue()),
|
||||
getChildTextValue(bpm.get(0), "Value"));
|
||||
getChildTextValue(heartRate.get(0), "Value"));
|
||||
|
||||
List<Element> ext = getChildElements(tag, "Extensions", 1);
|
||||
List<Element> tpx = getChildElements(ext.get(0), "TPX", 1);
|
||||
assertEquals(Integer.toString(sds.getPower().getValue()),
|
||||
getChildTextValue(tpx.get(0), "Watts"));
|
||||
List<Element> extensions = getChildElements(tag, "Extensions", 1);
|
||||
List<Element> tpx = getChildElements(extensions.get(0), "TPX", 1);
|
||||
assertEquals(
|
||||
Integer.toString(sds.getCadence().getValue()), getChildTextValue(tpx.get(0), "RunCadence"));
|
||||
assertEquals(
|
||||
Integer.toString(sds.getPower().getValue()), getChildTextValue(tpx.get(0), "Watts"));
|
||||
}
|
||||
}
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.fusiontables;
|
||||
|
||||
import com.google.android.apps.mytracks.io.docs.SendDocsActivity;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
/**
|
||||
* Tests the {@link SendFusionTablesActivity}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class SendFusionTablesActivityTest extends AndroidTestCase {
|
||||
|
||||
private SendFusionTablesActivity sendFusionTablesActivity;
|
||||
private SendRequest sendRequest;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
sendRequest = new SendRequest(1L, true, false, true);
|
||||
sendFusionTablesActivity = new SendFusionTablesActivity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link SendFusionTablesActivity#getNextClass(SendRequest, boolean)}. Sets
|
||||
* the flags of "sendDocs" and "cancel" to false and false.
|
||||
*/
|
||||
public void testGetNextClass_notCancelNotSendDocs() {
|
||||
sendRequest.setSendDocs(false);
|
||||
Class<?> next = sendFusionTablesActivity.getNextClass(sendRequest, false);
|
||||
assertEquals(UploadResultActivity.class, next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link SendFusionTablesActivity#getNextClass(SendRequest, boolean)}. Sets
|
||||
* the flags of "sendDocs" and "cancel" to true and false.
|
||||
*/
|
||||
public void testGetNextClass_notCancelSendDocs() {
|
||||
sendRequest.setSendDocs(true);
|
||||
Class<?> next = sendFusionTablesActivity.getNextClass(sendRequest, false);
|
||||
assertEquals(SendDocsActivity.class, next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link SendFusionTablesActivity#getNextClass(SendRequest,boolean)}. Sets
|
||||
* the flags of "sendDocs" and "cancel" to true and true.
|
||||
*/
|
||||
public void testGetNextClass_cancelSendDocs() {
|
||||
sendRequest.setSendDocs(true);
|
||||
Class<?> next = sendFusionTablesActivity.getNextClass(sendRequest, true);
|
||||
assertEquals(UploadResultActivity.class, next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link SendFusionTablesActivity#getNextClass(SendRequest,boolean)}. Sets
|
||||
* the flags of "sendDocs" and "cancel" to false and true.
|
||||
*/
|
||||
public void testGetNextClass_cancelNotSendDocs() {
|
||||
sendRequest.setSendDocs(false);
|
||||
Class<?> next = sendFusionTablesActivity.getNextClass(sendRequest, true);
|
||||
assertEquals(UploadResultActivity.class, next);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.io.gdata.maps.MapsMapMetadata;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests the {@link ChooseMapActivity}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class ChooseMapActivityTest extends AndroidTestCase {
|
||||
|
||||
private static final String MAP_ID = "mapid";
|
||||
private static final String MAP_TITLE = "title";
|
||||
private static final String MAP_DESC = "desc";
|
||||
|
||||
private ArrayList<String> mapIds = new ArrayList<String>();
|
||||
private ArrayList<MapsMapMetadata> mapDatas = new ArrayList<MapsMapMetadata>();
|
||||
private boolean errorDialogShown = false;
|
||||
private boolean progressDialogRemoved = false;
|
||||
|
||||
/**
|
||||
* Creates a class to override some methods of {@link ChooseMapActivity} to
|
||||
* makes it testable.
|
||||
*
|
||||
* @author youtaol
|
||||
*/
|
||||
public class ChooseMapActivityMock extends ChooseMapActivity {
|
||||
/**
|
||||
* By overriding this method, avoids to start next activity.
|
||||
*/
|
||||
@Override
|
||||
public void startActivity(Intent intent) {}
|
||||
|
||||
/**
|
||||
* By overriding this method, avoids to show an error dialog and set the
|
||||
* show flag to true.
|
||||
*/
|
||||
@Override
|
||||
public void showErrorDialog() {
|
||||
errorDialogShown = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* By overriding this method, avoids to show an error dialog and set the
|
||||
* show flag to true.
|
||||
*/
|
||||
@Override
|
||||
public void removeProgressDialog() {
|
||||
progressDialogRemoved = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link ChooseMapActivity#onAsyncTaskCompleted(boolean, ArrayList, ArrayList)}
|
||||
* . An alert dialog should be shown when there is no map.
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void testOnAsyncTaskCompleted_fail() {
|
||||
ChooseMapActivityMock chooseMapActivityMock = new ChooseMapActivityMock();
|
||||
errorDialogShown = false;
|
||||
progressDialogRemoved = false;
|
||||
chooseMapActivityMock.onAsyncTaskCompleted(false, null, null);
|
||||
assertTrue(progressDialogRemoved);
|
||||
assertTrue(errorDialogShown);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link ChooseMapActivity#onAsyncTaskCompleted(boolean, ArrayList, ArrayList)}
|
||||
* . Check the logic when there is only map.
|
||||
*/
|
||||
public void testOnAsyncTaskCompleted_success_oneMap() {
|
||||
ChooseMapActivityMock chooseMapActivityMock = new ChooseMapActivityMock();
|
||||
chooseMapActivityMock.arrayAdapter = new ArrayAdapter<ChooseMapActivity.ListItem>(getContext(),
|
||||
R.layout.choose_map_item);
|
||||
simulateMaps(1);
|
||||
chooseMapActivityMock.onAsyncTaskCompleted(true, mapIds, mapDatas);
|
||||
assertEquals(1, chooseMapActivityMock.arrayAdapter.getCount());
|
||||
assertEquals(MAP_ID + "0", chooseMapActivityMock.arrayAdapter.getItem(0).getMapId());
|
||||
assertEquals(MAP_TITLE + "0", chooseMapActivityMock.arrayAdapter.getItem(0).getMapData()
|
||||
.getTitle());
|
||||
assertEquals(MAP_DESC + "0", chooseMapActivityMock.arrayAdapter.getItem(0).getMapData()
|
||||
.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link ChooseMapActivity#onAsyncTaskCompleted(boolean, ArrayList, ArrayList)}
|
||||
* . Check the logic when there are 10 maps.
|
||||
*/
|
||||
public void testOnAsyncTaskCompleted_success_twoMaps() {
|
||||
ChooseMapActivityMock chooseMapActivityMock = new ChooseMapActivityMock();
|
||||
chooseMapActivityMock.arrayAdapter = new ArrayAdapter<ChooseMapActivity.ListItem>(getContext(),
|
||||
R.layout.choose_map_item);
|
||||
simulateMaps(10);
|
||||
chooseMapActivityMock.onAsyncTaskCompleted(true, mapIds, mapDatas);
|
||||
assertEquals(10, chooseMapActivityMock.arrayAdapter.getCount());
|
||||
assertEquals(MAP_ID + "9", chooseMapActivityMock.arrayAdapter.getItem(9).getMapId());
|
||||
assertEquals(MAP_TITLE + "9", chooseMapActivityMock.arrayAdapter.getItem(9).getMapData()
|
||||
.getTitle());
|
||||
assertEquals(MAP_DESC + "9", chooseMapActivityMock.arrayAdapter.getItem(9).getMapData()
|
||||
.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates map data for the test.
|
||||
*
|
||||
* @param number of data should be simulated.
|
||||
*/
|
||||
private void simulateMaps(int number) {
|
||||
mapIds = new ArrayList<String>();
|
||||
mapDatas = new ArrayList<MapsMapMetadata>();
|
||||
for (int i = 0; i < number; i++) {
|
||||
mapIds.add(MAP_ID + i);
|
||||
MapsMapMetadata metaData = new MapsMapMetadata();
|
||||
metaData.setTitle(MAP_TITLE + i);
|
||||
metaData.setDescription(MAP_DESC + i);
|
||||
metaData.setSearchable(true);
|
||||
mapDatas.add(metaData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.io.docs.SendDocsActivity;
|
||||
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesActivity;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
/**
|
||||
* Tests the {@link SendMapsActivity}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class SendMapsActivityTest extends AndroidTestCase {
|
||||
|
||||
private SendMapsActivity sendMapsActivity;
|
||||
private SendRequest sendRequest;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
sendRequest = new SendRequest(1L, true, false, true);
|
||||
sendMapsActivity = new SendMapsActivity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link SendMapsActivity#getNextClass(SendRequest, boolean)}. Sets the flags
|
||||
* of "sendFusionTables","sendDocs" and "cancel" to true, true and false.
|
||||
*/
|
||||
public void testGetNextClass_notCancelSendFusionTables() {
|
||||
sendRequest.setSendFusionTables(true);
|
||||
sendRequest.setSendDocs(true);
|
||||
Class<?> next = sendMapsActivity.getNextClass(sendRequest, false);
|
||||
assertEquals(SendFusionTablesActivity.class, next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link SendMapsActivity#getNextClass(SendRequest, boolean)}. Sets the flags
|
||||
* of "sendFusionTables","sendDocs" and "cancel" to false, true and false.
|
||||
*/
|
||||
public void testGetNextClass_notCancelSendDocs() {
|
||||
sendRequest.setSendFusionTables(false);
|
||||
sendRequest.setSendDocs(true);
|
||||
Class<?> next = sendMapsActivity.getNextClass(sendRequest, false);
|
||||
assertEquals(SendDocsActivity.class, next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link SendMapsActivity#getNextClass(SendRequest, boolean)}. Sets the flags
|
||||
* of "sendFusionTables","sendDocs" and "cancel" to false, false and false.
|
||||
*/
|
||||
public void testGetNextClass_notCancelNotSend() {
|
||||
sendRequest.setSendFusionTables(false);
|
||||
sendRequest.setSendDocs(false);
|
||||
Class<?> next = sendMapsActivity.getNextClass(sendRequest, false);
|
||||
assertEquals(UploadResultActivity.class, next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link SendMapsActivity#getNextClass(SendRequest, boolean)}. Sets the flags
|
||||
* of "sendFusionTables","sendDocs" and "cancel" to true, true and true.
|
||||
*/
|
||||
public void testGetNextClass_cancelSendDocs() {
|
||||
sendRequest.setSendFusionTables(true);
|
||||
sendRequest.setSendDocs(true);
|
||||
Class<?> next = sendMapsActivity.getNextClass(sendRequest, true);
|
||||
assertEquals(UploadResultActivity.class, next);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,68 +15,217 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link StringUtils}.
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class StringUtilsTest extends TestCase {
|
||||
public void testParseXmlDateTime() {
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01",
|
||||
2010, 5, 4, 3, 2, 1, 0);
|
||||
public class StringUtilsTest extends AndroidTestCase {
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#formatDateTime(android.content.Context, long)}.
|
||||
*/
|
||||
public void testFormatTime() {
|
||||
// Unix time 0 in UTC is "4:00 PM" in Pacific Standard time zone.
|
||||
// This test can break if run on a different time zone or with a different
|
||||
// time format preference.
|
||||
assertEquals("4:00 PM", StringUtils.formatTime(getContext(), 0L));
|
||||
}
|
||||
|
||||
public void testParseXmlDateTime_fractional() {
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01.3",
|
||||
2010, 5, 4, 3, 2, 1, 300);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01.35",
|
||||
2010, 5, 4, 3, 2, 1, 350);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01.352",
|
||||
2010, 5, 4, 3, 2, 1, 352);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01.3525",
|
||||
2010, 5, 4, 3, 2, 1, 352);
|
||||
/**
|
||||
* Tests {@link StringUtils#formatDateTime(android.content.Context, long)}.
|
||||
*/
|
||||
public void testFormatDateTime() {
|
||||
// Unix time 0 in UTC is "12/31/1969 4:00 PM" in Pacific Standard time zone.
|
||||
// This test can break if run on a different time zone or with a different
|
||||
// date/time format preference.
|
||||
assertEquals("12/31/1969 4:00 PM", StringUtils.formatDateTime(getContext(), 0L));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#formatDateTimeIso8601(long)}.
|
||||
*/
|
||||
public void testFormatDateTimeIso8601() {
|
||||
assertEquals("1970-01-01T00:00:12.345Z", StringUtils.formatDateTimeIso8601(12345));
|
||||
}
|
||||
|
||||
public void testParseXmlDateTime_timezone() {
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01Z",
|
||||
2010, 5, 4, 3, 2, 1, 0);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01+00:00",
|
||||
2010, 5, 4, 3, 2, 1, 0);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01-00:00",
|
||||
2010, 5, 4, 3, 2, 1, 0);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01+01:00",
|
||||
2010, 5, 4, 2, 2, 1, 0);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01+10:30",
|
||||
2010, 5, 3, 16, 32, 1, 0);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01-09:30",
|
||||
2010, 5, 4, 12, 32, 1, 0);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01-05:00",
|
||||
2010, 5, 4, 8, 2, 1, 0);
|
||||
/**
|
||||
* Tests {@link StringUtils#formatElapsedTime(long)}.
|
||||
*/
|
||||
public void testformatElapsedTime() {
|
||||
// 1 second
|
||||
assertEquals("00:01", StringUtils.formatElapsedTime(1000));
|
||||
// 10 seconds
|
||||
assertEquals("00:10", StringUtils.formatElapsedTime(10000));
|
||||
// 1 minute
|
||||
assertEquals("01:00", StringUtils.formatElapsedTime(60000));
|
||||
// 10 minutes
|
||||
assertEquals("10:00", StringUtils.formatElapsedTime(600000));
|
||||
// 1 hour
|
||||
assertEquals("1:00:00", StringUtils.formatElapsedTime(3600000));
|
||||
// 10 hours
|
||||
assertEquals("10:00:00", StringUtils.formatElapsedTime(36000000));
|
||||
// 100 hours
|
||||
assertEquals("100:00:00", StringUtils.formatElapsedTime(360000000));
|
||||
}
|
||||
|
||||
public void testParseXmlDateTime_fractionalAndTimezone() {
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01.352Z",
|
||||
2010, 5, 4, 3, 2, 1, 352);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01.47+00:00",
|
||||
2010, 5, 4, 3, 2, 1, 470);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01.5791+03:00",
|
||||
2010, 5, 4, 0, 2, 1, 579);
|
||||
assertParseXmlDateTime("2010-05-04T03:02:01.8-05:30",
|
||||
2010, 5, 4, 8, 32, 1, 800);
|
||||
/**
|
||||
* Tests {@link StringUtils#formatElapsedTimeWithHour(long)}.
|
||||
*/
|
||||
public void testformatElapsedTimeWithHour() {
|
||||
// 1 second
|
||||
assertEquals("0:00:01", StringUtils.formatElapsedTimeWithHour(1000));
|
||||
// 10 seconds
|
||||
assertEquals("0:00:10", StringUtils.formatElapsedTimeWithHour(10000));
|
||||
// 1 minute
|
||||
assertEquals("0:01:00", StringUtils.formatElapsedTimeWithHour(60000));
|
||||
// 10 minutes
|
||||
assertEquals("0:10:00", StringUtils.formatElapsedTimeWithHour(600000));
|
||||
// 1 hour
|
||||
assertEquals("1:00:00", StringUtils.formatElapsedTimeWithHour(3600000));
|
||||
// 10 hours
|
||||
assertEquals("10:00:00", StringUtils.formatElapsedTimeWithHour(36000000));
|
||||
// 100 hours
|
||||
assertEquals("100:00:00", StringUtils.formatElapsedTimeWithHour(360000000));
|
||||
}
|
||||
|
||||
private void assertParseXmlDateTime(String dateTime,
|
||||
int year, int month, int day, int hour, int min, int second, int millis) {
|
||||
long timestamp = StringUtils.parseXmlDateTime(dateTime);
|
||||
GregorianCalendar calendar =
|
||||
new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
calendar.set(year, month - 1, day, hour, min, second);
|
||||
calendar.set(GregorianCalendar.MILLISECOND, millis);
|
||||
assertEquals(calendar.getTimeInMillis(), timestamp);
|
||||
/**
|
||||
* Tests {@link StringUtils#formatDistance(android.content.Context, double,
|
||||
* boolean)}.
|
||||
*/
|
||||
public void testFormatDistance() {
|
||||
// A large number in metric
|
||||
assertEquals("5.00 km", StringUtils.formatDistance(getContext(), 5000, true));
|
||||
// A large number in imperial
|
||||
assertEquals("3.11 mi", StringUtils.formatDistance(getContext(), 5000, false));
|
||||
// A small number in metric
|
||||
assertEquals("100.00 m", StringUtils.formatDistance(getContext(), 100, true));
|
||||
// A small number in imperial
|
||||
assertEquals("328.08 ft", StringUtils.formatDistance(getContext(), 100, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#formatSpeed(android.content.Context, double,
|
||||
* boolean, boolean)}.
|
||||
*/
|
||||
public void testFormatSpeed() {
|
||||
// Speed in metric
|
||||
assertEquals("36.00 km/h", StringUtils.formatSpeed(getContext(), 10, true, true));
|
||||
// Speed in imperial
|
||||
assertEquals("22.37 mi/h", StringUtils.formatSpeed(getContext(), 10, false, true));
|
||||
// Pace in metric
|
||||
assertEquals("1.67 min/km", StringUtils.formatSpeed(getContext(), 10, true, false));
|
||||
// Pace in imperial
|
||||
assertEquals("2.68 min/mi", StringUtils.formatSpeed(getContext(), 10, false, false));
|
||||
// zero pace
|
||||
assertEquals("0.00 min/km", StringUtils.formatSpeed(getContext(), 0, true, false));
|
||||
assertEquals("0.00 min/mi", StringUtils.formatSpeed(getContext(), 0, false, false));
|
||||
// speed is NaN
|
||||
assertEquals("-", StringUtils.formatSpeed(getContext(), Double.NaN, true, true));
|
||||
// speed is infinite
|
||||
assertEquals("-", StringUtils.formatSpeed(getContext(), Double.NEGATIVE_INFINITY, true, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#formatTimeDistance(android.content.Context, long, double, boolean)}.
|
||||
*/
|
||||
public void testFormatTimeDistance() {
|
||||
assertEquals("00:10 5.00 km", StringUtils.formatTimeDistance(getContext(), 10000, 5000, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#formatCData(String)}.
|
||||
*/
|
||||
public void testFormatCData() {
|
||||
assertEquals("<![CDATA[hello]]>", StringUtils.formatCData("hello"));
|
||||
assertEquals("<![CDATA[hello]]]]><![CDATA[>there]]>", StringUtils.formatCData("hello]]>there"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#getTime(String)}.
|
||||
*/
|
||||
public void testGetTime() {
|
||||
assertGetTime("2010-05-04T03:02:01", 2010, 5, 4, 3, 2, 1, 0);
|
||||
assertGetTime("2010-05-04T03:02:01Z", 2010, 5, 4, 3, 2, 1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#getTime(String)} with fractional seconds.
|
||||
*/
|
||||
public void testGetTime_fractional() {
|
||||
assertGetTime("2010-05-04T03:02:01.3", 2010, 5, 4, 3, 2, 1, 300);
|
||||
assertGetTime("2010-05-04T03:02:01.35", 2010, 5, 4, 3, 2, 1, 350);
|
||||
assertGetTime("2010-05-04T03:02:01.352Z", 2010, 5, 4, 3, 2, 1, 352);
|
||||
assertGetTime("2010-05-04T03:02:01.3525Z", 2010, 5, 4, 3, 2, 1, 352);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#getTime(String)} with time zone.
|
||||
*/
|
||||
public void testGetTime_timezone() {
|
||||
assertGetTime("2010-05-04T03:02:01Z", 2010, 5, 4, 3, 2, 1, 0);
|
||||
assertGetTime("2010-05-04T03:02:01+00:00", 2010, 5, 4, 3, 2, 1, 0);
|
||||
assertGetTime("2010-05-04T03:02:01-00:00", 2010, 5, 4, 3, 2, 1, 0);
|
||||
assertGetTime("2010-05-04T03:02:01+01:00", 2010, 5, 4, 2, 2, 1, 0);
|
||||
assertGetTime("2010-05-04T03:02:01+10:30", 2010, 5, 3, 16, 32, 1, 0);
|
||||
assertGetTime("2010-05-04T03:02:01-09:30", 2010, 5, 4, 12, 32, 1, 0);
|
||||
assertGetTime("2010-05-04T03:02:01-05:00", 2010, 5, 4, 8, 2, 1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#getTime(String)} with fractional seconds and time
|
||||
* zone.
|
||||
*/
|
||||
public void testGetTime_fractionalAndTimezone() {
|
||||
assertGetTime("2010-05-04T03:02:01.352Z", 2010, 5, 4, 3, 2, 1, 352);
|
||||
assertGetTime("2010-05-04T03:02:01.47+00:00", 2010, 5, 4, 3, 2, 1, 470);
|
||||
assertGetTime("2010-05-04T03:02:01.5791+03:00", 2010, 5, 4, 0, 2, 1, 579);
|
||||
assertGetTime("2010-05-04T03:02:01.8-05:30", 2010, 5, 4, 8, 32, 1, 800);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the {@link StringUtils#getTime(String)} returns the expected
|
||||
* values.
|
||||
*
|
||||
* @param xmlDateTime the xml date time string
|
||||
* @param year the expected year
|
||||
* @param month the expected month
|
||||
* @param day the expected day
|
||||
* @param hour the expected hour
|
||||
* @param minute the expected minute
|
||||
* @param second the expected second
|
||||
* @param millisecond the expected milliseconds
|
||||
*/
|
||||
private void assertGetTime(String xmlDateTime, int year, int month, int day, int hour, int minute,
|
||||
int second, int millisecond) {
|
||||
GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
calendar.set(year, month - 1, day, hour, minute, second);
|
||||
calendar.set(GregorianCalendar.MILLISECOND, millisecond);
|
||||
assertEquals(calendar.getTimeInMillis(), StringUtils.getTime(xmlDateTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#getTimeParts(long)} with a positive number.
|
||||
*/
|
||||
public void testGetTimeParts_postive() {
|
||||
int parts[] = StringUtils.getTimeParts(61000);
|
||||
assertEquals(1, parts[0]);
|
||||
assertEquals(1, parts[1]);
|
||||
assertEquals(0, parts[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#getTimeParts(long)} with a negative number.
|
||||
*/
|
||||
public void testGetTimeParts_negative() {
|
||||
int parts[] = StringUtils.getTimeParts(-61000);
|
||||
assertEquals(-1, parts[0]);
|
||||
assertEquals(-1, parts[1]);
|
||||
assertEquals(0, parts[2]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user