diff options
| author | blafoo <github@blafoo.de> | 2012-02-08 00:44:27 +0100 |
|---|---|---|
| committer | blafoo <github@blafoo.de> | 2012-02-08 00:44:27 +0100 |
| commit | 0679e76ce7da5640cbeedbeff008624052b83991 (patch) | |
| tree | 3a8385e8f0b31b85691b1400e0a3e272f5e1bf01 /tests | |
| parent | db271dd2cd94a809d4422f58818a02403c08bbd6 (diff) | |
| download | cgeo-0679e76ce7da5640cbeedbeff008624052b83991.zip cgeo-0679e76ce7da5640cbeedbeff008624052b83991.tar.gz cgeo-0679e76ce7da5640cbeedbeff008624052b83991.tar.bz2 | |
Changed database handling
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/src/cgeo/geocaching/cgBaseTest.java | 12 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/cgDataTest.java | 74 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/cgeoApplicationTest.java | 43 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/files/GPXImporterTest.java | 15 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java | 2 |
5 files changed, 74 insertions, 72 deletions
diff --git a/tests/src/cgeo/geocaching/cgBaseTest.java b/tests/src/cgeo/geocaching/cgBaseTest.java index 311cb7a..06654ff 100644 --- a/tests/src/cgeo/geocaching/cgBaseTest.java +++ b/tests/src/cgeo/geocaching/cgBaseTest.java @@ -1,5 +1,6 @@ package cgeo.geocaching; +import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.test.RegExPerformanceTest; @@ -33,6 +34,7 @@ public class cgBaseTest extends AndroidTestCase { Assert.assertEquals(125.663703918457, cgBase.getElevation(new Geopoint(48.0, 2.0)), 0.1); } + @SuppressWarnings("unused") public static void testCompareCaches(ICache expected, cgCache actual) { Assert.assertEquals(expected.getGeocode(), actual.getGeocode()); Assert.assertTrue(expected.getType() == actual.getType()); @@ -72,7 +74,7 @@ public class cgBaseTest extends AndroidTestCase { int actualInventorySize = null != actual.getInventory() ? actual.getInventory().size() : 0; int expectedInventorySize = null != expected.getInventory() ? expected.getInventory().size() : 0; - // don't check inventory, it's to volatile + // the inventory can differ to often. // Assert.assertEquals(expectedInventorySize, actualInventorySize); int actualSpoilersSize = null != actual.getSpoilers() ? actual.getSpoilers().size() : 0; @@ -90,8 +92,8 @@ public class cgBaseTest extends AndroidTestCase { for (MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) { // to get the same results we have to use the date format used when the mocked data was created Settings.setGcCustomDate(mockedCache.getDateFormat()); - ParseResult parseResult = cgBase.parseCacheFromText(mockedCache.getData(), 0, null); - cgCache parsedCache = cgBase.getFirstElementFromSet(parseResult.cacheList); + SearchResult searchResult = cgBase.parseCacheFromText(mockedCache.getData(), 0, null); + cgCache parsedCache = searchResult.getFirstCacheFromResult(LoadFlags.LOADCACHEORDB); cgBaseTest.testCompareCaches(mockedCache, parsedCache); } Settings.setGcCustomDate(gcCustomDate); @@ -159,7 +161,7 @@ public class cgBaseTest extends AndroidTestCase { final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES.get(index); // to get the same results we have to use the date format used when the mocked data was created Settings.setGcCustomDate(mockedCache.getDateFormat()); - final ParseResult parseResult = cgBase.parseCacheFromText(mockedCache.getData(), 0, null); - return cgBase.getFirstElementFromSet(parseResult.cacheList); + final SearchResult searchResult = cgBase.parseCacheFromText(mockedCache.getData(), 0, null); + return searchResult.getFirstCacheFromResult(LoadFlags.LOADCACHEORDB); } }
\ No newline at end of file diff --git a/tests/src/cgeo/geocaching/cgDataTest.java b/tests/src/cgeo/geocaching/cgDataTest.java index b818f05..8892ade 100644 --- a/tests/src/cgeo/geocaching/cgDataTest.java +++ b/tests/src/cgeo/geocaching/cgDataTest.java @@ -1,11 +1,12 @@ package cgeo.geocaching; import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.enumerations.LoadFlags; import android.test.ApplicationTestCase; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; public class cgDataTest extends ApplicationTestCase<cgeoapplication> { @@ -35,56 +36,55 @@ public class cgDataTest extends ApplicationTestCase<cgeoapplication> { try { - // create lists - listId1 = app.createList("cgData Test"); - assertTrue(listId1 > StoredList.STANDARD_LIST_ID); - listId2 = app.createList("cgDataTest"); - assertTrue(listId2 > StoredList.STANDARD_LIST_ID); - assertTrue(app.getLists().size() >= 2); + // create lists + listId1 = app.createList("cgData Test"); + assertTrue(listId1 > StoredList.STANDARD_LIST_ID); + listId2 = app.createList("cgDataTest"); + assertTrue(listId2 > StoredList.STANDARD_LIST_ID); + assertTrue(app.getLists().size() >= 2); - cache1.setDetailed(true); - cache1.setListId(listId1); - cache2.setDetailed(true); - cache2.setListId(listId1); + cache1.setDetailed(true); + cache1.setListId(listId1); + cache2.setDetailed(true); + cache2.setListId(listId1); - // save caches to DB (cache1=listId1, cache2=listId1) - SearchResult searchResult = new SearchResult(); - app.addCacheToSearch(searchResult, cache1); - app.addCacheToSearch(searchResult, cache2); - assertTrue(app.getAllStoredCachesCount(false, CacheType.ALL, null) >= 2); + // save caches to DB (cache1=listId1, cache2=listId1) + app.saveCache(cache1, LoadFlags.SAVEALL); + app.saveCache(cache2, LoadFlags.SAVEALL); + assertTrue(app.getAllStoredCachesCount(false, CacheType.ALL, null) >= 2); - // rename list (cache1=listId1, cache2=listId1) - assertEquals(1, app.renameList(listId1, "cgData Test (renamed)")); + // rename list (cache1=listId1, cache2=listId1) + assertEquals(1, app.renameList(listId1, "cgData Test (renamed)")); - // get list - StoredList list1 = app.getList(listId1); - assertEquals("cgData Test (renamed)", list1.title); + // get list + StoredList list1 = app.getList(listId1); + assertEquals("cgData Test (renamed)", list1.title); - // move to list (cache1=listId2, cache2=listId2) - app.moveToList(cache1.getGeocode(), listId2); - assertEquals(1, app.getAllStoredCachesCount(false, CacheType.ALL, listId2)); + // move to list (cache1=listId2, cache2=listId2) + app.moveToList(cache1.getGeocode(), listId2); + assertEquals(1, app.getAllStoredCachesCount(false, CacheType.ALL, listId2)); - // remove list (cache1=1, cache2=listId2) - assertTrue(app.removeList(listId1)); + // remove list (cache1=1, cache2=listId2) + assertTrue(app.removeList(listId1)); - // mark dropped (cache1=1, cache2=0) - assertTrue(app.markDropped(cache2.getGeocode())); + // mark dropped (cache1=1, cache2=0) + app.markDropped(cache2.getGeocode()); - // mark stored (cache1=1, cache2=listId2) - app.markStored(cache2.getGeocode(), listId2); - StoredList list2 = app.getList(listId2); - // assertEquals(1, list2.count); + // mark stored (cache1=1, cache2=listId2) + app.markStored(cache2.getGeocode(), listId2); + StoredList list2 = app.getList(listId2); + //assertEquals(1, list2.count); - // drop stored (cache1=0, cache2=0) - app.dropStored(listId2); + // drop stored (cache1=0, cache2=0) + app.dropList(listId2); } finally { // remove caches - List<String> geocodes = new ArrayList<String>(); + Set<String> geocodes = new HashSet<String>(); geocodes.add(cache1.getGeocode()); geocodes.add(cache2.getGeocode()); - app.dropCaches(geocodes); + app.removeCaches(geocodes, LoadFlags.REMOVEALL); // remove list app.removeList(listId1); diff --git a/tests/src/cgeo/geocaching/cgeoApplicationTest.java b/tests/src/cgeo/geocaching/cgeoApplicationTest.java index 1bb7b85..cc9e66f 100644 --- a/tests/src/cgeo/geocaching/cgeoApplicationTest.java +++ b/tests/src/cgeo/geocaching/cgeoApplicationTest.java @@ -1,6 +1,7 @@ package cgeo.geocaching; import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Viewport; @@ -19,7 +20,6 @@ import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.SmallTest; import android.util.Log; -import java.util.Arrays; import java.util.Date; import junit.framework.Assert; @@ -41,6 +41,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { // init environment createApplication(); + cgBase.initialize(getApplication()); } /** @@ -96,12 +97,12 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static cgCache testSearchByGeocode(final String geocode) { - final ParseResult search = cgBase.searchByGeocode(geocode, null, 0, true, null); + final SearchResult search = cgBase.searchByGeocode(geocode, null, 0, true, null); assertNotNull(search); if (Settings.isPremiumMember() || search.error == null) { assertEquals(1, search.getGeocodes().size()); assertTrue(search.getGeocodes().contains(geocode)); - return cgeoapplication.getInstance().getCacheByGeocode(geocode); + return cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOADCACHEORDB); } assertEquals(0, search.getGeocodes().size()); return null; @@ -112,7 +113,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static void testSearchByGeocodeNotExisting() { - final ParseResult search = cgBase.searchByGeocode("GC123456", null, 0, true, null); + final SearchResult search = cgBase.searchByGeocode("GC123456", null, 0, true, null); assertNotNull(search); assertEquals(search.error, StatusCode.UNPUBLISHED_CACHE); } @@ -130,11 +131,11 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { deleteCacheFromDBAndLogout(cache.getGeocode()); - ParseResult search = cgBase.searchByGeocode(cache.getGeocode(), null, 0, true, null); + SearchResult search = cgBase.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); assertNotNull(search); assertEquals(1, search.getGeocodes().size()); assertTrue(search.getGeocodes().contains(cache.getGeocode())); - cgCache searchedCache = cgBase.getFirstElementFromSet(search.cacheList); + cgCache searchedCache = search.getFirstCacheFromResult(LoadFlags.LOADCACHEORDB); // coords must be null if the user is not logged in assertNull(searchedCache.getCoords()); @@ -143,7 +144,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { deleteCacheFromDBAndLogout(cache.getGeocode()); - search = cgBase.searchByGeocode(cache.getGeocode(), null, 0, true, null); + search = cgBase.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); assertNotNull(search); assertEquals(0, search.getGeocodes().size()); @@ -159,7 +160,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static void testSearchByCoords() { - final ParseResult search = cgBase.searchByCoords(null, new Geopoint("N 52° 24.972 E 009° 35.647"), CacheType.MYSTERY, 0, false); + final SearchResult search = cgBase.searchByCoords(null, new Geopoint("N 52° 24.972 E 009° 35.647"), CacheType.MYSTERY, 0, false); assertNotNull(search); assertEquals(20, search.getGeocodes().size()); assertTrue(search.getGeocodes().contains("GC1RMM2")); @@ -170,7 +171,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static void testSearchByOwner() { - final ParseResult search = cgBase.searchByOwner(null, "blafoo", CacheType.MYSTERY, 0, false); + final SearchResult search = cgBase.searchByOwner(null, "blafoo", CacheType.MYSTERY, 0, false); assertNotNull(search); assertEquals(3, search.getGeocodes().size()); assertTrue(search.getGeocodes().contains("GC36RT6")); @@ -181,7 +182,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static void testSearchByUsername() { - final ParseResult search = cgBase.searchByUsername(null, "blafoo", CacheType.WEBCAM, 0, false); + final SearchResult search = cgBase.searchByUsername(null, "blafoo", CacheType.WEBCAM, 0, false); assertNotNull(search); assertEquals(3, search.totalCnt); assertTrue(search.getGeocodes().contains("GCP0A9")); @@ -196,7 +197,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { final String token = cgBase.getMapUserToken(new Handler()); final Viewport viewport = new Viewport(cache.getCoords(), 0.003, 0.003); - final ParseResult search = cgBase.searchByViewport(token, viewport); + final SearchResult search = cgBase.searchByViewport(token, viewport); // GC2JVEH is a premium members only cache. It can't be "found" by non-premium members if (Settings.isPremiumMember()) { @@ -204,14 +205,13 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { // coords are identical... if the user is logged in if (search.error != null) { if (search.getGeocodes().contains(cache.getGeocode())) { - assertFalse(cache.getCoords().isEqualTo(cgeoapplication.getInstance().getCacheByGeocode(cache.getGeocode()).getCoords())); - assertFalse(cgeoapplication.getInstance().getCacheByGeocode(cache.getGeocode()).isReliableLatLon()); + assertFalse(cache.getCoords().isEqualTo(cgeoapplication.getInstance().loadCache(cache.getGeocode(), LoadFlags.LOADCACHEORDB).getCoords())); + assertFalse(cgeoapplication.getInstance().loadCache(cache.getGeocode(), LoadFlags.LOADCACHEORDB).isReliableLatLon()); } } else { - assertTrue(search.cacheList.size() >= 1); assertTrue(search.getGeocodes().contains(cache.getGeocode())); - assertEquals(cache.getCoords().toString(), cgeoapplication.getInstance().getCacheByGeocode(cache.getGeocode()).getCoords().toString()); - assertTrue(cgeoapplication.getInstance().getCacheByGeocode(cache.getGeocode()).isReliableLatLon()); + assertEquals(cache.getCoords().toString(), cgeoapplication.getInstance().loadCache(cache.getGeocode(), LoadFlags.LOADCACHEORDB).getCoords().toString()); + assertTrue(cgeoapplication.getInstance().loadCache(cache.getGeocode(), LoadFlags.LOADCACHEORDB).isReliableLatLon()); } } } @@ -232,15 +232,15 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { deleteCacheFromDBAndLogout(cache.getGeocode()); Viewport viewport = new Viewport(cache.getCoords(), 0.003, 0.003); - ParseResult search = cgBase.searchByViewport(token, viewport); + SearchResult search = cgBase.searchByViewport(token, viewport); assertNotNull(search); assertTrue(search.getGeocodes().contains(cache.getGeocode())); // coords differ Log.d(Settings.tag, "cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords expected = " + cache.getCoords()); - Log.d(Settings.tag, "cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords actual = " + cgeoapplication.getInstance().getCacheByGeocode(cache.getGeocode()).getCoords()); - assertFalse(cache.getCoords().isEqualTo(cgeoapplication.getInstance().getCacheByGeocode(cache.getGeocode()).getCoords(), 1e-3)); - assertFalse(cgeoapplication.getInstance().getCacheByGeocode(cache.getGeocode()).isReliableLatLon()); + Log.d(Settings.tag, "cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords actual = " + cgeoapplication.getInstance().loadCache(cache.getGeocode(), LoadFlags.LOADCACHEORDB).getCoords()); + assertFalse(cache.getCoords().isEqualTo(cgeoapplication.getInstance().loadCache(cache.getGeocode(), LoadFlags.LOADCACHEORDB).getCoords(), 1e-3)); + assertFalse(cgeoapplication.getInstance().loadCache(cache.getGeocode(), LoadFlags.LOADCACHEORDB).isReliableLatLon()); // premium cache cache = new GC2JVEH(); @@ -286,8 +286,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { /** Remove cache from DB and cache to ensure that the cache is not loaded from the database */ private static void deleteCacheFromDBAndLogout(String geocode) { - cgeoapplication.getInstance().dropCaches(Arrays.asList(geocode)); - cgeoapplication.removeCacheFromCache(geocode); + cgeoapplication.getInstance().removeCache(geocode, LoadFlags.REMOVEALL); cgBase.logout(); // Modify login data to avoid an automatic login again diff --git a/tests/src/cgeo/geocaching/files/GPXImporterTest.java b/tests/src/cgeo/geocaching/files/GPXImporterTest.java index 0fce2f8..dcc2bf6 100644 --- a/tests/src/cgeo/geocaching/files/GPXImporterTest.java +++ b/tests/src/cgeo/geocaching/files/GPXImporterTest.java @@ -4,6 +4,7 @@ import cgeo.geocaching.SearchResult; import cgeo.geocaching.Settings; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgeoapplication; +import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; import cgeo.geocaching.test.R; import cgeo.geocaching.utils.CancellableHandler; @@ -66,7 +67,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj; assertEquals(Collections.singletonList("GC31J2H"), new ArrayList<String>(search.getGeocodes())); - cgCache cache = cgeoapplication.getInstance().getCacheByGeocode("GC31J2H"); + cgCache cache = cgeoapplication.getInstance().loadCache("GC31J2H", LoadFlags.LOADCACHEORDB); assertCacheProperties(cache); // can't assert, for whatever reason the waypoints are remembered in DB @@ -95,7 +96,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj; assertEquals(Collections.singletonList("GC31J2H"), new ArrayList<String>(search.getGeocodes())); - cgCache cache = cgeoapplication.getInstance().getCacheByGeocode("GC31J2H"); + cgCache cache = cgeoapplication.getInstance().loadCache("GC31J2H", LoadFlags.LOADCACHEORDB); assertCacheProperties(cache); assertEquals(2, cache.getWaypoints().size()); } @@ -118,7 +119,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj; assertEquals(Collections.singletonList("OC5952"), new ArrayList<String>(search.getGeocodes())); - cgCache cache = cgeoapplication.getInstance().getCacheByGeocode("OC5952"); + cgCache cache = cgeoapplication.getInstance().loadCache("OC5952", LoadFlags.LOADCACHEORDB); assertCacheProperties(cache); } @@ -159,7 +160,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj; assertEquals(Collections.singletonList("GC31J2H"), new ArrayList<String>(search.getGeocodes())); - cgCache cache = cgeoapplication.getInstance().getCacheByGeocode("GC31J2H"); + cgCache cache = cgeoapplication.getInstance().loadCache("GC31J2H", LoadFlags.LOADCACHEORDB); assertCacheProperties(cache); // can't assert, for whatever reason the waypoints are remembered in DB @@ -177,7 +178,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj; assertEquals(Collections.singletonList("GC31J2H"), new ArrayList<String>(search.getGeocodes())); - cgCache cache = cgeoapplication.getInstance().getCacheByGeocode("GC31J2H"); + cgCache cache = cgeoapplication.getInstance().loadCache("GC31J2H", LoadFlags.LOADCACHEORDB); assertCacheProperties(cache); assertEquals(1, cache.getWaypoints().size()); // this is the original pocket query result without test waypoint } @@ -202,7 +203,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj; assertEquals(Collections.singletonList("GC31J2H"), new ArrayList<String>(search.getGeocodes())); - cgCache cache = cgeoapplication.getInstance().getCacheByGeocode("GC31J2H"); + cgCache cache = cgeoapplication.getInstance().loadCache("GC31J2H", LoadFlags.LOADCACHEORDB); assertCacheProperties(cache); assertEquals(1, cache.getWaypoints().size()); // this is the original pocket query result without test waypoint } @@ -250,7 +251,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { @Override protected void tearDown() throws Exception { - cgeoapplication.getInstance().dropStored(listId); + cgeoapplication.getInstance().dropList(listId); cgeoapplication.getInstance().removeList(listId); deleteDirectory(tempDir); super.tearDown(); diff --git a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java index 3ec07b8..cf348c4 100644 --- a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java +++ b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java @@ -135,7 +135,7 @@ public class GC1ZXX2 extends MockedCache { @Override public int getFavoritePoints() { - return 45; + return 43; } @Override |
