aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/files
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/cgeo/geocaching/files')
-rw-r--r--tests/src/cgeo/geocaching/files/GPXImporterTest.java34
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java42
-rw-r--r--tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java84
3 files changed, 113 insertions, 47 deletions
diff --git a/tests/src/cgeo/geocaching/files/GPXImporterTest.java b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
index da99c11..8c05ee0 100644
--- a/tests/src/cgeo/geocaching/files/GPXImporterTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
@@ -3,7 +3,7 @@ package cgeo.geocaching.files;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Settings;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.cgData;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
@@ -71,8 +71,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
assertEquals(GPXImporter.IMPORT_STEP_FINISHED, iMsg.next().what);
SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj;
assertEquals(Collections.singletonList(geocode), new ArrayList<String>(search.getGeocodes()));
-
- cgCache cache = cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ cgCache cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
assertCacheProperties(cache);
assertTrue(cache.getWaypoints().isEmpty());
@@ -99,8 +98,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_READ_WPT_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED);
SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj;
assertEquals(Collections.singletonList("GC31J2H"), new ArrayList<String>(search.getGeocodes()));
-
- cgCache cache = cgeoapplication.getInstance().loadCache("GC31J2H", LoadFlags.LOAD_CACHE_OR_DB);
+ cgCache cache = cgData.loadCache("GC31J2H", LoadFlags.LOAD_CACHE_OR_DB);
assertCacheProperties(cache);
assertEquals(2, cache.getWaypoints().size());
}
@@ -113,8 +111,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
runImportThread(importThread);
assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED);
-
- final cgCache cache = cgeoapplication.getInstance().loadCache("AID1", LoadFlags.LOAD_CACHE_OR_DB);
+ final cgCache cache = cgData.loadCache("AID1", LoadFlags.LOAD_CACHE_OR_DB);
assertCacheProperties(cache);
assertEquals("First Aid Station #1", cache.getName());
}
@@ -136,8 +133,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED);
SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj;
assertEquals(Collections.singletonList("OC5952"), new ArrayList<String>(search.getGeocodes()));
-
- cgCache cache = cgeoapplication.getInstance().loadCache("OC5952", LoadFlags.LOAD_CACHE_OR_DB);
+ cgCache cache = cgData.loadCache("OC5952", LoadFlags.LOAD_CACHE_OR_DB);
assertCacheProperties(cache);
}
@@ -179,8 +175,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED);
SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj;
assertEquals(Collections.singletonList(geocode), new ArrayList<String>(search.getGeocodes()));
-
- cgCache cache = cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ cgCache cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
assertCacheProperties(cache);
assertTrue(cache.getWaypoints().isEmpty());
@@ -198,8 +193,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_READ_WPT_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED);
SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj;
assertEquals(Collections.singletonList(geocode), new ArrayList<String>(search.getGeocodes()));
-
- cgCache cache = cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ cgCache cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
assertCacheProperties(cache);
assertEquals(1, cache.getWaypoints().size()); // this is the original pocket query result without test waypoint
}
@@ -225,8 +219,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_READ_WPT_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED);
SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj;
assertEquals(Collections.singletonList(geocode), new ArrayList<String>(search.getGeocodes()));
-
- cgCache cache = cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ cgCache cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
assertCacheProperties(cache);
assertEquals(1, cache.getWaypoints().size()); // this is the original pocket query result without test waypoint
}
@@ -266,10 +259,9 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
tempDir = new File(System.getProperty("java.io.tmpdir"), "cgeogpxesTest");
tempDir.mkdir();
-
// workaround to get storage initialized
- cgeoapplication.getInstance().getAllHistoricCachesCount();
- listId = cgeoapplication.getInstance().createList("cgeogpxesTest");
+ cgData.getAllHistoryCachesCount();
+ listId = cgData.createList("cgeogpxesTest");
importCacheStaticMaps = Settings.isStoreOfflineMaps();
Settings.setStoreOfflineMaps(true);
@@ -279,11 +271,11 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
@Override
protected void tearDown() throws Exception {
- SearchResult search = cgeoapplication.getInstance().getBatchOfStoredCaches(false, null, CacheType.ALL, listId);
+ SearchResult search = cgData.getBatchOfStoredCaches(null, CacheType.ALL, listId);
List<cgCache> cachesInList = new ArrayList<cgCache>();
cachesInList.addAll(search.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB));
- cgeoapplication.getInstance().markDropped(cachesInList);
- cgeoapplication.getInstance().removeList(listId);
+ cgData.markDropped(cachesInList);
+ cgData.removeList(listId);
deleteDirectory(tempDir);
Settings.setStoreOfflineMaps(importCacheStaticMaps);
Settings.setStoreOfflineWpMaps(importWpStaticMaps);
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 6c3c237..bbb4514 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -4,8 +4,8 @@ import cgeo.geocaching.LogEntry;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.StoredList;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgWaypoint;
-import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.cgData;
+import cgeo.geocaching.Waypoint;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
@@ -24,10 +24,11 @@ import java.util.Collection;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
- private static final SimpleDateFormat LOG_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // 2010-04-20T07:00:00Z
+ private static final SimpleDateFormat LOG_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); // 2010-04-20T07:00:00Z
private int listId;
public void testGPXVersion100() throws Exception {
@@ -166,7 +167,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
private static void assertGc31j2hWaypoints(final cgCache cache) {
assertNotNull(cache.getWaypoints());
assertEquals(2, cache.getWaypoints().size());
- cgWaypoint wp = cache.getWaypoints().get(1);
+ Waypoint wp = cache.getWaypoints().get(1);
assertEquals("GC31J2H", wp.getGeocode());
assertEquals("00", wp.getPrefix());
assertEquals("---", wp.getLookup());
@@ -212,29 +213,19 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
}
}
// reload caches, because the parser only returns the minimum version of each cache
- return new ArrayList<cgCache>(cgeoapplication.getInstance().loadCaches(result, LoadFlags.LOAD_ALL_DB_ONLY));
+ return new ArrayList<cgCache>(cgData.loadCaches(result, LoadFlags.LOAD_ALL_DB_ONLY));
}
- public static void testParseDateWithFractionalSeconds() {
+ public static void testParseDateWithFractionalSeconds() throws ParseException {
// was experienced in GSAK file
final String dateString = "2011-08-13T02:52:18.103Z";
- try {
- GPXParser.parseDate(dateString);
- } catch (ParseException e) {
- fail();
- e.printStackTrace();
- }
+ GPXParser.parseDate(dateString);
}
- public static void testParseDateWithHugeFraction() {
+ public static void testParseDateWithHugeFraction() throws ParseException {
// see issue 821
String dateString = "2011-11-07T00:00:00.0000000-07:00";
- try {
- GPXParser.parseDate(dateString);
- } catch (ParseException e) {
- fail();
- e.printStackTrace();
- }
+ GPXParser.parseDate(dateString);
}
public void testSelfmadeGPXWithoutGeocodes() throws Exception {
@@ -265,10 +256,9 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
removeCacheCompletely(geocode);
final List<cgCache> caches = readGPX10(R.raw.lazy);
assertEquals(1, caches.size());
- cgeoapplication.getInstance().removeAllFromCache();
-
+ cgData.removeAllFromCache();
// load only the minimum cache, it has several members missing
- final cgCache minimalCache = cgeoapplication.getInstance().loadCache(geocode, EnumSet.of(LoadFlag.LOAD_DB_MINIMAL));
+ final cgCache minimalCache = cgData.loadCache(geocode, EnumSet.of(LoadFlag.LOAD_DB_MINIMAL));
// now check that we load lazy members on demand
assertFalse(minimalCache.getAttributes().isEmpty());
@@ -297,17 +287,17 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- listId = cgeoapplication.getInstance().createList("Temporary unit testing");
+ listId = cgData.createList("Temporary unit testing");
assertTrue(listId != StoredList.TEMPORARY_LIST_ID);
assertTrue(listId != StoredList.STANDARD_LIST_ID);
}
@Override
protected void tearDown() throws Exception {
- SearchResult search = cgeoapplication.getInstance().getBatchOfStoredCaches(false, null, CacheType.ALL, listId);
+ SearchResult search = cgData.getBatchOfStoredCaches(null, CacheType.ALL, listId);
assertNotNull(search);
- cgeoapplication.getInstance().removeCaches(search.getGeocodes(), LoadFlags.REMOVE_ALL);
- cgeoapplication.getInstance().removeList(listId);
+ cgData.removeCaches(search.getGeocodes(), LoadFlags.REMOVE_ALL);
+ cgData.removeList(listId);
super.tearDown();
}
}
diff --git a/tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java b/tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java
new file mode 100644
index 0000000..2578efa
--- /dev/null
+++ b/tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java
@@ -0,0 +1,84 @@
+package cgeo.geocaching.files;
+
+import com.jayway.android.robotium.solo.Solo;
+
+import android.annotation.TargetApi;
+import android.os.Build;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.suitebuilder.annotation.Suppress;
+import android.widget.CheckBox;
+
+import java.util.ArrayList;
+
+@TargetApi(Build.VERSION_CODES.FROYO)
+@Suppress() /* This test breaks the continuous integration server, do not run it for now. */
+public class SimpleDirChooserUITest extends ActivityInstrumentationTestCase2<SimpleDirChooser> {
+
+ private Solo solo;
+
+ public SimpleDirChooserUITest() {
+ super(SimpleDirChooser.class);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ solo = new Solo(getInstrumentation(), getActivity());
+ }
+
+ public void testSingleSelection() throws InterruptedException {
+ // normally our activity should be ready, but we already had Jenkins report no checkboxes right here at the beginning
+ solo.waitForActivity(solo.getCurrentActivity().getClass().getSimpleName(), 2000);
+
+ assertChecked("Newly opened activity", 0);
+ solo.scrollToBottom();
+ pause();
+ // according to the documentation, automatic pauses only happen in the clickXYZ() methods.
+ // Therefore lets introduce a manual pause after the scrolling methods.
+
+ final int lastIndex = solo.getCurrentCheckBoxes().size() - 1;
+
+ solo.clickOnCheckBox(lastIndex);
+ assertTrue(solo.getCurrentCheckBoxes().get(lastIndex).isChecked());
+ assertFalse(solo.getCurrentCheckBoxes().get(0).isChecked());
+ assertChecked("Clicked last checkbox", 1);
+
+ solo.scrollUp();
+ pause();
+ solo.scrollToBottom();
+ pause();
+ assertChecked("Refreshing last checkbox", 1);
+
+ solo.scrollToTop();
+ pause();
+ solo.clickOnCheckBox(0);
+ assertChecked("Clicked first checkbox", 1);
+ assertTrue(solo.getCurrentCheckBoxes().get(0).isChecked());
+ solo.clickOnCheckBox(1);
+ assertChecked("Clicked second checkbox", 1);
+ assertTrue(solo.getCurrentCheckBoxes().get(1).isChecked());
+ }
+
+ private static void pause() throws InterruptedException {
+ Thread.sleep(500);
+ }
+
+ private void assertChecked(String message, int expectedChecked) {
+ int checked = 0;
+ final ArrayList<CheckBox> boxes = solo.getCurrentCheckBoxes();
+ assertNotNull("Could not get checkboxes", boxes);
+ assertTrue("There are no checkboxes", boxes.size() > 1);
+ for (CheckBox checkBox : boxes) {
+ if (checkBox.isChecked()) {
+ checked++;
+ }
+ }
+ assertEquals(message, expectedChecked, checked);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ solo.finishOpenedActivities();
+ super.tearDown();
+ }
+}