forked from upstream-mirrors/OpenTracks
merge heads
This commit is contained in:
@@ -11,5 +11,6 @@
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/MyTracks"/>
|
||||
<classpathentry kind="lib" path="libs/AndroidMockGenerator.jar"/>
|
||||
<classpathentry kind="lib" path="libs/robotium-solo-3.1.jar"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
|
||||
@@ -15,16 +15,9 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:debuggable="true"
|
||||
package="com.google.android.maps.mytracks.test"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0"
|
||||
package="com.google.android.maps.mytracks.test" >
|
||||
|
||||
<application
|
||||
android:icon="@android:drawable/sym_def_app_icon"
|
||||
android:label="My Tracks Tests" >
|
||||
<uses-library android:name="android.test.runner" />
|
||||
</application>
|
||||
android:versionName="1.0" >
|
||||
|
||||
<instrumentation
|
||||
android:name="android.test.InstrumentationTestRunner"
|
||||
@@ -34,4 +27,10 @@ limitations under the License.
|
||||
android:minSdkVersion="7"
|
||||
android:targetSdkVersion="15" />
|
||||
|
||||
<application
|
||||
android:icon="@android:drawable/sym_def_app_icon"
|
||||
android:label="My Tracks Tests" >
|
||||
<uses-library android:name="android.test.runner" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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.maps.mytracks.R;
|
||||
import com.jayway.android.robotium.solo.Solo;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Intent;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Tests the {@link UploadResultActivity}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class UploadResultActivityTest extends
|
||||
ActivityInstrumentationTestCase2<UploadResultActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private UploadResultActivity uploadResultActivity;
|
||||
private Solo solo;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
solo = new Solo(instrumentation);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is necessary for ActivityInstrumentationTestCase2.
|
||||
*/
|
||||
public UploadResultActivityTest() {
|
||||
super(UploadResultActivity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the display of dialog when send to all and all sends are successful.
|
||||
*/
|
||||
public void testAllSuccess() {
|
||||
initialActivity(true, true, true, true, true, true);
|
||||
|
||||
HashSet<String> stringHashSet = new HashSet<String>();
|
||||
ArrayList<View> view = solo.getViews();
|
||||
for (View oneView : view) {
|
||||
if (oneView instanceof TextView && oneView.isShown()) {
|
||||
stringHashSet.add((String) ((TextView) oneView).getText());
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.generic_success_title)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_maps)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_fusion_tables)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_docs)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_success_footer)));
|
||||
|
||||
assertFalse(stringHashSet
|
||||
.contains(uploadResultActivity.getString(R.string.generic_error_title)));
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_error)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the display of dialog when send to all and all sends are failed.
|
||||
*/
|
||||
public void testAllFailed() {
|
||||
// Send all kinds but all failed.
|
||||
initialActivity(true, true, true, false, false, false);
|
||||
HashSet<String> stringHashSet = new HashSet<String>();
|
||||
ArrayList<View> view = solo.getViews();
|
||||
for (View oneView : view) {
|
||||
if (oneView instanceof TextView && oneView.isShown()) {
|
||||
stringHashSet.add((String) ((TextView) oneView).getText());
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(stringHashSet.contains((Object) uploadResultActivity
|
||||
.getString(R.string.generic_error_title)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_maps)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_fusion_tables)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_docs)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_error)));
|
||||
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.generic_success_title)));
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_success_footer)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the display of dialog when match following items:
|
||||
* <ul>
|
||||
* <li>Only send to Maps and Docs.</li>
|
||||
* <li>Send to Maps successful.</li>
|
||||
* <li>Send to Docs failed.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public void testPartialSuccess() {
|
||||
initialActivity(true, false, true, true, false, false);
|
||||
|
||||
HashSet<String> stringHashSet = new HashSet<String>();
|
||||
ArrayList<View> view = solo.getViews();
|
||||
for (View oneView : view) {
|
||||
if (oneView instanceof TextView && oneView.isShown()) {
|
||||
stringHashSet.add((String) ((TextView) oneView).getText());
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.generic_error_title)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_maps)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_docs)));
|
||||
assertTrue(stringHashSet.contains(uploadResultActivity.getString(R.string.send_google_error)));
|
||||
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_fusion_tables)));
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.generic_success_title)));
|
||||
assertFalse(stringHashSet.contains(uploadResultActivity
|
||||
.getString(R.string.send_google_success_footer)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial a {@link SendRequest} and then initials a activity to be tested.
|
||||
*
|
||||
* @param isSendMaps
|
||||
* @param isSendFusionTables
|
||||
* @param isSendDocs
|
||||
* @param isMapsSuccess
|
||||
* @param isFusionTablesSuccess
|
||||
* @param isDocsSuccess
|
||||
*/
|
||||
private void initialActivity(boolean isSendMaps, boolean isSendFusionTables, boolean isSendDocs,
|
||||
boolean isMapsSuccess, boolean isFusionTablesSuccess, boolean isDocsSuccess) {
|
||||
Intent intent = new Intent();
|
||||
SendRequest sendRequest = new SendRequest(1L, true, true, true);
|
||||
sendRequest.setSendMaps(isSendMaps);
|
||||
sendRequest.setSendFusionTables(isSendFusionTables);
|
||||
sendRequest.setSendDocs(isSendDocs);
|
||||
sendRequest.setMapsSuccess(isMapsSuccess);
|
||||
sendRequest.setFusionTablesSuccess(isFusionTablesSuccess);
|
||||
sendRequest.setDocsSuccess(isDocsSuccess);
|
||||
intent.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
setActivityIntent(intent);
|
||||
uploadResultActivity = this.getActivity();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,8 +20,6 @@ import com.google.android.apps.mytracks.Constants;
|
||||
import android.os.Environment;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -31,76 +29,81 @@ import junit.framework.TestCase;
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class FileUtilsTest extends TestCase {
|
||||
private FileUtils fileUtils;
|
||||
private Set<String> existingFiles;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
existingFiles = new HashSet<String>();
|
||||
fileUtils = new FileUtils() {
|
||||
@Override
|
||||
protected boolean fileExists(File directory, String fullName) {
|
||||
return existingFiles.contains(fullName);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link FileUtils#buildExternalDirectoryPath(String...)}.
|
||||
*/
|
||||
public void testBuildExternalDirectoryPath() {
|
||||
String expectedName = Environment.getExternalStorageDirectory()
|
||||
+ File.separator
|
||||
+ Constants.SDCARD_TOP_DIR
|
||||
+ File.separator
|
||||
+ "a"
|
||||
+ File.separator
|
||||
+ "b"
|
||||
+ File.separator
|
||||
String expectedName = Environment.getExternalStorageDirectory() + File.separator
|
||||
+ Constants.SDCARD_TOP_DIR + File.separator + "a" + File.separator + "b" + File.separator
|
||||
+ "c";
|
||||
|
||||
String dirName = fileUtils.buildExternalDirectoryPath("a", "b", "c");
|
||||
String dirName = FileUtils.buildExternalDirectoryPath("a", "b", "c");
|
||||
assertEquals(expectedName, dirName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests sanitize filename.
|
||||
* Tests {@link FileUtils#buildUniqueFileName(File, String, String)} when the
|
||||
* file is new.
|
||||
*/
|
||||
public void testBuildUniqueFileName_new() {
|
||||
String filename = FileUtils.buildUniqueFileName(new File("/dir"), "Filename", "ext");
|
||||
assertEquals("Filename.ext", filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link FileUtils#buildUniqueFileName(File, String, String)} when the
|
||||
* file exists already.
|
||||
*/
|
||||
public void testBuildUniqueFileName_exist() {
|
||||
// Expect "/default.prop" to exist on the phone/emulator
|
||||
String filename = FileUtils.buildUniqueFileName(new File("/"), "default", "prop");
|
||||
assertEquals("default(1).prop", filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link FileUtils#sanitizeFileName(String)} with special characters.
|
||||
* Verifies that they are sanitized.
|
||||
*/
|
||||
public void testSanitizeFileName() {
|
||||
String name = "Swim\10ming-^across:/the/ pacific (ocean).";
|
||||
String expected = "Swim_ming-^across_the_ pacific (ocean)_";
|
||||
assertEquals(expected, fileUtils.sanitizeFileName(name));
|
||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests characters in other languages, like Chinese and Russian, are allowed.
|
||||
* Tests {@link FileUtils#sanitizeFileName(String)} with i18n characters (in
|
||||
* Chinese and Russian). Verifies that they are allowed.
|
||||
*/
|
||||
public void testSanitizeFileName_i18n() {
|
||||
String name = "您好-привет";
|
||||
String expected = "您好-привет";
|
||||
|
||||
assertEquals(expected, fileUtils.sanitizeFileName(name));
|
||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests special FAT32 characters are allowed.
|
||||
* Tests {@link FileUtils#sanitizeFileName(String)} with special FAT32
|
||||
* characters. Verifies that they are allowed.
|
||||
*/
|
||||
public void testSanitizeFileName_special_characters() {
|
||||
String name = "$%'-_@~`!(){}^#&+,;=[] ";
|
||||
String expected = "$%'-_@~`!(){}^#&+,;=[] ";
|
||||
|
||||
assertEquals(expected, fileUtils.sanitizeFileName(name));
|
||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing collapsing multiple underscores characters.
|
||||
* Tests {@link FileUtils#sanitizeFileName(String)} with multiple escaped
|
||||
* characters in a row. Verifies that they are collapsed into one underscore.
|
||||
*/
|
||||
public void testSanitizeFileName_collapse() {
|
||||
String name = "hello//there";
|
||||
String expected = "hello_there";
|
||||
|
||||
assertEquals(expected, fileUtils.sanitizeFileName(name));
|
||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link FileUtils#truncateFileName(File, String, String)}. Verifies
|
||||
* the a long file name is truncated.
|
||||
*/
|
||||
public void testTruncateFileName() {
|
||||
File directory = new File("/dir1/dir2/");
|
||||
String suffix = ".gpx";
|
||||
@@ -109,36 +112,12 @@ public class FileUtilsTest extends TestCase {
|
||||
name[i] = 'a';
|
||||
}
|
||||
String nameString = new String(name);
|
||||
|
||||
String truncated = fileUtils.truncateFileName(directory, nameString, suffix);
|
||||
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");
|
||||
|
||||
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(new File("/dir/"), "Filename", "ext");
|
||||
assertEquals("Filename(1).ext", filename);
|
||||
}
|
||||
|
||||
public void testBuildUniqueFileName_noneExists() {
|
||||
String filename = fileUtils.buildUniqueFileName(new File("/dir/"), "Filename", "ext");
|
||||
assertEquals("Filename.ext", filename);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user