diff options
Diffstat (limited to 'tests/src')
| -rw-r--r-- | tests/src/cgeo/geocaching/GCConstantsTest.java | 3 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/cgBaseTest.java | 25 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/cgDataTest.java | 93 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/cgeoApplicationTest.java | 45 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/files/GPXImporterTest.java | 15 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java | 2 |
6 files changed, 137 insertions, 46 deletions
diff --git a/tests/src/cgeo/geocaching/GCConstantsTest.java b/tests/src/cgeo/geocaching/GCConstantsTest.java index be7b5a8..696273d 100644 --- a/tests/src/cgeo/geocaching/GCConstantsTest.java +++ b/tests/src/cgeo/geocaching/GCConstantsTest.java @@ -20,9 +20,10 @@ public class GCConstantsTest extends AndroidTestCase { public static void testCacheCount() { assertCacheCount(149, "<strong><img src=\"/images/icons/icon_smile.png\" title=\"Caches Found\" /> 149</strong>"); assertCacheCount(491, MockedCache.readCachePage("GC2CJPF")); + assertCacheCount(1510, "<strong><img src=\"/images/icons/icon_smile.png\" title=\"Caches Found\" /> 1,510 · <img src=\"/images/challenges/types/sm/challenge.png\" title=\"Challenges Completed\" /> 2</strong>"); } private static void assertCacheCount(final int count, final String html) { - assertEquals(count, Integer.valueOf(BaseUtils.getMatch(html, GCConstants.PATTERN_CACHES_FOUND, true, "0")).intValue()); + assertEquals(count, Integer.parseInt(BaseUtils.getMatch(html, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll(",", ""))); } } diff --git a/tests/src/cgeo/geocaching/cgBaseTest.java b/tests/src/cgeo/geocaching/cgBaseTest.java index 1bd2e8a..78c7eef 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; @@ -11,7 +12,6 @@ import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.MediumTest; import java.util.ArrayList; -import java.util.Date; import junit.framework.Assert; @@ -58,11 +58,10 @@ public class cgBaseTest extends AndroidTestCase { Assert.assertEquals(expected.getPersonalNote(), actual.getPersonalNote()); Assert.assertEquals(expected.isFound(), actual.isFound()); Assert.assertEquals(expected.isFavorite(), actual.isFavorite()); + System.out.println(expected.getFavoritePoints() + " " + actual.getFavoritePoints()); Assert.assertTrue(expected.getFavoritePoints() <= actual.getFavoritePoints()); Assert.assertEquals(expected.isWatchlist(), actual.isWatchlist()); - Date date1 = expected.getHiddenDate(); - Date date2 = actual.getHiddenDate(); - Assert.assertEquals(date1.toString(), date2.toString()); + Assert.assertEquals(expected.getHiddenDate().toString(), actual.getHiddenDate().toString()); for (String attribute : expected.getAttributes()) { Assert.assertTrue(actual.getAttributes().contains(attribute)); } @@ -70,9 +69,7 @@ public class cgBaseTest extends AndroidTestCase { Assert.assertTrue(actual.getLogCounts().get(logType) >= expected.getLogCounts().get(logType)); } - int actualInventorySize = null != actual.getInventory() ? actual.getInventory().size() : 0; - int expectedInventorySize = null != expected.getInventory() ? expected.getInventory().size() : 0; - Assert.assertEquals(expectedInventorySize, actualInventorySize); + // the inventory can differ to often, therefore we don't compare them int actualSpoilersSize = null != actual.getSpoilers() ? actual.getSpoilers().size() : 0; int expectedSpoilersSize = null != expected.getSpoilers() ? expected.getSpoilers().size() : 0; @@ -89,8 +86,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); @@ -107,7 +104,7 @@ public class cgBaseTest extends AndroidTestCase { } public static void testWaypointsFromNote() { - final cgCache cache = createCache(); + final cgCache cache = cgBaseTest.createCache(0); assertNotNull(cache); final Geopoint[] empty = new Geopoint[] {}; @@ -154,11 +151,11 @@ public class cgBaseTest extends AndroidTestCase { } } - private static cgCache createCache() { - final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES.get(0); + public static cgCache createCache(int index) { + 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 new file mode 100644 index 0000000..456baf5 --- /dev/null +++ b/tests/src/cgeo/geocaching/cgDataTest.java @@ -0,0 +1,93 @@ +package cgeo.geocaching; + +import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.enumerations.LoadFlags; + +import android.test.ApplicationTestCase; + +import java.util.HashSet; +import java.util.Set; + +public class cgDataTest extends ApplicationTestCase<cgeoapplication> { + + public cgDataTest() { + super(cgeoapplication.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + // init environment + createApplication(); + } + + public static void testStoredLists() { + + cgeoapplication app = cgeoapplication.getInstance(); + int listId1 = StoredList.STANDARD_LIST_ID; + int listId2 = StoredList.STANDARD_LIST_ID; + + // create caches + final cgCache cache1 = cgBaseTest.createCache(0); + assertNotNull(cache1); + final cgCache cache2 = cgBaseTest.createCache(1); + assertNotNull(cache2); + + 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); + + cache1.setDetailed(true); + cache1.setListId(listId1); + cache2.setDetailed(true); + cache2.setListId(listId1); + + // 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)")); + + // 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)); + + // remove list (cache1=listId2, cache2=listId2) + assertTrue(app.removeList(listId1)); + + // mark dropped (cache1=1, cache2=0) + app.markDropped(cache2.getGeocode()); + + // mark stored (cache1=1, cache2=listId2) + app.markStored(cache2.getGeocode(), listId2); + assertEquals(2, app.getAllStoredCachesCount(false, CacheType.ALL, listId2)); + + // drop stored (cache1=0, cache2=0) + app.dropList(listId2); + + } finally { + + // remove caches + Set<String> geocodes = new HashSet<String>(); + geocodes.add(cache1.getGeocode()); + geocodes.add(cache2.getGeocode()); + app.removeCaches(geocodes, LoadFlags.REMOVEALL); + + // remove list + app.removeList(listId1); + app.removeList(listId2); + } + } +}
\ No newline at end of file diff --git a/tests/src/cgeo/geocaching/cgeoApplicationTest.java b/tests/src/cgeo/geocaching/cgeoApplicationTest.java index 1bb7b85..c48a6ae 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,9 +160,9 @@ 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(18 <= 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..15c40eb 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 42; } @Override |
