mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-06 19:43:06 +02:00
merge heads
This commit is contained in:
+5
-23
@@ -24,7 +24,6 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
@@ -59,7 +58,6 @@ public class UploadServiceChooserActivityTest extends
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getFusionTablesCheckBox().isShown());
|
||||
assertTrue(getDocsCheckBox().isShown());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
|
||||
// Clicks to disable all send items.
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
@@ -79,11 +77,9 @@ public class UploadServiceChooserActivityTest extends
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getFusionTablesCheckBox().isShown());
|
||||
assertTrue(getDocsCheckBox().isShown());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
|
||||
assertFalse(getNewMapRadioButton().isShown());
|
||||
assertFalse(getExistingMapRadioButton().isShown());
|
||||
assertFalse(getSendButton().isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +90,6 @@ public class UploadServiceChooserActivityTest extends
|
||||
initialActivity(true, false, false);
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
|
||||
// Clicks to enable this items.
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
@@ -108,8 +103,6 @@ public class UploadServiceChooserActivityTest extends
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getNewMapRadioButton().isShown());
|
||||
assertTrue(getExistingMapRadioButton().isShown());
|
||||
assertTrue(getSendButton().isEnabled());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,8 +113,6 @@ public class UploadServiceChooserActivityTest extends
|
||||
assertFalse(getMapsCheckBox().isShown());
|
||||
assertFalse(getFusionTablesCheckBox().isShown());
|
||||
assertFalse(getDocsCheckBox().isShown());
|
||||
assertFalse(getSendButton().isEnabled());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,35 +250,26 @@ public class UploadServiceChooserActivityTest extends
|
||||
uploadServiceChooserActivity = this.getActivity();
|
||||
}
|
||||
|
||||
private Button getSendButton() {
|
||||
return (Button) uploadServiceChooserActivity.getDialog()
|
||||
.findViewById(R.id.send_google_send_now);
|
||||
}
|
||||
|
||||
Button getCancelButton() {
|
||||
return (Button) uploadServiceChooserActivity.getDialog().findViewById(R.id.send_google_cancel);
|
||||
}
|
||||
|
||||
private CheckBox getMapsCheckBox() {
|
||||
return (CheckBox) uploadServiceChooserActivity.getDialog().findViewById(R.id.send_google_maps);
|
||||
return (CheckBox) uploadServiceChooserActivity.getAlertDialog().findViewById(R.id.send_google_maps);
|
||||
}
|
||||
|
||||
private CheckBox getFusionTablesCheckBox() {
|
||||
return (CheckBox) uploadServiceChooserActivity.getDialog().findViewById(
|
||||
return (CheckBox) uploadServiceChooserActivity.getAlertDialog().findViewById(
|
||||
R.id.send_google_fusion_tables);
|
||||
}
|
||||
|
||||
private CheckBox getDocsCheckBox() {
|
||||
return (CheckBox) uploadServiceChooserActivity.getDialog().findViewById(R.id.send_google_docs);
|
||||
return (CheckBox) uploadServiceChooserActivity.getAlertDialog().findViewById(R.id.send_google_docs);
|
||||
}
|
||||
|
||||
private RadioButton getNewMapRadioButton() {
|
||||
return (RadioButton) uploadServiceChooserActivity.getDialog().findViewById(
|
||||
return (RadioButton) uploadServiceChooserActivity.getAlertDialog().findViewById(
|
||||
R.id.send_google_new_map);
|
||||
}
|
||||
|
||||
private RadioButton getExistingMapRadioButton() {
|
||||
return (RadioButton) uploadServiceChooserActivity.getDialog().findViewById(
|
||||
return (RadioButton) uploadServiceChooserActivity.getAlertDialog().findViewById(
|
||||
R.id.send_google_existing_map);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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