forked from upstream-mirrors/OpenTracks
Merge to head
This commit is contained in:
@@ -1,102 +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.io.docs;
|
||||
|
||||
import com.google.android.apps.mytracks.io.gdata.GDataWrapper;
|
||||
import com.google.wireless.gdata.client.GDataServiceClient;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.mock.MockContext;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Tests for {@link DocsHelper}, with the exception of
|
||||
* {@link DocsHelper#addTrackRow}, which is in
|
||||
* {@link DocsHelper_AddTrackRowTest}.
|
||||
*
|
||||
* @author Matthew Simmons
|
||||
*/
|
||||
public class DocsHelperTest extends TestCase {
|
||||
private Context mockContext = new MockContext();
|
||||
|
||||
// TODO(simmonmt): Use AndroidMock to mock this class. We do it the hard
|
||||
// way because use of AndroidMock to mock GDataWrapper triggers a compile
|
||||
// error in an unrelated file. Specifically, it causes a NoClassDefFound
|
||||
// exception for com.google.wireless.gdata2.client.AuthenticationException,
|
||||
// (wrongly) attributed to the first source file in the project. Using the
|
||||
// @UsesMocks(GDataWrapper.class) annotation is enough -- you don't have to
|
||||
// touch AndroidMock at all to get this failure.
|
||||
// The bug is filed with Android Mock as
|
||||
// http://code.google.com/p/android-mock/issues/detail?id=3
|
||||
private class MockGDataWrapper extends GDataWrapper<GDataServiceClient> {
|
||||
private final boolean returnValue;
|
||||
|
||||
MockGDataWrapper(boolean returnValue) {
|
||||
this.returnValue = returnValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runQuery(QueryFunction<GDataServiceClient> queryFunction) {
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreateSpreadsheet_noException() throws Exception {
|
||||
// Our mock GDataWrapper isn't able to affect the return value from
|
||||
// DocsHelper#createSpreadsheet. As such, we're only able to simulate the
|
||||
// case where there weren't any GData errors, but not spreadsheet ID was
|
||||
// actually returned. createSpreadsheet is defined to return null in that
|
||||
// situation.
|
||||
assertNull(new DocsHelper().createSpreadsheet(
|
||||
mockContext, new MockGDataWrapper(true), "sheetName"));
|
||||
}
|
||||
|
||||
public void testCreateSpreadsheet_exception() throws Exception {
|
||||
try {
|
||||
new DocsHelper().createSpreadsheet(
|
||||
mockContext, new MockGDataWrapper(false), "sheetName");
|
||||
fail();
|
||||
} catch (IOException expected) {}
|
||||
}
|
||||
|
||||
public void testRequestSpreadsheetId_noException() throws Exception {
|
||||
assertNull(new DocsHelper().requestSpreadsheetId(
|
||||
new MockGDataWrapper(true), "sheetName"));
|
||||
}
|
||||
|
||||
public void testRequestSpreadsheetId_exception() throws Exception {
|
||||
try {
|
||||
new DocsHelper().requestSpreadsheetId(new MockGDataWrapper(false),
|
||||
"sheetName");
|
||||
fail();
|
||||
} catch (IOException expected) {}
|
||||
}
|
||||
|
||||
public void testGetWorksheetId_noException() throws Exception {
|
||||
assertNull(new DocsHelper().getWorksheetId(new MockGDataWrapper(true),
|
||||
"sheetId"));
|
||||
}
|
||||
|
||||
public void testGetWorksheetId_exception() throws Exception {
|
||||
try {
|
||||
new DocsHelper().getWorksheetId(new MockGDataWrapper(false), "sheetId");
|
||||
fail();
|
||||
} catch (IOException expected) {}
|
||||
}
|
||||
}
|
||||
-160
@@ -1,160 +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.io.docs;
|
||||
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.io.AuthManager;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.android.testing.mocking.AndroidMock;
|
||||
import com.google.android.testing.mocking.UsesMocks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.test.mock.MockContext;
|
||||
import android.test.mock.MockResources;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link DocsHelper#addTrackRow}
|
||||
*
|
||||
* @author Matthew Simmons
|
||||
*/
|
||||
public class DocsHelper_AddTrackRowTest extends TestCase {
|
||||
private static final long TIME = 1288721514000L;
|
||||
|
||||
private static class StringWritingDocsHelper extends DocsHelper {
|
||||
String writtenSheetUri = null;
|
||||
String writtenData = null;
|
||||
|
||||
@Override
|
||||
protected void writeRowData(AuthManager trixAuth, String worksheetUri,
|
||||
String postText) {
|
||||
writtenSheetUri = worksheetUri;
|
||||
writtenData = postText;
|
||||
}
|
||||
}
|
||||
|
||||
public void testAddTrackRow_imperial() throws Exception {
|
||||
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper();
|
||||
addTrackRow(docsHelper, false);
|
||||
|
||||
String expectedData =
|
||||
"<entry xmlns='http://www.w3.org/2005/Atom' "
|
||||
+ "xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>"
|
||||
+ "<gsx:name><![CDATA[trackName]]></gsx:name>"
|
||||
+ "<gsx:description><![CDATA[trackDescription]]></gsx:description>"
|
||||
+ "<gsx:date><![CDATA[" + StringUtils.formatDateTime(TIME) + "]]></gsx:date>"
|
||||
+ "<gsx:totaltime><![CDATA[0:00:05]]></gsx:totaltime>"
|
||||
+ "<gsx:movingtime><![CDATA[0:00:04]]></gsx:movingtime>"
|
||||
+ "<gsx:distance><![CDATA[12.43]]></gsx:distance>"
|
||||
+ "<gsx:distanceunit><![CDATA[mile]]></gsx:distanceunit>"
|
||||
+ "<gsx:averagespeed><![CDATA[8,947.75]]></gsx:averagespeed>"
|
||||
+ "<gsx:averagemovingspeed><![CDATA[11,184.68]]>"
|
||||
+ "</gsx:averagemovingspeed>"
|
||||
+ "<gsx:maxspeed><![CDATA[3,355.40]]></gsx:maxspeed>"
|
||||
+ "<gsx:speedunit><![CDATA[mph]]></gsx:speedunit>"
|
||||
+ "<gsx:elevationgain><![CDATA[19,685]]></gsx:elevationgain>"
|
||||
+ "<gsx:minelevation><![CDATA[-1,640]]></gsx:minelevation>"
|
||||
+ "<gsx:maxelevation><![CDATA[1,804]]></gsx:maxelevation>"
|
||||
+ "<gsx:elevationunit><![CDATA[feet]]></gsx:elevationunit>"
|
||||
+ "<gsx:map>"
|
||||
+ "<![CDATA[https://maps.google.com/maps/ms?msa=0&msid=trackMapId]]>"
|
||||
+ "</gsx:map>"
|
||||
+ "</entry>";
|
||||
|
||||
assertEquals(
|
||||
"https://spreadsheets.google.com/feeds/list/ssid/wsid/private/full",
|
||||
docsHelper.writtenSheetUri);
|
||||
assertEquals(expectedData, docsHelper.writtenData);
|
||||
}
|
||||
|
||||
public void testAddTrackRow_metric() throws Exception {
|
||||
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper();
|
||||
addTrackRow(docsHelper, true);
|
||||
|
||||
// The imperial test verifies that the tags come out in the proper order,
|
||||
// and with the proper names. We need only verify that the labels are
|
||||
// correct, and that at least one of the unit-dependent value tags is
|
||||
// correct.
|
||||
assertTrue(docsHelper.writtenData.contains(
|
||||
"<gsx:distanceunit><![CDATA[km]]></gsx:distanceunit>"));
|
||||
assertTrue(docsHelper.writtenData.contains(
|
||||
"<gsx:speedunit><![CDATA[kph]]></gsx:speedunit>"));
|
||||
assertTrue(docsHelper.writtenData.contains(
|
||||
"<gsx:elevationunit><![CDATA[meter]]></gsx:elevationunit>"));
|
||||
|
||||
assertTrue(docsHelper.writtenData.contains(
|
||||
"<gsx:distance><![CDATA[20.00]]></gsx:distance>"));
|
||||
}
|
||||
|
||||
/** Adds a row to the spreadsheet, using the provided helper. */
|
||||
@UsesMocks({AuthManager.class, MockResources.class, Track.class})
|
||||
private void addTrackRow(DocsHelper docsHelper, boolean useMetric)
|
||||
throws IOException {
|
||||
final Resources mockResources = AndroidMock.createMock(MockResources.class);
|
||||
|
||||
if (useMetric) {
|
||||
AndroidMock.expect(mockResources.getString(R.string.unit_kilometer))
|
||||
.andReturn("km");
|
||||
AndroidMock.expect(mockResources.getString(R.string.unit_kilometer_per_hour))
|
||||
.andReturn("kph");
|
||||
AndroidMock.expect(mockResources.getString(R.string.unit_meter))
|
||||
.andReturn("meter");
|
||||
} else {
|
||||
AndroidMock.expect(mockResources.getString(R.string.unit_mile))
|
||||
.andReturn("mile");
|
||||
AndroidMock.expect(mockResources.getString(R.string.unit_mile_per_hour))
|
||||
.andReturn("mph");
|
||||
AndroidMock.expect(mockResources.getString(R.string.unit_feet))
|
||||
.andReturn("feet");
|
||||
}
|
||||
AndroidMock.replay(mockResources);
|
||||
|
||||
Context mockContext = new MockContext() {
|
||||
@Override
|
||||
public Resources getResources() {
|
||||
return mockResources;
|
||||
}
|
||||
};
|
||||
|
||||
AuthManager mockAuthManager = AndroidMock.createMock(AuthManager.class);
|
||||
AndroidMock.replay(mockAuthManager);
|
||||
|
||||
TripStatistics stats = new TripStatistics();
|
||||
stats.setStartTime(TIME);
|
||||
stats.setTotalTime(5000);
|
||||
stats.setMovingTime(4000);
|
||||
stats.setTotalDistance(20000);
|
||||
stats.setMaxSpeed(1500);
|
||||
stats.setTotalElevationGain(6000);
|
||||
stats.setMinElevation(-500);
|
||||
stats.setMaxElevation(550);
|
||||
|
||||
Track track = new Track();
|
||||
track.setName("trackName");
|
||||
track.setDescription("trackDescription");
|
||||
track.setMapId("trackMapId");
|
||||
track.setStatistics(stats);
|
||||
|
||||
docsHelper.addTrackRow(mockContext, mockAuthManager, "ssid", "wsid",
|
||||
track, useMetric);
|
||||
}
|
||||
}
|
||||
@@ -1,60 +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.io.docs;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* This class tests {@link DocsTagBuilder}
|
||||
*
|
||||
* @author Matthew Simmons
|
||||
*/
|
||||
public class DocsTagBuilderTest extends TestCase {
|
||||
public void testAppend() {
|
||||
assertEquals("<gsx:tag><![CDATA[value]]></gsx:tag>",
|
||||
new DocsTagBuilder(false).append("tag", "value").build());
|
||||
}
|
||||
|
||||
public void testMultiAppend() {
|
||||
String actual = new DocsTagBuilder(false)
|
||||
.append("tag1", "value1")
|
||||
.append("tag2", "value2")
|
||||
.build();
|
||||
|
||||
assertEquals("<gsx:tag1><![CDATA[value1]]></gsx:tag1>"
|
||||
+ "<gsx:tag2><![CDATA[value2]]></gsx:tag2>", actual);
|
||||
}
|
||||
|
||||
public void testAppendLargeUnits_imperial() {
|
||||
assertEquals("<gsx:tag><![CDATA[62.14]]></gsx:tag>",
|
||||
new DocsTagBuilder(false).appendLargeUnits("tag", 100.0).build());
|
||||
}
|
||||
|
||||
public void testAppendLargeUnits_metric() {
|
||||
assertEquals("<gsx:tag><![CDATA[100.00]]></gsx:tag>",
|
||||
new DocsTagBuilder(true).appendLargeUnits("tag", 100.0).build());
|
||||
}
|
||||
|
||||
public void testAppendSmallUnits_imperial() {
|
||||
assertEquals("<gsx:tag><![CDATA[328]]></gsx:tag>",
|
||||
new DocsTagBuilder(false).appendSmallUnits("tag", 100.0).build());
|
||||
}
|
||||
|
||||
public void testAppendSmallUnits_metric() {
|
||||
assertEquals("<gsx:tag><![CDATA[100]]></gsx:tag>",
|
||||
new DocsTagBuilder(true).appendSmallUnits("tag", 100.0).build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* 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.docs;
|
||||
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.wireless.gdata.data.Entry;
|
||||
import com.google.wireless.gdata.docs.SpreadsheetsClient.WorksheetEntry;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils}.
|
||||
*
|
||||
* @author jshih@google.com (Jimmy Shih)
|
||||
*/
|
||||
public class SendDocsUtilsTest extends AndroidTestCase {
|
||||
|
||||
private static final long TIME = 1288721514000L;
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getEntryId(Entry)} with a valid id.
|
||||
*/
|
||||
public void testGetEntryId_valid() {
|
||||
Entry entry = new Entry();
|
||||
entry.setId("https://docs.google.com/feeds/documents/private/full/spreadsheet%3A123");
|
||||
assertEquals("123", SendDocsUtils.getEntryId(entry));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getEntryId(Entry)} with an invalid id.
|
||||
*/
|
||||
public void testGetEntryId_invalid() {
|
||||
Entry entry = new Entry();
|
||||
entry.setId("123");
|
||||
assertEquals(null, SendDocsUtils.getEntryId(entry));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getNewSpreadsheetId(String)} with a valid id.
|
||||
*/
|
||||
public void testGetNewSpreadsheetId_valid_id() {
|
||||
assertEquals("123", SendDocsUtils.getNewSpreadsheetId(
|
||||
"<id>https://docs.google.com/feeds/documents/private/full/spreadsheet%3A123</id>"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getNewSpreadsheetId(String)} without an open
|
||||
* tag, <id>.
|
||||
*/
|
||||
public void testGetNewSpreadsheetId_no_open_tag() {
|
||||
assertEquals(null, SendDocsUtils.getNewSpreadsheetId(
|
||||
"https://docs.google.com/feeds/documents/private/full/spreadsheet%3A123</id>"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getNewSpreadsheetId(String)} without an end tag,
|
||||
* </id>.
|
||||
*/
|
||||
public void testGetNewSpreadsheetId_no_end_tag() {
|
||||
assertEquals(null, SendDocsUtils.getNewSpreadsheetId(
|
||||
"<id>https://docs.google.com/feeds/documents/private/full/spreadsheet%3A123"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getNewSpreadsheetId(String)} without the url
|
||||
* prefix,
|
||||
* https://docs.google.com/feeds/documents/private/full/spreadsheet%3A.
|
||||
*/
|
||||
public void testGetNewSpreadsheetId_no_prefix() {
|
||||
assertEquals(null, SendDocsUtils.getNewSpreadsheetId("<id>123</id>"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getWorksheetEntryId(WorksheetEntry)} with a
|
||||
* valid entry.
|
||||
*/
|
||||
public void testGetWorksheetEntryId_valid() {
|
||||
WorksheetEntry entry = new WorksheetEntry();
|
||||
entry.setId("/123");
|
||||
assertEquals("123", SendDocsUtils.getWorksheetEntryId(entry));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getWorksheetEntryId(WorksheetEntry)} with a
|
||||
* invalid entry.
|
||||
*/
|
||||
public void testGetWorksheetEntryId_invalid() {
|
||||
WorksheetEntry entry = new WorksheetEntry();
|
||||
entry.setId("123");
|
||||
assertEquals(null, SendDocsUtils.getWorksheetEntryId(entry));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getRowContent(Track, boolean,
|
||||
* android.content.Context)} with metric units.
|
||||
*/
|
||||
public void testGetRowContent_metric() throws Exception {
|
||||
Track track = getTrack();
|
||||
String expectedData = "<entry xmlns='http://www.w3.org/2005/Atom' "
|
||||
+ "xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>"
|
||||
+ "<gsx:name><![CDATA[trackName]]></gsx:name>"
|
||||
+ "<gsx:description><![CDATA[trackDescription]]></gsx:description>" + "<gsx:date><![CDATA["
|
||||
+ StringUtils.formatDateTime(getContext(), TIME) + "]]></gsx:date>"
|
||||
+ "<gsx:totaltime><![CDATA[00:05]]></gsx:totaltime>"
|
||||
+ "<gsx:movingtime><![CDATA[00:04]]></gsx:movingtime>"
|
||||
+ "<gsx:distance><![CDATA[20.00]]></gsx:distance>"
|
||||
+ "<gsx:distanceunit><![CDATA[km]]></gsx:distanceunit>"
|
||||
+ "<gsx:averagespeed><![CDATA[14,400.00]]></gsx:averagespeed>"
|
||||
+ "<gsx:averagemovingspeed><![CDATA[18,000.00]]>" + "</gsx:averagemovingspeed>"
|
||||
+ "<gsx:maxspeed><![CDATA[5,400.00]]></gsx:maxspeed>"
|
||||
+ "<gsx:speedunit><![CDATA[km/h]]></gsx:speedunit>"
|
||||
+ "<gsx:elevationgain><![CDATA[6,000]]></gsx:elevationgain>"
|
||||
+ "<gsx:minelevation><![CDATA[-500]]></gsx:minelevation>"
|
||||
+ "<gsx:maxelevation><![CDATA[550]]></gsx:maxelevation>"
|
||||
+ "<gsx:elevationunit><![CDATA[m]]></gsx:elevationunit>" + "<gsx:map>"
|
||||
+ "<![CDATA[https://maps.google.com/maps/ms?msa=0&msid=trackMapId]]>" + "</gsx:map>"
|
||||
+ "</entry>";
|
||||
assertEquals(expectedData, SendDocsUtils.getRowContent(track, true, getContext()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getRowContent(Track, boolean,
|
||||
* android.content.Context)} with imperial units.
|
||||
*/
|
||||
public void testGetRowContent_imperial() throws Exception {
|
||||
Track track = getTrack();
|
||||
String expectedData = "<entry xmlns='http://www.w3.org/2005/Atom' "
|
||||
+ "xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>"
|
||||
+ "<gsx:name><![CDATA[trackName]]></gsx:name>"
|
||||
+ "<gsx:description><![CDATA[trackDescription]]></gsx:description>" + "<gsx:date><![CDATA["
|
||||
+ StringUtils.formatDateTime(getContext(), TIME) + "]]></gsx:date>"
|
||||
+ "<gsx:totaltime><![CDATA[00:05]]></gsx:totaltime>"
|
||||
+ "<gsx:movingtime><![CDATA[00:04]]></gsx:movingtime>"
|
||||
+ "<gsx:distance><![CDATA[12.43]]></gsx:distance>"
|
||||
+ "<gsx:distanceunit><![CDATA[mi]]></gsx:distanceunit>"
|
||||
+ "<gsx:averagespeed><![CDATA[8,947.75]]></gsx:averagespeed>"
|
||||
+ "<gsx:averagemovingspeed><![CDATA[11,184.68]]>" + "</gsx:averagemovingspeed>"
|
||||
+ "<gsx:maxspeed><![CDATA[3,355.40]]></gsx:maxspeed>"
|
||||
+ "<gsx:speedunit><![CDATA[mi/h]]></gsx:speedunit>"
|
||||
+ "<gsx:elevationgain><![CDATA[19,685]]></gsx:elevationgain>"
|
||||
+ "<gsx:minelevation><![CDATA[-1,640]]></gsx:minelevation>"
|
||||
+ "<gsx:maxelevation><![CDATA[1,804]]></gsx:maxelevation>"
|
||||
+ "<gsx:elevationunit><![CDATA[ft]]></gsx:elevationunit>" + "<gsx:map>"
|
||||
+ "<![CDATA[https://maps.google.com/maps/ms?msa=0&msid=trackMapId]]>" + "</gsx:map>"
|
||||
+ "</entry>";
|
||||
assertEquals(expectedData, SendDocsUtils.getRowContent(track, false, getContext()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a track for testing {@link SendDocsUtils#getRowContent(Track, boolean,
|
||||
* android.content.Context)}.
|
||||
*/
|
||||
private Track getTrack() {
|
||||
TripStatistics stats = new TripStatistics();
|
||||
stats.setStartTime(TIME);
|
||||
stats.setTotalTime(5000);
|
||||
stats.setMovingTime(4000);
|
||||
stats.setTotalDistance(20000);
|
||||
stats.setMaxSpeed(1500);
|
||||
stats.setTotalElevationGain(6000);
|
||||
stats.setMinElevation(-500);
|
||||
stats.setMaxElevation(550);
|
||||
|
||||
Track track = new Track();
|
||||
track.setName("trackName");
|
||||
track.setDescription("trackDescription");
|
||||
track.setMapId("trackMapId");
|
||||
track.setStatistics(stats);
|
||||
return track;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#appendTag(StringBuilder, String, String)} with
|
||||
* repeated calls.
|
||||
*/
|
||||
public void testAppendTag() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
SendDocsUtils.appendTag(stringBuilder, "name1", "value1");
|
||||
assertEquals("<gsx:name1><![CDATA[value1]]></gsx:name1>", stringBuilder.toString());
|
||||
|
||||
SendDocsUtils.appendTag(stringBuilder, "name2", "value2");
|
||||
assertEquals(
|
||||
"<gsx:name1><![CDATA[value1]]></gsx:name1><gsx:name2><![CDATA[value2]]></gsx:name2>",
|
||||
stringBuilder.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getDistance(double, boolean)} with metric units.
|
||||
*/
|
||||
public void testGetDistance_metric() {
|
||||
assertEquals("1.22", SendDocsUtils.getDistance(1222.3, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getDistance(double, boolean)} with imperial
|
||||
* units.
|
||||
*/
|
||||
public void testGetDistance_imperial() {
|
||||
assertEquals("0.76", SendDocsUtils.getDistance(1222.3, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getSpeed(double, boolean)} with metric units.
|
||||
*/
|
||||
public void testGetSpeed_metric() {
|
||||
assertEquals("15.55", SendDocsUtils.getSpeed(4.32, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getSpeed(double, boolean)} with imperial units.
|
||||
*/
|
||||
public void testGetSpeed_imperial() {
|
||||
assertEquals("9.66", SendDocsUtils.getSpeed(4.32, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getElevation(double, boolean)} with metric
|
||||
* units.
|
||||
*/
|
||||
public void testGetElevation_metric() {
|
||||
assertEquals("3", SendDocsUtils.getElevation(3.456, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendDocsUtils#getElevation(double, boolean)} with imperial
|
||||
* units.
|
||||
*/
|
||||
public void testGetElevation_imperial() {
|
||||
assertEquals("11", SendDocsUtils.getElevation(3.456, false));
|
||||
}
|
||||
}
|
||||
-130
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 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.MyTracks;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.View;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests {@link ResultDialogFactory}.
|
||||
*
|
||||
* @author Matthew Simmons
|
||||
*/
|
||||
public class ResultDialogFactoryTest extends ActivityInstrumentationTestCase2<MyTracks> {
|
||||
public ResultDialogFactoryTest() {
|
||||
super(MyTracks.class);
|
||||
}
|
||||
|
||||
private List<SendResult> makeResults(SendResult... results) {
|
||||
List<SendResult> resultsList = new ArrayList<SendResult>();
|
||||
for (SendResult result : results) {
|
||||
resultsList.add(result);
|
||||
}
|
||||
return resultsList;
|
||||
}
|
||||
|
||||
private DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {}
|
||||
};
|
||||
|
||||
private MyTracks myTracks;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myTracks = getActivity();
|
||||
};
|
||||
|
||||
public void testSuccess_noShare() {
|
||||
List<SendResult> results = makeResults(new SendResult(SendType.MYMAPS, true),
|
||||
new SendResult(SendType.DOCS, true));
|
||||
|
||||
AlertDialog dialog = ResultDialogFactory.makeDialog(
|
||||
myTracks, results, clickListener, null, null);
|
||||
dialog.show();
|
||||
|
||||
ListView listView = (ListView) dialog.findViewById(R.id.send_to_google_result_list);
|
||||
ListAdapter listAdapter = listView.getAdapter();
|
||||
assertEquals(2, listAdapter.getCount());
|
||||
|
||||
assertEquals(SendType.MYMAPS, ((SendResult) listAdapter.getItem(0)).getType());
|
||||
assertEquals(SendType.DOCS, ((SendResult) listAdapter.getItem(1)).getType());
|
||||
|
||||
// Checking the return code of Dialog#getButton doesn't appear to be
|
||||
// sufficient, as a Button will be returned even if it doesn't appear in
|
||||
// the rendered dialog.
|
||||
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_POSITIVE).getVisibility());
|
||||
assertEquals(View.GONE, dialog.getButton(AlertDialog.BUTTON_NEUTRAL).getVisibility());
|
||||
|
||||
assertEquals(View.VISIBLE,
|
||||
dialog.findViewById(R.id.send_to_google_result_comment).getVisibility());
|
||||
assertEquals(View.GONE,
|
||||
dialog.findViewById(R.id.send_to_google_result_error).getVisibility());
|
||||
|
||||
// TODO: Test correct listener invocation. Neither TouchUtils#clickView
|
||||
// nor Button#performClick appear to cause listener invocation. This
|
||||
// might be Android bug
|
||||
// http://code.google.com/p/android/issues/detail?id=6564
|
||||
}
|
||||
|
||||
public void testSuccess_share() {
|
||||
List<SendResult> results = makeResults(
|
||||
new SendResult(SendType.MYMAPS, true), new SendResult(SendType.DOCS, true));
|
||||
|
||||
AlertDialog dialog = ResultDialogFactory.makeDialog(
|
||||
myTracks, results, clickListener, clickListener, null);
|
||||
dialog.show();
|
||||
|
||||
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_POSITIVE).getVisibility());
|
||||
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_NEGATIVE).getVisibility());
|
||||
}
|
||||
|
||||
public void testFailure_noShare() {
|
||||
List<SendResult> results = makeResults(new SendResult(SendType.MYMAPS, true),
|
||||
new SendResult(SendType.DOCS, false));
|
||||
|
||||
AlertDialog dialog = ResultDialogFactory.makeDialog(
|
||||
myTracks, results, clickListener, null, null);
|
||||
dialog.show();
|
||||
|
||||
assertEquals(View.GONE,
|
||||
dialog.findViewById(R.id.send_to_google_result_comment).getVisibility());
|
||||
assertEquals(View.VISIBLE,
|
||||
dialog.findViewById(R.id.send_to_google_result_error).getVisibility());
|
||||
}
|
||||
|
||||
public void testFailure_share() {
|
||||
List<SendResult> results = makeResults(new SendResult(SendType.MYMAPS, true),
|
||||
new SendResult(SendType.DOCS, false));
|
||||
|
||||
AlertDialog dialog = ResultDialogFactory.makeDialog(
|
||||
myTracks, results, clickListener, clickListener, null);
|
||||
dialog.show();
|
||||
|
||||
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_POSITIVE).getVisibility());
|
||||
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_NEGATIVE).getVisibility());
|
||||
}
|
||||
}
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 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.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests {@link ResultListAdapter}.
|
||||
*
|
||||
* @author Matthew Simmons
|
||||
*/
|
||||
public class ResultListAdapterTest extends AndroidTestCase {
|
||||
private static class TestResultListAdapter extends ResultListAdapter {
|
||||
public View contentView;
|
||||
public int drawableId;
|
||||
public int nameId;
|
||||
public int urlId;
|
||||
|
||||
public TestResultListAdapter(Context context, List<SendResult> results) {
|
||||
super(context, 0, results);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setImage(View content, int drawableId) {
|
||||
saveContentView(content);
|
||||
this.drawableId = drawableId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setName(View content, int nameId) {
|
||||
saveContentView(content);
|
||||
this.nameId = nameId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUrl(View content, int urlId) {
|
||||
saveContentView(content);
|
||||
this.urlId = urlId;
|
||||
}
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
private void saveContentView(View contentView) {
|
||||
if (this.contentView == null) {
|
||||
this.contentView = contentView;
|
||||
} else {
|
||||
AndroidTestCase.assertEquals(this.contentView, contentView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final SendType sendType = SendType.MYMAPS;
|
||||
|
||||
private View inflateContentView(int viewId) {
|
||||
LayoutInflater layoutInflater
|
||||
= (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
return layoutInflater.inflate(viewId, null);
|
||||
}
|
||||
|
||||
private List<SendResult> makeResult(SendType type, boolean success) {
|
||||
List<SendResult> results = new ArrayList<SendResult>();
|
||||
results.add(new SendResult(type, success));
|
||||
return results;
|
||||
}
|
||||
|
||||
public void testSuccess_createsNewView() {
|
||||
TestResultListAdapter adapter = new TestResultListAdapter(getContext(),
|
||||
makeResult(sendType, true));
|
||||
adapter.getView(0, null, null);
|
||||
|
||||
assertEquals(R.drawable.success, adapter.drawableId);
|
||||
assertEquals(sendType.getServiceName(), adapter.nameId);
|
||||
assertEquals(sendType.getServiceUrl(), adapter.urlId);
|
||||
}
|
||||
|
||||
public void testSuccess_reusesView() {
|
||||
View contentView = inflateContentView(R.layout.send_to_google_result_list_item);
|
||||
TestResultListAdapter adapter = new TestResultListAdapter(getContext(),
|
||||
makeResult(sendType, true));
|
||||
adapter.getView(0, contentView, null);
|
||||
|
||||
assertEquals(contentView, adapter.contentView);
|
||||
assertEquals(R.drawable.success, adapter.drawableId);
|
||||
assertEquals(sendType.getServiceName(), adapter.nameId);
|
||||
assertEquals(sendType.getServiceUrl(), adapter.urlId);
|
||||
}
|
||||
|
||||
public void testFailure() {
|
||||
TestResultListAdapter adapter = new TestResultListAdapter(getContext(),
|
||||
makeResult(sendType, false));
|
||||
adapter.getView(0, null, null);
|
||||
|
||||
assertEquals(R.drawable.failure, adapter.drawableId);
|
||||
assertEquals(sendType.getServiceName(), adapter.nameId);
|
||||
assertEquals(sendType.getServiceUrl(), adapter.urlId);
|
||||
}
|
||||
}
|
||||
+285
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* 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.content.Track;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils}.
|
||||
*
|
||||
* @author jshih@google.com (Jimmy Shih)
|
||||
*/
|
||||
public class SendFusionTablesUtilsTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getMapUrl(Track)} with null track.
|
||||
*/
|
||||
public void testGetMapUrl_null_track() {
|
||||
assertEquals(null, SendFusionTablesUtils.getMapUrl(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getMapUrl(Track)} with null table id.
|
||||
*/
|
||||
public void testGetMapUrl_null_table_id() {
|
||||
Track track = new Track();
|
||||
TripStatistics stats = new TripStatistics();
|
||||
stats.setBounds((int) 100.E6, (int) 10.E6, (int) 50.E6, (int) 5.E6);
|
||||
track.setStatistics(stats);
|
||||
track.setTableId(null);
|
||||
assertEquals(null, SendFusionTablesUtils.getMapUrl(track));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getMapUrl(Track)} with null stats.
|
||||
*/
|
||||
public void testGetMapUrl_null_stats() {
|
||||
Track track = new Track();
|
||||
track.setStatistics(null);
|
||||
track.setTableId("123");
|
||||
assertEquals(null, SendFusionTablesUtils.getMapUrl(track));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getMapUrl(Track)} with a valid track.
|
||||
*/
|
||||
public void testGetMapUrl_valid_track() {
|
||||
Track track = new Track();
|
||||
TripStatistics stats = new TripStatistics();
|
||||
stats.setBounds((int) 100.E6, (int) 10.E6, (int) 50.E6, (int) 5.E6);
|
||||
track.setStatistics(stats);
|
||||
track.setTableId("123");
|
||||
assertEquals(
|
||||
"https://www.google.com/fusiontables/embedviz?"
|
||||
+ "viz=MAP&q=select+col0,+col1,+col2,+col3+from+123+&h=false&lat=7.500000&lng=75.000000"
|
||||
+ "&z=15&t=1&l=col2", SendFusionTablesUtils.getMapUrl(track));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests (@link {@link SendFusionTablesUtils#formatSqlValues(String...)} with
|
||||
* no value.
|
||||
*/
|
||||
public void testFormatSqlValues_no_value() {
|
||||
assertEquals("()", SendFusionTablesUtils.formatSqlValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests (@link {@link SendFusionTablesUtils#formatSqlValues(String...)} with
|
||||
* an empty string.
|
||||
*/
|
||||
public void testFormatSqlValues_empty_string() {
|
||||
assertEquals("(\'\')", SendFusionTablesUtils.formatSqlValues(""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests (@link {@link SendFusionTablesUtils#formatSqlValues(String...)} with
|
||||
* one value.
|
||||
*/
|
||||
public void testFormatSqlValues_one_value() {
|
||||
assertEquals("(\'first\')", SendFusionTablesUtils.formatSqlValues("first"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests (@link {@link SendFusionTablesUtils#formatSqlValues(String...)} with
|
||||
* two values.
|
||||
*/
|
||||
public void testFormatSqlValues_two_values() {
|
||||
assertEquals(
|
||||
"(\'first\',\'second\')", SendFusionTablesUtils.formatSqlValues("first", "second"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#escapeSqlString(String)} with a value
|
||||
* containing several single quotes.
|
||||
*/
|
||||
public void testEscapeSqValuel() {
|
||||
String value = "let's'";
|
||||
assertEquals("let''s''", SendFusionTablesUtils.escapeSqlString(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getKmlPoint(Location)} with a null
|
||||
* point.
|
||||
*/
|
||||
public void testGetKmlPoint_null_point() {
|
||||
assertEquals(
|
||||
"<Point><coordinates></coordinates></Point>", SendFusionTablesUtils.getKmlPoint(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getKmlPoint(Location)} with a valid
|
||||
* point.
|
||||
*/
|
||||
public void testGetKmlPoint_valid_point() {
|
||||
Location location = new Location("test");
|
||||
location.setLongitude(10.1);
|
||||
location.setLatitude(20.2);
|
||||
location.setAltitude(30.3);
|
||||
assertEquals("<Point><coordinates>10.1,20.2,30.3</coordinates></Point>",
|
||||
SendFusionTablesUtils.getKmlPoint(location));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getKmlLineString(ArrayList)} with a null
|
||||
* locations.
|
||||
*/
|
||||
public void testKmlLineString_null_locations() {
|
||||
assertEquals("<LineString><coordinates></coordinates></LineString>",
|
||||
SendFusionTablesUtils.getKmlLineString(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getKmlLineString(ArrayList)} with no
|
||||
* location.
|
||||
*/
|
||||
public void testKmlLineString_no_location() {
|
||||
ArrayList<Location> locations = new ArrayList<Location>();
|
||||
assertEquals("<LineString><coordinates></coordinates></LineString>",
|
||||
SendFusionTablesUtils.getKmlLineString(locations));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getKmlLineString(ArrayList)} with one
|
||||
* location.
|
||||
*/
|
||||
public void testKmlLineString_one_location() {
|
||||
ArrayList<Location> locations = new ArrayList<Location>();
|
||||
Location location = new Location("test");
|
||||
location.setLongitude(10.1);
|
||||
location.setLatitude(20.2);
|
||||
location.setAltitude(30.3);
|
||||
locations.add(location);
|
||||
assertEquals("<LineString><coordinates>10.1,20.2,30.3</coordinates></LineString>",
|
||||
SendFusionTablesUtils.getKmlLineString(locations));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getKmlLineString(ArrayList)} with two
|
||||
* locations.
|
||||
*/
|
||||
public void testKmlLineString_two_locations() {
|
||||
ArrayList<Location> locations = new ArrayList<Location>();
|
||||
Location location1 = new Location("test");
|
||||
location1.setLongitude(10.1);
|
||||
location1.setLatitude(20.2);
|
||||
location1.setAltitude(30.3);
|
||||
locations.add(location1);
|
||||
|
||||
Location location2 = new Location("test");
|
||||
location2.setLongitude(1.1);
|
||||
location2.setLatitude(2.2);
|
||||
location2.removeAltitude();
|
||||
locations.add(location2);
|
||||
|
||||
assertEquals("<LineString><coordinates>10.1,20.2,30.3 1.1,2.2</coordinates></LineString>",
|
||||
SendFusionTablesUtils.getKmlLineString(locations));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#appendLocation(Location, StringBuilder)}
|
||||
* with no altitude.
|
||||
*/
|
||||
public void testAppendLocation_no_altitude() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Location location = new Location("test");
|
||||
location.setLongitude(10.1);
|
||||
location.setLatitude(20.2);
|
||||
location.removeAltitude();
|
||||
SendFusionTablesUtils.appendLocation(location, builder);
|
||||
assertEquals("10.1,20.2", builder.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#appendLocation(Location, StringBuilder)}
|
||||
* with altitude.
|
||||
*/
|
||||
public void testAppendLocation_has_altitude() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Location location = new Location("test");
|
||||
location.setLongitude(10.1);
|
||||
location.setLatitude(20.2);
|
||||
location.setAltitude(30.3);
|
||||
SendFusionTablesUtils.appendLocation(location, builder);
|
||||
assertEquals("10.1,20.2,30.3", builder.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getTableId(InputStream)} with a null
|
||||
* inputstream.
|
||||
*/
|
||||
public void testGetTableId_null() {
|
||||
assertEquals(null, SendFusionTablesUtils.getTableId(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getTableId(InputStream)} with an
|
||||
* inputstream containing no data.
|
||||
*/
|
||||
public void testGetTableId_no_data() {
|
||||
InputStream inputStream = new ByteArrayInputStream(new byte[0]);
|
||||
assertEquals(null, SendFusionTablesUtils.getTableId(inputStream));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getTableId(InputStream)} with an empty
|
||||
* inputstream.
|
||||
*/
|
||||
public void testGetTableId_empty() {
|
||||
String string = "";
|
||||
InputStream inputStream = new ByteArrayInputStream(string.getBytes());
|
||||
assertEquals(null, SendFusionTablesUtils.getTableId(inputStream));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getTableId(InputStream)} with an one
|
||||
* line inputstream.
|
||||
*/
|
||||
public void testGetTableId_one_line() {
|
||||
String string = "tableid";
|
||||
InputStream inputStream = new ByteArrayInputStream(string.getBytes());
|
||||
assertEquals(null, SendFusionTablesUtils.getTableId(inputStream));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getTableId(InputStream)} with an
|
||||
* inputstream not containing "tableid".
|
||||
*/
|
||||
public void testGetTableId_no_table_id() {
|
||||
String string = "error\n123";
|
||||
InputStream inputStream = new ByteArrayInputStream(string.getBytes());
|
||||
assertEquals(null, SendFusionTablesUtils.getTableId(inputStream));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendFusionTablesUtils#getTableId(InputStream)} with a valid
|
||||
* inputstream.
|
||||
*/
|
||||
public void testGetTableId() {
|
||||
String string = "tableid\n123";
|
||||
InputStream inputStream = null;
|
||||
inputStream = new ByteArrayInputStream(string.getBytes());
|
||||
assertEquals("123", SendFusionTablesUtils.getTableId(inputStream));
|
||||
}
|
||||
}
|
||||
+37
-30
@@ -16,48 +16,55 @@
|
||||
package com.google.android.apps.mytracks.services;
|
||||
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Tests {@link DefaultTrackNameFactory}
|
||||
*
|
||||
*
|
||||
* @author Matthew Simmons
|
||||
*/
|
||||
public class DefaultTrackNameFactoryTest extends AndroidTestCase {
|
||||
/**
|
||||
* A version of the factory which allows us to supply our own answer as to
|
||||
* whether a timestamp-based track name should be used.
|
||||
*/
|
||||
private static class MockDefaultTrackNameFactory
|
||||
extends DefaultTrackNameFactory {
|
||||
private final boolean useTimestamp;
|
||||
|
||||
MockDefaultTrackNameFactory(Context context, boolean useTimestamp) {
|
||||
super(context);
|
||||
this.useTimestamp = useTimestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean useTimestampTrackName() {
|
||||
return useTimestamp;
|
||||
}
|
||||
}
|
||||
|
||||
private static final long TIMESTAMP = 1288213406000L;
|
||||
private static final long TRACK_ID = 1L;
|
||||
private static final long START_TIME = 1288213406000L;
|
||||
|
||||
public void testTimestampTrackName() {
|
||||
DefaultTrackNameFactory factory =
|
||||
new MockDefaultTrackNameFactory(getContext(), true);
|
||||
|
||||
assertEquals(StringUtils.formatDateTime(TIMESTAMP), factory.newTrackName(1, TIMESTAMP));
|
||||
public void testDefaultTrackName_date_local() {
|
||||
DefaultTrackNameFactory defaultTrackNameFactory = new DefaultTrackNameFactory(getContext()) {
|
||||
@Override
|
||||
String getTrackNameSetting() {
|
||||
return getContext().getString(R.string.settings_recording_track_name_date_local_value);
|
||||
}
|
||||
};
|
||||
assertEquals(StringUtils.formatDateTime(getContext(), START_TIME),
|
||||
defaultTrackNameFactory.getDefaultTrackName(TRACK_ID, START_TIME));
|
||||
}
|
||||
|
||||
public void testIncrementingTrackName() {
|
||||
DefaultTrackNameFactory factory =
|
||||
new MockDefaultTrackNameFactory(getContext(), false);
|
||||
public void testDefaultTrackName_date_iso_8601() {
|
||||
DefaultTrackNameFactory defaultTrackNameFactory = new DefaultTrackNameFactory(getContext()) {
|
||||
@Override
|
||||
String getTrackNameSetting() {
|
||||
return getContext().getString(R.string.settings_recording_track_name_date_iso_8601_value);
|
||||
}
|
||||
};
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
|
||||
DefaultTrackNameFactory.ISO_8601_FORMAT);
|
||||
assertEquals(simpleDateFormat.format(new Date(START_TIME)),
|
||||
defaultTrackNameFactory.getDefaultTrackName(TRACK_ID, START_TIME));
|
||||
}
|
||||
|
||||
assertEquals("Track 1", factory.newTrackName(1, TIMESTAMP));
|
||||
public void testDefaultTrackName_number() {
|
||||
DefaultTrackNameFactory defaultTrackNameFactory = new DefaultTrackNameFactory(getContext()) {
|
||||
@Override
|
||||
String getTrackNameSetting() {
|
||||
return getContext().getString(R.string.settings_recording_track_name_number_value);
|
||||
}
|
||||
};
|
||||
assertEquals(
|
||||
"Track " + TRACK_ID, defaultTrackNameFactory.getDefaultTrackName(TRACK_ID, START_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,6 @@ import junit.framework.TestCase;
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class FileUtilsTest extends TestCase {
|
||||
private static final String ORIGINAL_NAME = "Swim\10ming-^across: the/ pacific (ocean).";
|
||||
private static final String SANITIZED_NAME = "Swimming-across the pacific (ocean).";
|
||||
|
||||
private FileUtils fileUtils;
|
||||
private Set<String> existingFiles;
|
||||
|
||||
@@ -65,31 +62,83 @@ public class FileUtilsTest extends TestCase {
|
||||
assertEquals(expectedName, dirName);
|
||||
}
|
||||
|
||||
public void testSanitizeName() {
|
||||
assertEquals(SANITIZED_NAME, fileUtils.sanitizeName(ORIGINAL_NAME));
|
||||
/**
|
||||
* Tests sanitize filename.
|
||||
*/
|
||||
public void testSanitizeFileName() {
|
||||
String name = "Swim\10ming-^across:/the/ pacific (ocean).";
|
||||
String expected = "Swim_ming-^across_the_ pacific (ocean)_";
|
||||
assertEquals(expected, fileUtils.sanitizeFileName(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests characters in other languages, like Chinese and Russian, are allowed.
|
||||
*/
|
||||
public void testSanitizeFileName_i18n() {
|
||||
String name = "您好-привет";
|
||||
String expected = "您好-привет";
|
||||
|
||||
assertEquals(expected, fileUtils.sanitizeFileName(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests special FAT32 characters are allowed.
|
||||
*/
|
||||
public void testSanitizeFileName_special_characters() {
|
||||
String name = "$%'-_@~`!(){}^#&+,;=[] ";
|
||||
String expected = "$%'-_@~`!(){}^#&+,;=[] ";
|
||||
|
||||
assertEquals(expected, fileUtils.sanitizeFileName(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing collapsing multiple underscores characters.
|
||||
*/
|
||||
public void testSanitizeFileName_collapse() {
|
||||
String name = "hello//there";
|
||||
String expected = "hello_there";
|
||||
|
||||
assertEquals(expected, fileUtils.sanitizeFileName(name));
|
||||
}
|
||||
|
||||
public void testTruncateFileName() {
|
||||
File directory = new File("/dir1/dir2/");
|
||||
String suffix = ".gpx";
|
||||
char[] name = new char[FileUtils.MAX_FAT32_PATH_LENGTH];
|
||||
for (int i = 0; i < name.length; i++) {
|
||||
name[i] = 'a';
|
||||
}
|
||||
String nameString = new String(name);
|
||||
|
||||
String truncated = fileUtils.truncateFileName(directory, nameString, suffix);
|
||||
for (int i = 0; i < truncated.length(); i++) {
|
||||
assertEquals('a', truncated.charAt(i));
|
||||
}
|
||||
assertEquals(FileUtils.MAX_FAT32_PATH_LENGTH,
|
||||
new File(directory, truncated + suffix).getPath().length());
|
||||
}
|
||||
|
||||
public void testBuildUniqueFileName_someExist() {
|
||||
existingFiles = new HashSet<String>();
|
||||
existingFiles.add("Filename.ext");
|
||||
existingFiles.add("Filename (1).ext");
|
||||
existingFiles.add("Filename (2).ext");
|
||||
existingFiles.add("Filename (3).ext");
|
||||
existingFiles.add("Filename (4).ext");
|
||||
existingFiles.add("Filename(1).ext");
|
||||
existingFiles.add("Filename(2).ext");
|
||||
existingFiles.add("Filename(3).ext");
|
||||
existingFiles.add("Filename(4).ext");
|
||||
|
||||
String filename = fileUtils.buildUniqueFileName(null, "Filename", "ext");
|
||||
assertEquals("Filename (5).ext", filename);
|
||||
String filename = fileUtils.buildUniqueFileName(new File("/dir/"), "Filename", "ext");
|
||||
assertEquals("Filename(5).ext", filename);
|
||||
}
|
||||
|
||||
public void testBuildUniqueFileName_oneExists() {
|
||||
existingFiles.add("Filename.ext");
|
||||
|
||||
String filename = fileUtils.buildUniqueFileName(null, "Filename", "ext");
|
||||
assertEquals("Filename (1).ext", filename);
|
||||
String filename = fileUtils.buildUniqueFileName(new File("/dir/"), "Filename", "ext");
|
||||
assertEquals("Filename(1).ext", filename);
|
||||
}
|
||||
|
||||
public void testBuildUniqueFileName_noneExists() {
|
||||
String filename = fileUtils.buildUniqueFileName(null, "Filename", "ext");
|
||||
String filename = fileUtils.buildUniqueFileName(new File("/dir/"), "Filename", "ext");
|
||||
assertEquals("Filename.ext", filename);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user