diff options
author | rsudev <rasch@munin-soft.de> | 2013-08-29 09:40:04 +0200 |
---|---|---|
committer | rsudev <rasch@munin-soft.de> | 2013-08-29 09:40:04 +0200 |
commit | e6e45ecf25d28cc1e6afe85125023eb51368169a (patch) | |
tree | fa1ad22bdc92b2c56b16b450abf9af21296cb1d1 /tests/src/cgeo | |
parent | 34b097ce9d166f40f9633d6227de058c447b85c9 (diff) | |
download | cgeo-e6e45ecf25d28cc1e6afe85125023eb51368169a.zip cgeo-e6e45ecf25d28cc1e6afe85125023eb51368169a.tar.gz cgeo-e6e45ecf25d28cc1e6afe85125023eb51368169a.tar.bz2 |
Switch off and restore static map flags for waypoint test
Diffstat (limited to 'tests/src/cgeo')
-rw-r--r-- | tests/src/cgeo/CGeoTestCase.java | 48 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/GeocacheTest.java | 47 |
2 files changed, 75 insertions, 20 deletions
diff --git a/tests/src/cgeo/CGeoTestCase.java b/tests/src/cgeo/CGeoTestCase.java index 88184e0..b741e95 100644 --- a/tests/src/cgeo/CGeoTestCase.java +++ b/tests/src/cgeo/CGeoTestCase.java @@ -4,6 +4,8 @@ import cgeo.geocaching.cgData; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; +import cgeo.geocaching.settings.Settings; +import cgeo.geocaching.settings.TestSettings; import android.test.ApplicationTestCase; @@ -11,6 +13,10 @@ import java.util.EnumSet; public abstract class CGeoTestCase extends ApplicationTestCase<cgeoapplication> { + private boolean oldStoreMapsFlag; + private boolean oldStoreWpMapsFlag; + private boolean oldMapStoreFlagsRecorded = false; + public CGeoTestCase() { super(cgeoapplication.class); } @@ -28,7 +34,7 @@ public abstract class CGeoTestCase extends ApplicationTestCase<cgeoapplication> /** * remove cache from database and file system - * + * * @param geocode */ protected static void removeCacheCompletely(final String geocode) { @@ -37,4 +43,44 @@ public abstract class CGeoTestCase extends ApplicationTestCase<cgeoapplication> cgData.removeCache(geocode, flags); } + /** + * must be called once before setting the flags + * can be called again after restoring the flags + */ + protected void recordMapStoreFlags() { + if (oldMapStoreFlagsRecorded) { + throw new IllegalStateException("MapStoreFlags already recorded!"); + } + oldStoreMapsFlag = Settings.isStoreOfflineMaps(); + oldStoreWpMapsFlag = Settings.isStoreOfflineWpMaps(); + oldMapStoreFlagsRecorded = true; + } + + /** + * can be called after recordMapStoreFlags, + * to set the flags for map storing as necessary + * @param storeCacheMap + * @param storeWpMaps + */ + protected void setMapStoreFlags(boolean storeCacheMap, boolean storeWpMaps) { + if (!oldMapStoreFlagsRecorded) { + throw new IllegalStateException("Previous MapStoreFlags havn't been recorded! Setting not allowed"); + } + + TestSettings.setStoreOfflineMaps(storeCacheMap); + TestSettings.setStoreOfflineWpMaps(storeWpMaps); + } + + /** + * has to be called after completion of the test (preferably in the finally part of a try statement) + */ + protected void restoreMapStoreFlags() { + if (!oldMapStoreFlagsRecorded) { + throw new IllegalStateException("Previous MapStoreFlags havn't been recorded. Restore not possible"); + } + + TestSettings.setStoreOfflineMaps(oldStoreMapsFlag); + TestSettings.setStoreOfflineWpMaps(oldStoreWpMapsFlag); + oldMapStoreFlagsRecorded = false; + } } diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java index 9606287..5850c4f 100644 --- a/tests/src/cgeo/geocaching/GeocacheTest.java +++ b/tests/src/cgeo/geocaching/GeocacheTest.java @@ -50,32 +50,41 @@ public class GeocacheTest extends CGeoTestCase { assertEquals("GC1234", cache.getGeocode()); } - public static void testUpdateWaypointFromNote() { + public void testUpdateWaypointFromNote() { assertWaypointsParsed("Test N51 13.888 E007 03.444", 1); } - public static void testUpdateWaypointsFromNote() { + public void testUpdateWaypointsFromNote() { assertWaypointsParsed("Test N51 13.888 E007 03.444 Test N51 13.233 E007 03.444 Test N51 09.123 E007 03.444", 3); } - private static void assertWaypointsParsed(String note, int expectedWaypoints) { - Geocache cache = new Geocache(); - final String geocode = "Test" + System.nanoTime(); - cache.setGeocode(geocode); - cache.setWaypoints(new ArrayList<Waypoint>(), false); - for (int i = 0; i < 2; i++) { - cache.setPersonalNote(note); - cache.parseWaypointsFromNote(); - final List<Waypoint> waypoints = cache.getWaypoints(); - assertNotNull(waypoints); - assertEquals(expectedWaypoints, waypoints.size()); - final Waypoint waypoint = waypoints.get(0); - assertEquals(new Geopoint("N51 13.888 E007 03.444"), waypoint.getCoords()); - // assertEquals("Test", waypoint.getNote()); - assertEquals(cgeoapplication.getInstance().getString(R.string.cache_personal_note) + " 1", waypoint.getName()); - cache.store(StoredList.TEMPORARY_LIST_ID, null); + private void assertWaypointsParsed(String note, int expectedWaypoints) { + + recordMapStoreFlags(); + + try { + setMapStoreFlags(false, false); + + Geocache cache = new Geocache(); + final String geocode = "Test" + System.nanoTime(); + cache.setGeocode(geocode); + cache.setWaypoints(new ArrayList<Waypoint>(), false); + for (int i = 0; i < 2; i++) { + cache.setPersonalNote(note); + cache.parseWaypointsFromNote(); + final List<Waypoint> waypoints = cache.getWaypoints(); + assertNotNull(waypoints); + assertEquals(expectedWaypoints, waypoints.size()); + final Waypoint waypoint = waypoints.get(0); + assertEquals(new Geopoint("N51 13.888 E007 03.444"), waypoint.getCoords()); + // assertEquals("Test", waypoint.getNote()); + assertEquals(cgeoapplication.getInstance().getString(R.string.cache_personal_note) + " 1", waypoint.getName()); + cache.store(StoredList.TEMPORARY_LIST_ID, null); + } + removeCacheCompletely(geocode); + } finally { + restoreMapStoreFlags(); } - removeCacheCompletely(geocode); } public static void testMergeDownloadedStored() { |