aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/cgeo/geocaching')
-rw-r--r--tests/src/cgeo/geocaching/CacheTest.java16
-rw-r--r--tests/src/cgeo/geocaching/DestinationTest.java (renamed from tests/src/cgeo/geocaching/cgDestinationTest.java)6
-rw-r--r--tests/src/cgeo/geocaching/HtmlPerformanceTest.java5
-rw-r--r--tests/src/cgeo/geocaching/SearchResultTest.java17
-rw-r--r--tests/src/cgeo/geocaching/SettingsTest.java9
-rw-r--r--tests/src/cgeo/geocaching/TrackablesTest.java27
-rw-r--r--tests/src/cgeo/geocaching/cgDataTest.java47
-rw-r--r--tests/src/cgeo/geocaching/cgeoApplicationTest.java83
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java25
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java4
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java8
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java7
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCParserTest.java (renamed from tests/src/cgeo/geocaching/cgBaseTest.java)127
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java5
-rw-r--r--tests/src/cgeo/geocaching/connector/opencaching/OkapiClientTest.java15
-rw-r--r--tests/src/cgeo/geocaching/enumerations/CacheAttributeTest.java23
-rw-r--r--tests/src/cgeo/geocaching/files/GPXImporterTest.java8
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java15
-rw-r--r--tests/src/cgeo/geocaching/files/LocParserTest.java7
-rw-r--r--tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java24
-rw-r--r--tests/src/cgeo/geocaching/filter/SizeFilterTest.java49
-rw-r--r--tests/src/cgeo/geocaching/filter/StateArchivedFilterTest.java27
-rw-r--r--tests/src/cgeo/geocaching/filter/StateDisabledFilterTest.java26
-rw-r--r--tests/src/cgeo/geocaching/filter/StateFoundFilterTest.java26
-rw-r--r--tests/src/cgeo/geocaching/filter/StatePremiumFilterTest.java26
-rw-r--r--tests/src/cgeo/geocaching/filter/TerrainFilterTest.java24
-rw-r--r--tests/src/cgeo/geocaching/filter/TypeFilterTest.java52
-rw-r--r--tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java10
-rw-r--r--tests/src/cgeo/geocaching/geopoint/GeopointTest.java33
-rw-r--r--tests/src/cgeo/geocaching/geopoint/HumanDistanceTest.java40
-rw-r--r--tests/src/cgeo/geocaching/geopoint/ViewportTest.java100
-rw-r--r--tests/src/cgeo/geocaching/network/ParametersTest.java53
-rw-r--r--tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java15
-rw-r--r--tests/src/cgeo/geocaching/test/RegExPerformanceTest.java9
-rw-r--r--tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java6
-rw-r--r--tests/src/cgeo/geocaching/test/WhitespaceTest.java34
-rw-r--r--tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java4
-rw-r--r--tests/src/cgeo/geocaching/test/mock/GC2CJPF.java4
-rw-r--r--tests/src/cgeo/geocaching/test/mock/GC2JVEH.java4
-rw-r--r--tests/src/cgeo/geocaching/test/mock/MockedCache.java13
-rw-r--r--tests/src/cgeo/geocaching/utils/AbstractLRUTest.java20
-rw-r--r--tests/src/cgeo/geocaching/utils/BaseUtilsTest.java26
-rw-r--r--tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java85
-rw-r--r--tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java66
-rw-r--r--tests/src/cgeo/geocaching/utils/MemorySubjectTest.java78
45 files changed, 1008 insertions, 300 deletions
diff --git a/tests/src/cgeo/geocaching/CacheTest.java b/tests/src/cgeo/geocaching/CacheTest.java
index a76764d..e1d6efb 100644
--- a/tests/src/cgeo/geocaching/CacheTest.java
+++ b/tests/src/cgeo/geocaching/CacheTest.java
@@ -25,4 +25,20 @@ public class CacheTest extends AndroidTestCase {
assertFalse(cacheYesterday.canBeAddedToCalendar());
}
+ public static void testEquality() {
+ final cgCache one = new cgCache();
+ final cgCache two = new cgCache();
+
+ // identity
+ assertTrue(one.equals(one));
+
+ // different objects without geocode shall not be equal
+ assertFalse(one.equals(two));
+
+ one.setGeocode("geocode");
+ two.setGeocode("geocode");
+
+ // different objects with same geocode shall be equal
+ assertTrue(one.equals(two));
+ }
}
diff --git a/tests/src/cgeo/geocaching/cgDestinationTest.java b/tests/src/cgeo/geocaching/DestinationTest.java
index cb5fe45..26caacd 100644
--- a/tests/src/cgeo/geocaching/cgDestinationTest.java
+++ b/tests/src/cgeo/geocaching/DestinationTest.java
@@ -6,14 +6,14 @@ import android.test.AndroidTestCase;
import junit.framework.Assert;
-public class cgDestinationTest extends AndroidTestCase {
+public class DestinationTest extends AndroidTestCase {
- private cgDestination dest = null;
+ private Destination dest = null;
@Override
protected void setUp() throws Exception {
super.setUp();
- dest = new cgDestination(1, 10000, new Geopoint(52.5, 9.33));
+ dest = new Destination(1, 10000, new Geopoint(52.5, 9.33));
}
public void testSomething() {
diff --git a/tests/src/cgeo/geocaching/HtmlPerformanceTest.java b/tests/src/cgeo/geocaching/HtmlPerformanceTest.java
index 735dc74..b08b06e 100644
--- a/tests/src/cgeo/geocaching/HtmlPerformanceTest.java
+++ b/tests/src/cgeo/geocaching/HtmlPerformanceTest.java
@@ -1,11 +1,12 @@
package cgeo.geocaching;
+import cgeo.geocaching.utils.Log;
+
import org.apache.commons.lang3.StringEscapeUtils;
import android.os.SystemClock;
import android.test.AndroidTestCase;
import android.text.Html;
-import android.util.Log;
public class HtmlPerformanceTest extends AndroidTestCase {
private String input;
@@ -55,7 +56,7 @@ public class HtmlPerformanceTest extends AndroidTestCase {
final long start = SystemClock.elapsedRealtime();
runnable.run();
final long end = SystemClock.elapsedRealtime();
- Log.d(Settings.tag, label + ": " + (end - start) + " ms");
+ Log.d(label + ": " + (end - start) + " ms");
return end - start;
}
}
diff --git a/tests/src/cgeo/geocaching/SearchResultTest.java b/tests/src/cgeo/geocaching/SearchResultTest.java
new file mode 100644
index 0000000..8fcd188
--- /dev/null
+++ b/tests/src/cgeo/geocaching/SearchResultTest.java
@@ -0,0 +1,17 @@
+package cgeo.geocaching;
+
+import android.test.AndroidTestCase;
+
+import java.util.HashSet;
+
+public class SearchResultTest extends AndroidTestCase {
+ public static void testCreateFromGeocodes() {
+ final HashSet<String> geocodes = new HashSet<String>();
+ geocodes.add("GC12345");
+ geocodes.add("GC23456");
+ final SearchResult searchResult = new SearchResult(geocodes);
+ assertEquals(2, searchResult.getCount());
+ assertEquals(2, searchResult.getTotal());
+ assertTrue(searchResult.getGeocodes().contains("GC12345"));
+ }
+}
diff --git a/tests/src/cgeo/geocaching/SettingsTest.java b/tests/src/cgeo/geocaching/SettingsTest.java
index c31e635..27395ec 100644
--- a/tests/src/cgeo/geocaching/SettingsTest.java
+++ b/tests/src/cgeo/geocaching/SettingsTest.java
@@ -1,7 +1,6 @@
package cgeo.geocaching;
-import cgeo.geocaching.Settings;
-import cgeo.geocaching.cgeo;
+import org.mapsforge.android.maps.MapDatabase;
import android.test.ActivityInstrumentationTestCase2;
@@ -21,7 +20,9 @@ public class SettingsTest extends ActivityInstrumentationTestCase2<cgeo> {
* this should work fine without an exception (once there was an exception because of the empty map file string)
*/
public static void testSettingsException() {
- // asserts A OR NOT A, because we don't know what the settings are on any device or emulator
- assertTrue(Settings.isValidMapFile() || !Settings.isValidMapFile());
+ final String mapFile = Settings.getMapFile();
+ assertNotNull(mapFile);
+ // We just want to ensure that it does not throw any exception but we do not know anything about the result
+ MapDatabase.isValidMapFile(mapFile);
}
}
diff --git a/tests/src/cgeo/geocaching/TrackablesTest.java b/tests/src/cgeo/geocaching/TrackablesTest.java
index 1d3d165..3cb34a6 100644
--- a/tests/src/cgeo/geocaching/TrackablesTest.java
+++ b/tests/src/cgeo/geocaching/TrackablesTest.java
@@ -1,5 +1,6 @@
package cgeo.geocaching;
+import cgeo.geocaching.connector.gc.GCParser;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
import cgeo.geocaching.utils.BaseUtils;
@@ -9,16 +10,16 @@ import java.util.List;
public class TrackablesTest extends AbstractResourceInstrumentationTestCase {
public void testLogPageWithTrackables() {
- List<cgTrackableLog> tbLogs = cgBase.parseTrackableLog(getFileContent(R.raw.log_with_2tb));
+ List<TrackableLog> tbLogs = GCParser.parseTrackableLog(getFileContent(R.raw.log_with_2tb));
assertNotNull(tbLogs);
assertEquals(2, tbLogs.size());
- cgTrackableLog log = tbLogs.get(0);
+ TrackableLog log = tbLogs.get(0);
assertEquals("Steffen's Kaiserwagen", log.name);
assertEquals("1QG1EE", log.trackCode);
}
public void testLogPageWithoutTrackables() {
- List<cgTrackableLog> tbLogs = cgBase.parseTrackableLog(getFileContent(R.raw.log_without_tb));
+ List<TrackableLog> tbLogs = GCParser.parseTrackableLog(getFileContent(R.raw.log_without_tb));
assertNotNull(tbLogs);
assertEquals(0, tbLogs.size());
}
@@ -40,20 +41,20 @@ public class TrackablesTest extends AbstractResourceInstrumentationTestCase {
final cgTrackable trackable = getTBXATG();
assertEquals("TBXATG", trackable.getGeocode());
- List<cgLog> log = trackable.getLogs();
+ List<LogEntry> log = trackable.getLogs();
// second log entry has several images; just check first two
- assertEquals("http://img.geocaching.com/track/log/large/f2e24c50-394c-4d74-8fb4-87298d8bff1d.jpg", log.get(1).logImages.get(0).getUrl());
- assertEquals("7b Welcome to Geowoodstock", log.get(1).logImages.get(0).getTitle());
- assertEquals("http://img.geocaching.com/track/log/large/b57c29c3-134e-4202-a2a1-69ce8920b055.jpg", log.get(1).logImages.get(1).getUrl());
- assertEquals("8 Crater Lake Natl Park Oregon", log.get(1).logImages.get(1).getTitle());
+ assertEquals("http://img.geocaching.com/track/log/large/f2e24c50-394c-4d74-8fb4-87298d8bff1d.jpg", log.get(1).getLogImages().get(0).getUrl());
+ assertEquals("7b Welcome to Geowoodstock", log.get(1).getLogImages().get(0).getTitle());
+ assertEquals("http://img.geocaching.com/track/log/large/b57c29c3-134e-4202-a2a1-69ce8920b055.jpg", log.get(1).getLogImages().get(1).getUrl());
+ assertEquals("8 Crater Lake Natl Park Oregon", log.get(1).getLogImages().get(1).getTitle());
// third log entry has one image
- assertEquals("http://img.geocaching.com/track/log/large/0096b42d-4d10-45fa-9be2-2d08c0d5cc61.jpg", log.get(2).logImages.get(0).getUrl());
- assertEquals("Traverski&#39;s GC Univ coin on tour", log.get(2).logImages.get(0).getTitle());
+ assertEquals("http://img.geocaching.com/track/log/large/0096b42d-4d10-45fa-9be2-2d08c0d5cc61.jpg", log.get(2).getLogImages().get(0).getUrl());
+ assertEquals("Traverski&#39;s GC Univ coin on tour", log.get(2).getLogImages().get(0).getTitle());
}
public void testParseTrackableWithoutReleaseDate() {
- cgTrackable trackable = cgBase.parseTrackable(getFileContent(R.raw.tb14wfv), null, null);
+ cgTrackable trackable = GCParser.parseTrackable(getFileContent(R.raw.tb14wfv), null, null);
assertNotNull(trackable);
assertEquals("The Brickster", trackable.getName());
assertEquals("Adrian C", trackable.getOwner());
@@ -66,11 +67,11 @@ public class TrackablesTest extends AbstractResourceInstrumentationTestCase {
}
private cgTrackable getTB2R124() {
- return cgBase.parseTrackable(BaseUtils.replaceWhitespace(getFileContent(R.raw.trackable_tb2r124)), null, null);
+ return GCParser.parseTrackable(BaseUtils.replaceWhitespace(getFileContent(R.raw.trackable_tb2r124)), null, null);
}
private cgTrackable getTBXATG() {
- return cgBase.parseTrackable(BaseUtils.replaceWhitespace(getFileContent(R.raw.trackable_tbxatg)), null, null);
+ return GCParser.parseTrackable(BaseUtils.replaceWhitespace(getFileContent(R.raw.trackable_tbxatg)), null, null);
}
}
diff --git a/tests/src/cgeo/geocaching/cgDataTest.java b/tests/src/cgeo/geocaching/cgDataTest.java
index 0625585..3ce6431 100644
--- a/tests/src/cgeo/geocaching/cgDataTest.java
+++ b/tests/src/cgeo/geocaching/cgDataTest.java
@@ -1,26 +1,16 @@
package cgeo.geocaching;
+import cgeo.CGeoTestCase;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
+import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.geopoint.Viewport;
-import android.test.ApplicationTestCase;
-
+import java.util.Collections;
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 class cgDataTest extends CGeoTestCase {
public static void testStoredLists() {
@@ -29,9 +19,10 @@ public class cgDataTest extends ApplicationTestCase<cgeoapplication> {
int listId2 = StoredList.STANDARD_LIST_ID;
// create caches
- final cgCache cache1 = cgBaseTest.createCache(0);
- assertNotNull(cache1);
- final cgCache cache2 = cgBaseTest.createCache(1);
+ final cgCache cache1 = new cgCache();
+ cache1.setGeocode("Cache 1");
+ final cgCache cache2 = new cgCache();
+ cache2.setGeocode("Cache 2");
assertNotNull(cache2);
try {
@@ -51,7 +42,7 @@ public class cgDataTest extends ApplicationTestCase<cgeoapplication> {
// save caches to DB (cache1=listId1, cache2=listId1)
app.saveCache(cache1, LoadFlags.SAVE_ALL);
app.saveCache(cache2, LoadFlags.SAVE_ALL);
- assertTrue(app.getAllStoredCachesCount(false, CacheType.ALL, null) >= 2);
+ assertTrue(app.getAllStoredCachesCount(false, CacheType.ALL) >= 2);
// rename list (cache1=listId1, cache2=listId1)
assertEquals(1, app.renameList(listId1, "cgData Test (renamed)"));
@@ -61,17 +52,17 @@ public class cgDataTest extends ApplicationTestCase<cgeoapplication> {
assertEquals("cgData Test (renamed)", list1.title);
// move to list (cache1=listId2, cache2=listId2)
- app.moveToList(cache1.getGeocode(), listId2);
+ app.moveToList(Collections.singletonList(cache1), 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());
+ app.markDropped(Collections.singletonList(cache2));
// mark stored (cache1=1, cache2=listId2)
- app.markStored(cache2.getGeocode(), listId2);
+ app.markStored(Collections.singletonList(cache2), listId2);
assertEquals(2, app.getAllStoredCachesCount(false, CacheType.ALL, listId2));
// drop stored (cache1=0, cache2=0)
@@ -90,4 +81,14 @@ public class cgDataTest extends ApplicationTestCase<cgeoapplication> {
app.removeList(listId2);
}
}
-} \ No newline at end of file
+
+ // Check that queries don't throw an exception (see issue #1429).
+ public static void testLoadWaypoints() {
+ final Viewport viewport = new Viewport(new Geopoint(-1, -2), new Geopoint(3, 4));
+ final cgeoapplication app = cgeoapplication.getInstance();
+ app.getWaypointsInViewport(viewport, false, false);
+ app.getWaypointsInViewport(viewport, false, true);
+ app.getWaypointsInViewport(viewport, true, false);
+ app.getWaypointsInViewport(viewport, true, true);
+ }
+}
diff --git a/tests/src/cgeo/geocaching/cgeoApplicationTest.java b/tests/src/cgeo/geocaching/cgeoApplicationTest.java
index 89c46c4..a754375 100644
--- a/tests/src/cgeo/geocaching/cgeoApplicationTest.java
+++ b/tests/src/cgeo/geocaching/cgeoApplicationTest.java
@@ -1,27 +1,29 @@
package cgeo.geocaching;
+import cgeo.CGeoTestCase;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.gc.GCBase;
+import cgeo.geocaching.connector.gc.GCParser;
+import cgeo.geocaching.connector.gc.Login;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Viewport;
-import cgeo.geocaching.network.Login;
import cgeo.geocaching.test.RegExPerformanceTest;
import cgeo.geocaching.test.mock.GC1ZXX2;
import cgeo.geocaching.test.mock.GC2CJPF;
import cgeo.geocaching.test.mock.GC2JVEH;
import cgeo.geocaching.test.mock.MockedCache;
import cgeo.geocaching.utils.CancellableHandler;
+import cgeo.geocaching.utils.Log;
+import cgeo.test.Compare;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import android.test.ApplicationTestCase;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
-import android.util.Log;
import java.util.Date;
@@ -32,20 +34,7 @@ import junit.framework.Assert;
* application and/or context.
*/
-public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
-
- public cgeoApplicationTest() {
- super(cgeoapplication.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- // init environment
- createApplication();
- cgBase.initialize(getApplication());
- }
+public class cgeoApplicationTest extends CGeoTestCase {
/**
* The name 'test preconditions' is a convention to signal that if this test
@@ -64,7 +53,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
*/
@MediumTest
public static void testSearchTrackableNotExisting() {
- cgTrackable tb = cgBase.searchTrackable("123456", null, null);
+ cgTrackable tb = GCParser.searchTrackable("123456", null, null);
assertNotNull(tb);
}
@@ -73,7 +62,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
*/
@MediumTest
public static void testSearchTrackable() {
- cgTrackable tb = cgBase.searchTrackable("TB2J1VZ", null, null);
+ cgTrackable tb = GCParser.searchTrackable("TB2J1VZ", null, null);
// fix data
assertEquals("aefffb86-099f-444f-b132-605436163aa8", tb.getGuid());
assertEquals("TB2J1VZ", tb.getGeocode());
@@ -100,9 +89,9 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
*/
@MediumTest
public static cgCache testSearchByGeocode(final String geocode) {
- final SearchResult search = cgBase.searchByGeocode(geocode, null, 0, true, null);
+ final SearchResult search = cgCache.searchByGeocode(geocode, null, 0, true, null);
assertNotNull(search);
- if (Settings.isPremiumMember() || search.error == null) {
+ if (Settings.isPremiumMember() || search.getError() == null) {
assertEquals(1, search.getGeocodes().size());
assertTrue(search.getGeocodes().contains(geocode));
return cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
@@ -116,9 +105,9 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
*/
@MediumTest
public static void testSearchByGeocodeNotExisting() {
- final SearchResult search = cgBase.searchByGeocode("GC123456", null, 0, true, null);
+ final SearchResult search = cgCache.searchByGeocode("GC123456", null, 0, true, null);
assertNotNull(search);
- assertEquals(search.error, StatusCode.UNPUBLISHED_CACHE);
+ assertEquals(StatusCode.UNPUBLISHED_CACHE, search.getError());
}
/**
@@ -135,7 +124,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
deleteCacheFromDBAndLogout(cache.getGeocode());
- SearchResult search = cgBase.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null);
+ SearchResult search = cgCache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null);
assertNotNull(search);
assertEquals(1, search.getGeocodes().size());
assertTrue(search.getGeocodes().contains(cache.getGeocode()));
@@ -148,7 +137,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
deleteCacheFromDBAndLogout(cache.getGeocode());
- search = cgBase.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null);
+ search = cgCache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null);
assertNotNull(search);
assertEquals(0, search.getGeocodes().size());
@@ -174,7 +163,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
deleteCacheFromDBAndLogout(cache.getGeocode());
- SearchResult search = cgBase.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null);
+ SearchResult search = cgCache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null);
assertNotNull(search);
assertEquals(0, search.getGeocodes().size());
@@ -191,7 +180,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
*/
@MediumTest
public static void testSearchByCoords() {
- final SearchResult search = cgBase.searchByCoords(null, new Geopoint("N 52° 24.972 E 009° 35.647"), CacheType.MYSTERY, false);
+ final SearchResult search = GCParser.searchByCoords(null, new Geopoint("N 52° 24.972 E 009° 35.647"), CacheType.MYSTERY, false);
assertNotNull(search);
assertTrue(18 <= search.getGeocodes().size());
assertTrue(search.getGeocodes().contains("GC1RMM2"));
@@ -202,7 +191,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
*/
@MediumTest
public static void testSearchByOwner() {
- final SearchResult search = cgBase.searchByOwner(null, "blafoo", CacheType.MYSTERY, false);
+ final SearchResult search = GCParser.searchByOwner(null, "blafoo", CacheType.MYSTERY, false);
assertNotNull(search);
assertEquals(3, search.getGeocodes().size());
assertTrue(search.getGeocodes().contains("GC36RT6"));
@@ -213,9 +202,9 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
*/
@MediumTest
public static void testSearchByUsername() {
- final SearchResult search = cgBase.searchByUsername(null, "blafoo", CacheType.WEBCAM, false);
+ final SearchResult search = GCParser.searchByUsername(null, "blafoo", CacheType.WEBCAM, false);
assertNotNull(search);
- assertEquals(3, search.totalCnt);
+ assertEquals(3, search.getTotal());
assertTrue(search.getGeocodes().contains("GCP0A9"));
}
@@ -231,8 +220,8 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
GC2CJPF mockedCache = new GC2CJPF();
deleteCacheFromDB(mockedCache.getGeocode());
- final String tokens[] = GCBase.getTokens();
- final Viewport viewport = new Viewport(mockedCache.getCoords(), 0.003, 0.003);
+ final String[] tokens = GCBase.getTokens();
+ final Viewport viewport = new Viewport(mockedCache, 0.003, 0.003);
// check coords for DETAILED
Settings.setLiveMapStrategy(Strategy.DETAILED);
@@ -242,18 +231,20 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
cgCache parsedCache = cgeoapplication.getInstance().loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB);
- assertEquals(Settings.isPremiumMember(), mockedCache.getCoords().isEqualTo(parsedCache.getCoords()));
+ assertEquals(Settings.isPremiumMember(), mockedCache.getCoords().equals(parsedCache.getCoords()));
assertEquals(Settings.isPremiumMember(), parsedCache.isReliableLatLon());
// check update after switch strategy to FAST
Settings.setLiveMapStrategy(Strategy.FAST);
+ GCBase.removeFromTileCache(mockedCache);
+
search = ConnectorFactory.searchByViewport(viewport, tokens);
assertNotNull(search);
assertTrue(search.getGeocodes().contains(mockedCache.getGeocode()));
parsedCache = cgeoapplication.getInstance().loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB);
- assertEquals(Settings.isPremiumMember(), mockedCache.getCoords().isEqualTo(parsedCache.getCoords()));
+ assertEquals(Settings.isPremiumMember(), mockedCache.getCoords().equals(parsedCache.getCoords()));
assertEquals(Settings.isPremiumMember(), parsedCache.isReliableLatLon());
} finally {
@@ -275,21 +266,22 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
try {
- final String tokens[] = null; // without a valid token we are "logged off"
+ final String[] tokens = null; // without a valid token we are "logged off"
// non premium cache
MockedCache cache = new GC2CJPF();
deleteCacheFromDBAndLogout(cache.getGeocode());
+ GCBase.removeFromTileCache(cache);
- Viewport viewport = new Viewport(cache.getCoords(), 0.003, 0.003);
+ Viewport viewport = new Viewport(cache, 0.003, 0.003);
SearchResult search = ConnectorFactory.searchByViewport(viewport, tokens);
assertNotNull(search);
assertTrue(search.getGeocodes().contains(cache.getGeocode()));
// coords differ
cgCache cacheFromViewport = cgeoapplication.getInstance().loadCache(cache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB);
- Log.d(Settings.tag, "cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords expected = " + cache.getCoords());
- Log.d(Settings.tag, "cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords actual = " + cacheFromViewport.getCoords());
+ Log.d("cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords expected = " + cache.getCoords());
+ Log.d("cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords actual = " + cacheFromViewport.getCoords());
assertFalse(cache.getCoords().isEqualTo(cacheFromViewport.getCoords(), 1e-3));
// depending on the chosen strategy the coords can be reliable or not
assertEquals(testStrategy == Strategy.DETAILED, cacheFromViewport.isReliableLatLon());
@@ -298,7 +290,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
cache = new GC2JVEH();
deleteCacheFromDBAndLogout(cache.getGeocode());
- viewport = new Viewport(cache.getCoords(), 0.003, 0.003);
+ viewport = new Viewport(cache, 0.003, 0.003);
search = ConnectorFactory.searchByViewport(viewport, tokens);
assertNotNull(search);
@@ -319,10 +311,15 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
*/
public static void testSearchByGeocodeBasis() {
for (MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) {
- mockedCache.setMockedDataUser(Settings.getUsername());
- cgCache parsedCache = cgeoApplicationTest.testSearchByGeocode(mockedCache.getGeocode());
- if (null != parsedCache) {
- cgBaseTest.testCompareCaches(mockedCache, parsedCache, true);
+ String oldUser = mockedCache.getMockedDataUser();
+ try {
+ mockedCache.setMockedDataUser(Settings.getUsername());
+ cgCache parsedCache = cgeoApplicationTest.testSearchByGeocode(mockedCache.getGeocode());
+ if (null != parsedCache) {
+ Compare.assertCompareCaches(mockedCache, parsedCache, true);
+ }
+ } finally {
+ mockedCache.setMockedDataUser(oldUser);
}
}
}
diff --git a/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java
new file mode 100644
index 0000000..234ff26
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java
@@ -0,0 +1,25 @@
+package cgeo.geocaching.connector.gc;
+
+import cgeo.geocaching.geopoint.Geopoint;
+
+import junit.framework.TestCase;
+
+public class AutoZoomTest extends TestCase {
+
+ public static void testZoom1() {
+ Geopoint bottomLeft = new Geopoint(49.3, 8.3);
+ Geopoint topRight = new Geopoint(49.4, 8.4);
+
+ int zoom = Tile.calcZoomLat(bottomLeft, topRight);
+
+ assertTrue(Math.abs(new Tile(bottomLeft, zoom).getY() - new Tile(topRight, zoom).getY()) == 1);
+ assertTrue(Math.abs(new Tile(bottomLeft, zoom + 1).getY() - new Tile(topRight, zoom + 1).getY()) > 1);
+
+ zoom = Tile.calcZoomLon(bottomLeft, topRight);
+
+ assertTrue(new Tile(bottomLeft, zoom).getX() + 1 == new Tile(topRight, zoom).getX());
+ assertTrue(new Tile(bottomLeft, zoom + 1).getX() + 1 < new Tile(topRight, zoom + 1).getX());
+
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java
index e6a2474..88873a1 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java
@@ -1,11 +1,11 @@
package cgeo.geocaching.connector.gc;
import cgeo.geocaching.SearchResult;
-import cgeo.geocaching.cgBaseTest;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.test.mock.GC2CJPF;
import cgeo.geocaching.test.mock.MockedCache;
+import cgeo.test.Compare;
import java.util.HashSet;
import java.util.Set;
@@ -37,7 +37,7 @@ public class GCBaseTest extends TestCase {
SearchResult result = GCBase.searchByGeocodes(geocodes);
cgCache parsedCache = result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
- cgBaseTest.testCompareCaches(mockedCache, parsedCache, false);
+ Compare.assertCompareCaches(mockedCache, parsedCache, false);
}
}
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
index dfa9a8b..f85a697 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
@@ -4,7 +4,6 @@ import cgeo.geocaching.SearchResult;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Viewport;
-import cgeo.geocaching.network.Login;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
public class GCConnectorTest extends AbstractResourceInstrumentationTestCase {
@@ -18,7 +17,7 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase {
final Viewport viewport = new Viewport(new Geopoint("N 52° 25.369 E 9° 35.499"), new Geopoint("N 52° 25.600 E 9° 36.200"));
SearchResult searchResult = ConnectorFactory.searchByViewport(viewport, tokens);
assertNotNull(searchResult);
- assertTrue(searchResult.getCount() >= 1);
+ assertFalse(searchResult.isEmpty());
assertTrue(searchResult.getGeocodes().contains("GC211WG"));
// Spiel & Sport GC211WG N 52° 25.413 E 009° 36.049
}
@@ -32,12 +31,7 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase {
}
public static void testBaseCodings() {
- assertEquals(2045702, GCBase.newidToGCId("CpLB"));
- assertEquals("CpLB", GCBase.gcidToNewId(2045702));
assertEquals(2045702, GCBase.gccodeToGCId("GC2MEGA"));
- assertEquals("GC2MEGA", GCBase.gcidToGCCode(2045702));
-
- assertEquals("GC211WG", GCBase.newidToGeocode("gEaR"));
}
/** Tile computation with different zoom levels */
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
index c930ab5..809318a 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
@@ -1,6 +1,5 @@
package cgeo.geocaching.connector.gc;
-import cgeo.geocaching.connector.gc.GCConstants;
import cgeo.geocaching.test.mock.MockedCache;
import cgeo.geocaching.utils.BaseUtils;
@@ -31,7 +30,11 @@ public class GCConstantsTest extends AndroidTestCase {
}
private static void assertCacheCount(final int count, final String html) {
- assertEquals(count, Integer.parseInt(BaseUtils.getMatch(html, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", "")));
+ try {
+ assertEquals(count, Integer.parseInt(BaseUtils.getMatch(html, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", "")));
+ } catch (NumberFormatException e) {
+ fail();
+ }
}
public static void testConstants() {
diff --git a/tests/src/cgeo/geocaching/cgBaseTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
index 408cd94..54f69ce 100644
--- a/tests/src/cgeo/geocaching/cgBaseTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
@@ -1,16 +1,18 @@
-package cgeo.geocaching;
+package cgeo.geocaching.connector.gc;
-import cgeo.geocaching.connector.gc.GCConstants;
+import cgeo.geocaching.SearchResult;
+import cgeo.geocaching.Settings;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.enumerations.LoadFlags;
-import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
import cgeo.geocaching.test.RegExPerformanceTest;
import cgeo.geocaching.test.mock.MockedCache;
-import cgeo.geocaching.utils.BaseUtils;
import cgeo.geocaching.utils.CancellableHandler;
+import cgeo.test.Compare;
import org.apache.commons.lang3.StringUtils;
@@ -18,67 +20,34 @@ import android.test.suitebuilder.annotation.MediumTest;
import java.util.ArrayList;
-public class cgBaseTest extends AbstractResourceInstrumentationTestCase {
-
- public static void testRegEx() {
- String page = MockedCache.readCachePage("GC2CJPF");
- assertEquals("blafoo", BaseUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???"));
- assertTrue(page.contains("id=\"ctl00_hlRenew\"") || "Premium Member".equals(BaseUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???")));
- int cachesFound = Integer.parseInt(BaseUtils.getMatch(page, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", ""));
- assertTrue(cachesFound >= 491);
- }
-
- public static void testReplaceWhitespaces() {
- assertEquals("foo bar baz ", BaseUtils.replaceWhitespace(new String(" foo\n\tbar \r baz ")));
- }
-
- public static void testElevation() {
- assertEquals(125.663703918457, (new Geopoint(48.0, 2.0)).getElevation(), 0.1);
+public class GCParserTest extends AbstractResourceInstrumentationTestCase {
+ public void testUnpublishedCache() {
+ final String page = getFileContent(R.raw.cache_unpublished);
+ SearchResult result = GCParser.parseCacheFromText(page, null);
+ assertNotNull(result);
+ assertTrue(result.isEmpty());
+ assertEquals(StatusCode.UNPUBLISHED_CACHE, result.getError());
}
- public static void testCompareCaches(ICache expected, cgCache actual, boolean all) {
- assertEquals(expected.getGeocode(), actual.getGeocode());
- assertTrue(expected.getType() == actual.getType());
- assertEquals(expected.getOwner(), actual.getOwner());
- assertEquals(expected.getDifficulty(), actual.getDifficulty());
- assertEquals(expected.getTerrain(), actual.getTerrain());
- assertEquals(expected.isDisabled(), actual.isDisabled());
- assertEquals(expected.isArchived(), actual.isArchived());
- assertEquals(expected.getSize(), actual.getSize());
- assertEquals(expected.getName(), actual.getName());
- assertEquals(expected.getGuid(), actual.getGuid());
- assertTrue(expected.getFavoritePoints() <= actual.getFavoritePoints());
- assertEquals(expected.getHiddenDate().toString(), actual.getHiddenDate().toString());
- assertEquals(expected.isPremiumMembersOnly(), actual.isPremiumMembersOnly());
-
- if (all) {
- assertEquals(expected.getLatitude(), actual.getLatitude());
- assertEquals(expected.getLongitude(), actual.getLongitude());
- assertTrue(actual.isReliableLatLon());
- assertEquals(expected.isOwn(), actual.isOwn());
- assertEquals(expected.getOwnerReal(), actual.getOwnerReal());
- assertEquals(expected.getHint(), actual.getHint());
- assertTrue(actual.getDescription().startsWith(expected.getDescription()));
- assertEquals(expected.getShortDescription(), actual.getShortDescription());
- assertEquals(expected.getCacheId(), actual.getCacheId());
- assertEquals(expected.getLocation(), actual.getLocation());
- assertEquals(expected.isFound(), actual.isFound());
- assertEquals(expected.isFavorite(), actual.isFavorite());
- assertEquals(expected.isWatchlist(), actual.isWatchlist());
+ private static cgCache createCache(int index) {
+ final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES[index];
+ // to get the same results we have to use the date format used when the mocked data was created
+ String oldCustomDate = Settings.getGcCustomDate();
- for (String attribute : expected.getAttributes()) {
- assertTrue(actual.getAttributes().contains(attribute));
- }
- for (LogType logType : expected.getLogCounts().keySet()) {
- assertTrue(actual.getLogCounts().get(logType) >= expected.getLogCounts().get(logType));
- }
+ SearchResult searchResult;
+ try {
+ Settings.setGcCustomDate(MockedCache.getDateFormat());
+ searchResult = GCParser.parseCacheFromText(mockedCache.getData(), null);
+ } finally {
+ Settings.setGcCustomDate(oldCustomDate);
+ }
- // the inventory can differ to often, therefore we don't compare them
+ assertNotNull(searchResult);
+ assertEquals(1, searchResult.getCount());
- int actualSpoilersSize = null != actual.getSpoilers() ? actual.getSpoilers().size() : 0;
- int expectedSpoilersSize = null != expected.getSpoilers() ? expected.getSpoilers().size() : 0;
- assertEquals(expectedSpoilersSize, actualSpoilersSize);
- }
+ final cgCache cache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
+ assertNotNull(cache);
+ return cache;
}
/**
@@ -92,10 +61,10 @@ public class cgBaseTest extends AbstractResourceInstrumentationTestCase {
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());
- SearchResult searchResult = cgBase.parseCacheFromText(mockedCache.getData(), null);
+ SearchResult searchResult = GCParser.parseCacheFromText(mockedCache.getData(), null);
cgCache parsedCache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
assertTrue(StringUtils.isNotBlank(mockedCache.getMockedDataUser()));
- cgBaseTest.testCompareCaches(mockedCache, parsedCache, true);
+ Compare.assertCompareCaches(mockedCache, parsedCache, true);
}
} finally {
Settings.setGcCustomDate(gcCustomDate);
@@ -103,7 +72,7 @@ public class cgBaseTest extends AbstractResourceInstrumentationTestCase {
}
public static void testWaypointsFromNote() {
- final cgCache cache = cgBaseTest.createCache(0);
+ final cgCache cache = createCache(0);
final Geopoint[] empty = new Geopoint[] {};
final Geopoint[] one = new Geopoint[] { new Geopoint("N51 21.523", "E7 2.680") };
@@ -145,36 +114,8 @@ public class cgBaseTest extends AbstractResourceInstrumentationTestCase {
cache.parseWaypointsFromNote();
assertEquals(expected.length, cache.getWaypoints().size());
for (int i = 0; i < expected.length; i++) {
- assertTrue(expected[i].isEqualTo(cache.getWaypoint(i).getCoords()));
- }
- }
-
- 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
- String oldCustomDate = Settings.getGcCustomDate();
-
- SearchResult searchResult;
- try {
- Settings.setGcCustomDate(MockedCache.getDateFormat());
- searchResult = cgBase.parseCacheFromText(mockedCache.getData(), null);
- } finally {
- Settings.setGcCustomDate(oldCustomDate);
+ assertTrue(expected[i].equals(cache.getWaypoint(i).getCoords()));
}
-
- assertNotNull(searchResult);
- assertEquals(1, searchResult.getCount());
-
- final cgCache cache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
- assertNotNull(cache);
- return cache;
}
- public void testUnpublishedCache() {
- final String page = getFileContent(R.raw.cache_unpublished);
- SearchResult result = cgBase.parseCacheFromText(page, null);
- assertNotNull(result);
- assertEquals(0, result.getCount());
- assertEquals(StatusCode.UNPUBLISHED_CACHE, result.getError());
- }
-} \ No newline at end of file
+}
diff --git a/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java b/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java
index 74704b3..3fa17f8 100644
--- a/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java
@@ -1,20 +1,19 @@
package cgeo.geocaching.connector.gc;
-import cgeo.geocaching.Settings;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
+import cgeo.geocaching.utils.Log;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.util.Log;
public class IconDecoderTest extends AbstractResourceInstrumentationTestCase {
public void testparseMapPNG14() {
final Bitmap bitmap = getBitmap(R.raw.tile14);
- Log.d(Settings.tag, "Bitmap=" + bitmap.getWidth() + "x" + bitmap.getHeight());
+ Log.d("Bitmap=" + bitmap.getWidth() + "x" + bitmap.getHeight());
assertEquals(CacheType.TRADITIONAL, parseMapPNG(bitmap, 97, 136, 14).getType());
assertEquals(CacheType.MYSTERY, parseMapPNG(bitmap, 226, 104, 14).getType());
diff --git a/tests/src/cgeo/geocaching/connector/opencaching/OkapiClientTest.java b/tests/src/cgeo/geocaching/connector/opencaching/OkapiClientTest.java
index d5dfac1..608f728 100644
--- a/tests/src/cgeo/geocaching/connector/opencaching/OkapiClientTest.java
+++ b/tests/src/cgeo/geocaching/connector/opencaching/OkapiClientTest.java
@@ -1,10 +1,11 @@
package cgeo.geocaching.connector.opencaching;
+import cgeo.CGeoTestCase;
import cgeo.geocaching.cgCache;
+import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.enumerations.LoadFlags;
-import android.test.AndroidTestCase;
-
-public class OkapiClientTest extends AndroidTestCase {
+public class OkapiClientTest extends CGeoTestCase {
public static void testGetOCCache() {
String geoCode = "OU0331";
@@ -12,6 +13,14 @@ public class OkapiClientTest extends AndroidTestCase {
assertNotNull(cache);
assertEquals(geoCode, cache.getGeocode());
assertEquals("Oshkosh Municipal Tank", cache.getName());
+ assertTrue(cache.isDetailed());
+
+ // cache should be stored to DB (to listID 0) when loaded above
+ cache = cgeoapplication.getInstance().loadCache(geoCode, LoadFlags.LOAD_ALL_DB_ONLY);
+ assertNotNull(cache);
+ assertEquals(geoCode, cache.getGeocode());
+ assertEquals("Oshkosh Municipal Tank", cache.getName());
+ assertTrue(cache.isDetailed());
}
}
diff --git a/tests/src/cgeo/geocaching/enumerations/CacheAttributeTest.java b/tests/src/cgeo/geocaching/enumerations/CacheAttributeTest.java
new file mode 100644
index 0000000..f369b0e
--- /dev/null
+++ b/tests/src/cgeo/geocaching/enumerations/CacheAttributeTest.java
@@ -0,0 +1,23 @@
+package cgeo.geocaching.enumerations;
+
+import android.test.AndroidTestCase;
+
+public class CacheAttributeTest extends AndroidTestCase {
+
+ public static void testTrimAttributeName() {
+ for (CacheAttribute attribute : CacheAttribute.values()) {
+ final String rawName = attribute.gcRawName;
+ assertTrue("bad attribute name " + rawName, CacheAttribute.trimAttributeName(rawName).equals(rawName));
+ }
+ }
+
+ public static void testIds() {
+ for (CacheAttribute attribute : CacheAttribute.values()) {
+ if (attribute != CacheAttribute.UNKNOWN) {
+ assertTrue(attribute.drawableId != 0);
+ assertTrue(attribute.stringIdYes != 0);
+ assertTrue(attribute.stringIdNo != 0);
+ }
+ }
+ }
+}
diff --git a/tests/src/cgeo/geocaching/files/GPXImporterTest.java b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
index 10d60b3..a0dd377 100644
--- a/tests/src/cgeo/geocaching/files/GPXImporterTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
@@ -8,10 +8,10 @@ import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
import cgeo.geocaching.utils.CancellableHandler;
+import cgeo.geocaching.utils.Log;
import android.net.Uri;
import android.os.Message;
-import android.util.Log;
import java.io.File;
import java.io.IOException;
@@ -82,7 +82,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
try {
importThread.join();
} catch (InterruptedException e) {
- Log.e(Settings.tag, "GPXImporterTest.runImportThread", e);
+ Log.e("GPXImporterTest.runImportThread", e);
}
importStepHandler.waitForCompletion();
}
@@ -231,7 +231,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
@Override
public synchronized void handleRegularMessage(Message msg) {
- final Message msg1 = new Message();
+ final Message msg1 = Message.obtain();
msg1.copyFrom(msg);
messages.add(msg1);
lastMessage = System.currentTimeMillis();
@@ -281,7 +281,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
super.tearDown();
}
- private void deleteDirectory(File dir) {
+ private static void deleteDirectory(File dir) {
for (File f : dir.listFiles()) {
if (f.isFile()) {
f.delete();
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 3754af1..47975c9 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -1,13 +1,12 @@
package cgeo.geocaching.files;
+import cgeo.geocaching.LogEntry;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgLog;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
@@ -43,7 +42,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertEquals(5.0f, cache.getTerrain());
assertEquals("Baden-Württemberg, Germany", cache.getLocation());
assertEquals("Ein alter Kindheitstraum, ein Schatz auf einer unbewohnten Insel.\nA old dream of my childhood, a treasure on a lonely island.", cache.getShortdesc());
- assertTrue(new Geopoint(48.859683, 9.1874).isEqualTo(cache.getCoords()));
+ assertEquals(new Geopoint(48.859683, 9.1874), cache.getCoords());
return cache;
}
@@ -67,7 +66,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertEquals(4.0f, cache.getTerrain());
assertEquals("Baden-Württemberg, Germany", cache.getLocation());
assertEquals("Ein alter Kindheitstraum, ein Schatz auf einer unbewohnten Insel. A old dream of my childhood, a treasure on a lonely is", cache.getShortdesc());
- assertTrue(new Geopoint(48.85968, 9.18740).isEqualTo(cache.getCoords()));
+ assertEquals(new Geopoint(48.85968, 9.18740), cache.getCoords());
assertTrue(cache.isReliableLatLon());
}
@@ -117,8 +116,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertEquals(2.0f, cache.getDifficulty(), 0.01f);
assertEquals(1.0f, cache.getTerrain(), 0.01f);
final Geopoint refCoordinates = new Geopoint("N 49° 19.122", "E 008° 32.739");
- assertEquals(refCoordinates.format(GeopointFormatter.Format.LAT_DECMINUTE), cache.getLatitude());
- assertEquals(refCoordinates.format(GeopointFormatter.Format.LON_DECMINUTE), cache.getLongitude());
+ assertEquals(refCoordinates, cache.getCoords());
assertEquals("vptsz", cache.getOwner());
assertEquals(CacheSize.SMALL, cache.getSize());
assertEquals(CacheType.MULTI, cache.getType());
@@ -131,7 +129,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertEquals("Station3: Der zerbrochene Stein zählt doppelt.\nFinal: Oben neben dem Tor", cache.getHint());
// logs
assertEquals(6, cache.getLogs().size());
- final cgLog log = cache.getLogs().get(5);
+ final LogEntry log = cache.getLogs().get(5);
assertEquals("Geoteufel", log.author);
assertEquals(parseTime("2011-09-11T07:00:00Z"), log.date);
assertEquals(-1, log.found);
@@ -195,9 +193,8 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
}
}
- List<cgCache> cacheList = new ArrayList<cgCache>(caches);
// TODO: may need to sort by geocode when a test imports more than one cache
- return cacheList;
+ return new ArrayList<cgCache>(caches);
}
public static void testParseDateWithFractionalSeconds() {
diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java
index 64ac7ad..7e7a1be 100644
--- a/tests/src/cgeo/geocaching/files/LocParserTest.java
+++ b/tests/src/cgeo/geocaching/files/LocParserTest.java
@@ -25,9 +25,8 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase {
instream.close();
}
- List<cgCache> cacheList = new ArrayList<cgCache>(caches);
// TODO: may need to sort by geocode when a test imports more than one cache
- return cacheList;
+ return new ArrayList<cgCache>(caches);
}
public void testOCLoc() throws IOException, ParserException {
@@ -37,7 +36,7 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase {
assertNotNull(cache);
assertEquals("OC5952", cache.getGeocode());
assertEquals("Die Schatzinsel / treasure island", cache.getName());
- assertTrue(new Geopoint(48.85968, 9.18740).isEqualTo(cache.getCoords()));
+ assertEquals(new Geopoint(48.85968, 9.18740), cache.getCoords());
}
public void testGCLoc() throws IOException, ParserException {
@@ -47,7 +46,7 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase {
assertNotNull(cache);
assertEquals("GC1BKP3", cache.getGeocode());
assertEquals("Die Schatzinsel / treasure island", cache.getName());
- assertTrue(new Geopoint(48.859683, 9.1874).isEqualTo(cache.getCoords()));
+ assertEquals(new Geopoint(48.859683, 9.1874), cache.getCoords());
assertEquals(1.0f, cache.getDifficulty());
assertEquals(5.0f, cache.getTerrain());
assertEquals(CacheSize.MICRO, cache.getSize());
diff --git a/tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java b/tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java
new file mode 100644
index 0000000..a24cf72
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java
@@ -0,0 +1,24 @@
+package cgeo.geocaching.filter;
+
+import cgeo.CGeoTestCase;
+import cgeo.geocaching.cgCache;
+
+public class DifficultyFilterTest extends CGeoTestCase {
+
+ public static void testTerrainFilter() {
+ final cgCache easy = new cgCache();
+ easy.setDifficulty(1.5f);
+
+ final cgCache hard = new cgCache();
+ hard.setDifficulty(5f);
+
+ final DifficultyFilter easyFilter = new DifficultyFilter(1);
+
+ assertTrue(easyFilter.accepts(easy));
+ assertFalse(easyFilter.accepts(hard));
+ }
+
+ public static void testAllFilters() {
+ assertTrue(new DifficultyFilter.Factory().getFilters().length == 5); // difficulty ranges from 1 to 5
+ }
+}
diff --git a/tests/src/cgeo/geocaching/filter/SizeFilterTest.java b/tests/src/cgeo/geocaching/filter/SizeFilterTest.java
new file mode 100644
index 0000000..a641874
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/SizeFilterTest.java
@@ -0,0 +1,49 @@
+package cgeo.geocaching.filter;
+
+import cgeo.CGeoTestCase;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.enumerations.CacheSize;
+
+import java.util.ArrayList;
+
+public class SizeFilterTest extends CGeoTestCase {
+
+ private cgCache micro;
+ private cgCache regular;
+ private SizeFilter microFilter;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // cache initialization can only be done without errors after application setup
+ micro = new cgCache();
+ micro.setSize(CacheSize.MICRO);
+
+ regular = new cgCache();
+ regular.setSize(CacheSize.REGULAR);
+
+ microFilter = new SizeFilter(CacheSize.MICRO);
+ }
+
+ public void testAccepts() {
+ assertTrue(microFilter.accepts(micro));
+ assertFalse(microFilter.accepts(regular));
+ }
+
+ public static void testGetAllFilters() {
+ final int expectedSizes = CacheSize.values().length - 1; // hide "UNKNOWN"
+ assertEquals(expectedSizes, new SizeFilter.Factory().getFilters().length);
+ }
+
+ public void testFilter() {
+ final ArrayList<cgCache> list = new ArrayList<cgCache>();
+ list.add(regular);
+ list.add(micro);
+ assertEquals(2, list.size());
+
+ microFilter.filter(list);
+ assertEquals(1, list.size());
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/filter/StateArchivedFilterTest.java b/tests/src/cgeo/geocaching/filter/StateArchivedFilterTest.java
new file mode 100644
index 0000000..9b40140
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/StateArchivedFilterTest.java
@@ -0,0 +1,27 @@
+package cgeo.geocaching.filter;
+
+import cgeo.CGeoTestCase;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.filter.StateFilter.StateArchivedFilter;
+
+public class StateArchivedFilterTest extends CGeoTestCase {
+
+ private StateFilter.StateArchivedFilter archivedFilter;
+ private cgCache archivedCache;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // members can only be setup here, after application is initialized
+ archivedFilter = new StateArchivedFilter();
+ archivedCache = new cgCache();
+ archivedCache.setArchived(true);
+ }
+
+ public void testAccepts() {
+ assertTrue(archivedFilter.accepts(archivedCache));
+ assertFalse(archivedFilter.accepts(new cgCache()));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/filter/StateDisabledFilterTest.java b/tests/src/cgeo/geocaching/filter/StateDisabledFilterTest.java
new file mode 100644
index 0000000..e73f771
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/StateDisabledFilterTest.java
@@ -0,0 +1,26 @@
+package cgeo.geocaching.filter;
+
+import cgeo.CGeoTestCase;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.filter.StateFilter.StateDisabledFilter;
+
+public class StateDisabledFilterTest extends CGeoTestCase {
+
+ private StateFilter.StateDisabledFilter disabledFilter;
+ private cgCache disabledCache;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ disabledFilter = new StateDisabledFilter();
+ disabledCache = new cgCache();
+ disabledCache.setDisabled(true);
+ }
+
+ public void testAccepts() {
+ assertTrue(disabledFilter.accepts(disabledCache));
+ assertFalse(disabledFilter.accepts(new cgCache()));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/filter/StateFoundFilterTest.java b/tests/src/cgeo/geocaching/filter/StateFoundFilterTest.java
new file mode 100644
index 0000000..053363f
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/StateFoundFilterTest.java
@@ -0,0 +1,26 @@
+package cgeo.geocaching.filter;
+
+import cgeo.CGeoTestCase;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.filter.StateFilter.StateFoundFilter;
+
+public class StateFoundFilterTest extends CGeoTestCase {
+
+ private StateFilter.StateFoundFilter foundFilter;
+ private cgCache foundCache;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ foundFilter = new StateFoundFilter();
+ foundCache = new cgCache();
+ foundCache.setFound(true);
+ }
+
+ public void testAccepts() {
+ assertTrue(foundFilter.accepts(foundCache));
+ assertFalse(foundFilter.accepts(new cgCache()));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/filter/StatePremiumFilterTest.java b/tests/src/cgeo/geocaching/filter/StatePremiumFilterTest.java
new file mode 100644
index 0000000..9221da0
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/StatePremiumFilterTest.java
@@ -0,0 +1,26 @@
+package cgeo.geocaching.filter;
+
+import cgeo.CGeoTestCase;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.filter.StateFilter.StatePremiumFilter;
+
+public class StatePremiumFilterTest extends CGeoTestCase {
+
+ private StateFilter.StatePremiumFilter premiumFilter;
+ private cgCache premiumCache;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ premiumFilter = new StatePremiumFilter();
+ premiumCache = new cgCache();
+ premiumCache.setPremiumMembersOnly(true);
+ }
+
+ public void testAccepts() {
+ assertTrue(premiumFilter.accepts(premiumCache));
+ assertFalse(premiumFilter.accepts(new cgCache()));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/filter/TerrainFilterTest.java b/tests/src/cgeo/geocaching/filter/TerrainFilterTest.java
new file mode 100644
index 0000000..9deea34
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/TerrainFilterTest.java
@@ -0,0 +1,24 @@
+package cgeo.geocaching.filter;
+
+import cgeo.CGeoTestCase;
+import cgeo.geocaching.cgCache;
+
+public class TerrainFilterTest extends CGeoTestCase {
+
+ public static void testTerrainFilter() {
+ final cgCache easy = new cgCache();
+ easy.setTerrain(1.5f);
+
+ final cgCache hard = new cgCache();
+ hard.setTerrain(5f);
+
+ final AbstractRangeFilter easyFilter = new TerrainFilter(1);
+
+ assertTrue(easyFilter.accepts(easy));
+ assertFalse(easyFilter.accepts(hard));
+ }
+
+ public static void testAllFilters() {
+ assertTrue(new TerrainFilter.Factory().getFilters().length == 5); // terrain ranges from 1 to 5
+ }
+}
diff --git a/tests/src/cgeo/geocaching/filter/TypeFilterTest.java b/tests/src/cgeo/geocaching/filter/TypeFilterTest.java
new file mode 100644
index 0000000..5b2631c
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/TypeFilterTest.java
@@ -0,0 +1,52 @@
+package cgeo.geocaching.filter;
+
+import cgeo.CGeoTestCase;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.enumerations.CacheType;
+
+import java.util.ArrayList;
+
+public class TypeFilterTest extends CGeoTestCase {
+
+ private TypeFilter traditionalFilter;
+ private cgCache traditional;
+ private cgCache mystery;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ traditionalFilter = new TypeFilter(CacheType.TRADITIONAL);
+
+ traditional = new cgCache();
+ traditional.setType(CacheType.TRADITIONAL);
+
+ mystery = new cgCache();
+ mystery.setType(CacheType.MYSTERY);
+ }
+
+ public void testAccepts() {
+ assertTrue(traditionalFilter.accepts(traditional));
+ assertFalse(traditionalFilter.accepts(mystery));
+ }
+
+ public void testFilter() {
+ final ArrayList<cgCache> list = new ArrayList<cgCache>();
+ traditionalFilter.filter(list);
+ assertEquals(0, list.size());
+
+ list.add(traditional);
+ list.add(mystery);
+ assertEquals(2, list.size());
+
+ traditionalFilter.filter(list);
+ assertEquals(1, list.size());
+ assertTrue(list.contains(traditional));
+
+ }
+
+ public static void testGetAllFilters() {
+ final int expectedEntries = CacheType.values().length - 1; // hide "all"
+ assertEquals(expectedEntries, new TypeFilter.Factory().getFilters().length);
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
index 661623e..44fbe18 100644
--- a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
@@ -1,7 +1,5 @@
package cgeo.geocaching.geopoint;
-import cgeo.geocaching.geopoint.GeopointParser.ParseException;
-
import android.test.AndroidTestCase;
public class GeoPointParserTest extends AndroidTestCase {
@@ -27,7 +25,7 @@ public class GeoPointParserTest extends AndroidTestCase {
Geopoint point = null;
try {
point = GeopointParser.parse("N 49° 56.031");
- } catch (ParseException e) {
+ } catch (Geopoint.ParseException e) {
// expected
}
assertEquals(null, point);
@@ -57,14 +55,14 @@ public class GeoPointParserTest extends AndroidTestCase {
final Geopoint p2 = GeopointParser.parse("N51 21.523", "E07 02.680");
assertNotNull(p1);
assertNotNull(p2);
- assertTrue(p1.isEqualTo(p2));
+ assertTrue(p1.equals(p2));
}
public static void testUnrelatedParts() {
Geopoint point = null;
try {
point = GeopointParser.parse("N51 21.523 and some words in between, so there is no relation E07 02.680");
- } catch (ParseException e) {
+ } catch (Geopoint.ParseException e) {
// expected
}
assertEquals(null, point);
@@ -77,6 +75,6 @@ public class GeoPointParserTest extends AndroidTestCase {
"E 15° 53' 41.68''");
assertNotNull(pointComma);
assertNotNull(pointDot);
- assertTrue(pointComma.isEqualTo(pointDot));
+ assertTrue(pointComma.equals(pointDot));
}
}
diff --git a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java b/tests/src/cgeo/geocaching/geopoint/GeopointTest.java
index 894b046..76a9496 100644
--- a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/GeopointTest.java
@@ -1,9 +1,10 @@
package cgeo.geocaching.geopoint;
-import cgeo.geocaching.geopoint.Geopoint.DDD;
-import cgeo.geocaching.geopoint.Geopoint.DMM;
-import cgeo.geocaching.geopoint.Geopoint.DMS;
+import cgeo.geocaching.geopoint.direction.DDD;
+import cgeo.geocaching.geopoint.direction.DMM;
+import cgeo.geocaching.geopoint.direction.DMS;
+import android.os.Bundle;
import android.test.AndroidTestCase;
import junit.framework.Assert;
@@ -41,12 +42,6 @@ public class GeopointTest extends AndroidTestCase {
Assert.assertFalse(gp1.equals(gp2));
}
- public static void testCreateE6() {
- final Geopoint gp1 = new Geopoint(48.2, 2.34);
- final Geopoint gp2 = new Geopoint(48200000, 2340000);
- Assert.assertTrue(gp1.isEqualTo(gp2, 1e-6));
- }
-
public static void testGetE6() {
final Geopoint gp = new Geopoint(41.2, -3.4);
Assert.assertEquals(41200000.0, gp.getLatitudeE6(), 1e-6);
@@ -67,6 +62,14 @@ public class GeopointTest extends AndroidTestCase {
Assert.assertEquals(107.715, gp2.bearingTo(gp1), 1e-3);
}
+ public static void testParcelable() {
+ final Geopoint gp = new Geopoint(1.2, 3.4);
+ final String KEY = "geopoint";
+ final Bundle bundle = new Bundle();
+ bundle.putParcelable(KEY, gp);
+ assertEquals(gp, bundle.getParcelable(KEY));
+ }
+
public static void testDDD() {
// case 1
final Geopoint gp1 = new Geopoint(51.3d, 13.8d);
@@ -77,7 +80,7 @@ public class GeopointTest extends AndroidTestCase {
Geopoint gp1a = DDD.createGeopoint(String.valueOf(ddd1.latDir), String.valueOf(ddd1.latDeg), String.valueOf(ddd1.latDegFrac),
String.valueOf(ddd1.lonDir), String.valueOf(ddd1.lonDeg), String.valueOf(ddd1.lonDegFrac));
- Assert.assertTrue(gp1a.isEqualTo(gp1));
+ Assert.assertTrue(gp1a.equals(gp1));
// case 2
final Geopoint gp2 = new Geopoint(51.34567d, 13.87654d);
@@ -88,7 +91,7 @@ public class GeopointTest extends AndroidTestCase {
Geopoint gp2a = DDD.createGeopoint(String.valueOf(ddd2.latDir), String.valueOf(ddd2.latDeg), String.valueOf(ddd2.latDegFrac),
String.valueOf(ddd2.lonDir), String.valueOf(ddd2.lonDeg), String.valueOf(ddd2.lonDegFrac));
- Assert.assertTrue(gp2a.isEqualTo(gp2));
+ Assert.assertTrue(gp2a.equals(gp2));
// case 3
final Geopoint gp3 = new Geopoint(51.29999833333333d, 13.8d);
@@ -137,7 +140,7 @@ public class GeopointTest extends AndroidTestCase {
Geopoint gp1a = DMM.createGeopoint(String.valueOf(dmm1.latDir), String.valueOf(dmm1.latDeg), String.valueOf(dmm1.latMin), String.valueOf(dmm1.latMinFrac),
String.valueOf(dmm1.lonDir), String.valueOf(dmm1.lonDeg), String.valueOf(dmm1.lonMin), String.valueOf(dmm1.lonMinFrac));
- Assert.assertTrue(gp1a.isEqualTo(gp1));
+ Assert.assertTrue(gp1a.equals(gp1));
// case 2
final Geopoint gp2 = new Geopoint(51.34567d, 13.87654d);
@@ -194,7 +197,7 @@ public class GeopointTest extends AndroidTestCase {
Geopoint gp1a = DMS.createGeopoint(String.valueOf(dms1.latDir), String.valueOf(dms1.latDeg), String.valueOf(dms1.latMin), String.valueOf(dms1.latSec), String.valueOf(dms1.latSecFrac),
String.valueOf(dms1.lonDir), String.valueOf(dms1.lonDeg), String.valueOf(dms1.lonMin), String.valueOf(dms1.lonSec), String.valueOf(dms1.lonSecFrac));
- Assert.assertTrue(gp1a.isEqualTo(gp1));
+ Assert.assertTrue(gp1a.equals(gp1));
// case 2
final Geopoint gp2 = new Geopoint(51.34567d, 13.87654d);
@@ -243,4 +246,8 @@ public class GeopointTest extends AndroidTestCase {
Assert.assertEquals(lonSecFrac, dms.lonSecFrac);
}
+ public static void testElevation() {
+ assertEquals(125.663703918457, (new Geopoint(48.0, 2.0)).getElevation(), 0.1);
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/geopoint/HumanDistanceTest.java b/tests/src/cgeo/geocaching/geopoint/HumanDistanceTest.java
index 3c7cb98..c5fce00 100644
--- a/tests/src/cgeo/geocaching/geopoint/HumanDistanceTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/HumanDistanceTest.java
@@ -1,19 +1,41 @@
package cgeo.geocaching.geopoint;
+import cgeo.CGeoTestCase;
import cgeo.geocaching.Settings;
-import android.test.AndroidTestCase;
+import java.util.regex.Pattern;
-public class HumanDistanceTest extends AndroidTestCase {
+public class HumanDistanceTest extends CGeoTestCase {
- public static void testHumanDistance() {
- assertEquals("?", HumanDistance.getHumanDistance(null));
- if (Settings.isUseMetricUnits()) {
- assertEquals("123 km", HumanDistance.getHumanDistance(123.456f));
- assertEquals("123 m", HumanDistance.getHumanDistance(0.123456f));
+ private static void assertMatch(final String ok, final float distance) {
+ final String humanDistance = HumanDistance.getHumanDistance(distance);
+ if (!Pattern.compile('^' + ok + '$').matcher(humanDistance).find()) {
+ fail("getHumanDistance(" + distance +
+ ") [metric: " + (Settings.isUseMetricUnits() ? "yes" : "no") +
+ "] fails to match " + ok + ": " + humanDistance);
}
- else {
- assertEquals("77 mi", HumanDistance.getHumanDistance(123.456f));
+ }
+
+ // Make method non-static so that Settings is initialized
+ @SuppressWarnings("static-method")
+ public void testHumanDistance() {
+ assertEquals("?", HumanDistance.getHumanDistance(null));
+ final boolean savedMetrics = Settings.isUseMetricUnits();
+ try {
+ Settings.setUseMetricUnits(true);
+ assertMatch("123 km", 122.782f);
+ assertMatch("123 km", 123.456f);
+ assertMatch("12.3 km", 12.3456f);
+ assertMatch("1.23 km", 1.23456f);
+ assertMatch("123 m", 0.123456f);
+ Settings.setUseMetricUnits(false);
+ assertMatch("76.7 mi", 123.456f);
+ assertMatch("7.67 mi", 12.3456f);
+ assertMatch("0.77 mi", 1.23456f);
+ assertMatch("405 ft", 0.123456f);
+ assertMatch("40.5 ft", 0.0123456f);
+ } finally {
+ Settings.setUseMetricUnits(savedMetrics);
}
}
}
diff --git a/tests/src/cgeo/geocaching/geopoint/ViewportTest.java b/tests/src/cgeo/geocaching/geopoint/ViewportTest.java
new file mode 100644
index 0000000..ac32468
--- /dev/null
+++ b/tests/src/cgeo/geocaching/geopoint/ViewportTest.java
@@ -0,0 +1,100 @@
+package cgeo.geocaching.geopoint;
+
+import cgeo.geocaching.ICoordinates;
+
+import android.test.AndroidTestCase;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+public class ViewportTest extends AndroidTestCase {
+
+ final private static Viewport vpRef = new Viewport(new Geopoint(-1.0, -2.0), new Geopoint(3.0, 4.0));
+
+ public static void assertBounds(final Viewport vp) {
+ assertEquals(new Geopoint(1.0, 1.0), vp.center);
+ assertEquals(new Geopoint(3.0, 4.0), vp.topRight);
+ assertEquals(new Geopoint(-1.0, -2.0), vp.bottomLeft);
+ }
+
+ public static void testCreationBounds() {
+ assertBounds(new Viewport(new Geopoint(-1.0, -2.0), new Geopoint(3.0, 4.0)));
+ assertBounds(new Viewport(new Geopoint(3.0, 4.0), new Geopoint(-1.0, -2.0)));
+ assertBounds(new Viewport(new Geopoint(-1.0, 4.0), new Geopoint(3.0, -2.0)));
+ assertBounds(new Viewport(new Geopoint(3.0, -2.0), new Geopoint(-1.0, 4.0)));
+ }
+
+ public static void testCreationCenter() {
+ assertBounds(new Viewport(new Geopoint(1.0, 1.0), 4.0, 6.0));
+ }
+
+ public static void testCreationSeparate() {
+ assertBounds(vpRef);
+ }
+
+ public static void testMinMax() {
+ assertEquals(-1.0, vpRef.getLatitudeMin());
+ assertEquals(3.0, vpRef.getLatitudeMax());
+ assertEquals(-2.0, vpRef.getLongitudeMin());
+ assertEquals(4.0, vpRef.getLongitudeMax());
+ }
+
+ public static void testSpans() {
+ assertEquals(4.0, vpRef.getLatitudeSpan());
+ assertEquals(6.0, vpRef.getLongitudeSpan());
+ }
+
+ public static void testInViewport() {
+ assertFalse(vpRef.contains(new Geopoint(-2.0, -2.0)));
+ assertFalse(vpRef.contains(new Geopoint(4.0, 4.0)));
+ assertTrue(vpRef.contains(new Geopoint(0.0, 0.0)));
+ assertTrue(vpRef.contains(new Geopoint(-1.0, -2.0)));
+ assertTrue(vpRef.contains(new Geopoint(3.0, 4.0)));
+ }
+
+ public static void testSqlWhere() {
+ assertEquals("latitude >= -1.0 and latitude <= 3.0 and longitude >= -2.0 and longitude <= 4.0", vpRef.sqlWhere(null));
+ assertEquals("t.latitude >= -1.0 and t.latitude <= 3.0 and t.longitude >= -2.0 and t.longitude <= 4.0", vpRef.sqlWhere("t"));
+ }
+
+ public static void testEquals() {
+ assertEquals(vpRef, vpRef);
+ assertEquals(vpRef, new Viewport(vpRef.bottomLeft, vpRef.topRight));
+ assertFalse(vpRef.equals(new Viewport(new Geopoint(0.0, 0.0), 1.0, 1.0)));
+ }
+
+ public static void testResize() {
+ assertEquals(vpRef, vpRef.resize(1.0));
+ assertEquals(new Viewport(new Geopoint(-3.0, -5.0), new Geopoint(5.0, 7.0)), vpRef.resize(2.0));
+ assertEquals(new Viewport(new Geopoint(0.0, -0.5), new Geopoint(2.0, 2.5)), vpRef.resize(0.5));
+ }
+
+ public static void testIncludes() {
+ assertTrue(vpRef.includes(vpRef));
+ assertTrue(vpRef.includes(vpRef.resize(0.5)));
+ assertFalse(vpRef.includes(vpRef.resize(2.0)));
+ }
+
+ public static void testExpands() {
+ assertEquals(vpRef, vpRef.expand(new Geopoint(0, 0)));
+ final Viewport vp1 = vpRef.expand(new Geopoint(-4.0, 0.0));
+ assertEquals(new Geopoint(-4.0, -2.0), vp1.bottomLeft);
+ assertEquals(new Geopoint(3.0, 4.0), vp1.topRight);
+ final Viewport vp2 = vpRef.expand(new Geopoint(-10.0, 10.0));
+ assertEquals(new Geopoint(-10.0, -2.0), vp2.bottomLeft);
+ assertEquals(new Geopoint(3.0, 10.0), vp2.topRight);
+ }
+
+ public static void testContaining() {
+ assertNull(Viewport.containing(Collections.singleton((ICoordinates) null)));
+ final Set<Geopoint> points = new HashSet<Geopoint>();
+ points.add(vpRef.bottomLeft);
+ assertEquals(new Viewport(vpRef.bottomLeft, vpRef.bottomLeft), Viewport.containing(points));
+ points.add(vpRef.topRight);
+ assertEquals(vpRef, Viewport.containing(points));
+ points.add(vpRef.center);
+ assertEquals(vpRef, Viewport.containing(points));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/network/ParametersTest.java b/tests/src/cgeo/geocaching/network/ParametersTest.java
new file mode 100644
index 0000000..4c56f05
--- /dev/null
+++ b/tests/src/cgeo/geocaching/network/ParametersTest.java
@@ -0,0 +1,53 @@
+package cgeo.geocaching.network;
+
+import cgeo.geocaching.network.Parameters;
+
+import android.test.AndroidTestCase;
+
+import java.security.InvalidParameterException;
+
+import junit.framework.Assert;
+
+public class ParametersTest extends AndroidTestCase {
+
+ public static void testException() {
+ try {
+ final Parameters params = new Parameters("aaa", "AAA", "bbb");
+ params.clear(); // this will never be invoked, but suppresses warnings about unused objects
+ Assert.fail("Exception not raised");
+ } catch (InvalidParameterException e) {
+ // Ok
+ }
+ try {
+ final Parameters params = new Parameters("aaa", "AAA");
+ params.put("bbb", "BBB", "ccc");
+ Assert.fail("Exception not raised");
+ } catch (InvalidParameterException e) {
+ // Ok
+ }
+ }
+
+ public static void testMultipleValues() {
+ final Parameters params = new Parameters("aaa", "AAA", "bbb", "BBB");
+ params.put("ccc", "CCC", "ddd", "DDD");
+ Assert.assertEquals("aaa=AAA&bbb=BBB&ccc=CCC&ddd=DDD", params.toString());
+ }
+
+ public static void testSort() {
+ final Parameters params = new Parameters();
+ params.put("aaa", "AAA");
+ params.put("ccc", "CCC");
+ params.put("bbb", "BBB");
+ Assert.assertEquals("aaa=AAA&ccc=CCC&bbb=BBB", params.toString());
+ params.sort();
+ Assert.assertEquals("aaa=AAA&bbb=BBB&ccc=CCC", params.toString());
+ }
+
+ public static void testToString() {
+ final Parameters params = new Parameters();
+ params.put("name", "foo&bar");
+ params.put("type", "moving");
+ Assert.assertEquals("name=foo%26bar&type=moving", params.toString());
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
index 906b414..e07a518 100644
--- a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
+++ b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
@@ -16,16 +16,23 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument
}
protected String getFileContent(int resourceId) {
- InputStream ins = getInstrumentation().getContext().getResources().openRawResource(resourceId);
- return new Scanner(ins).useDelimiter("\\A").next();
+ final InputStream ins = getResourceStream(resourceId);
+ final String result = new Scanner(ins).useDelimiter("\\A").next();
+ try {
+ ins.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return result;
}
protected void copyResourceToFile(int resourceId, File file) throws IOException {
final InputStream is = getResourceStream(resourceId);
final FileOutputStream os = new FileOutputStream(file);
-
+
try {
- byte[] buffer = new byte[4096];
+ final byte[] buffer = new byte[4096];
int byteCount;
while ((byteCount = is.read(buffer)) >= 0) {
os.write(buffer, 0, byteCount);
diff --git a/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java b/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java
index 0e2619d..3075d0e 100644
--- a/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java
+++ b/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java
@@ -68,12 +68,7 @@ public class RegExPerformanceTest extends TestCase {
public final static Pattern PATTERN_DESCRIPTION = Pattern.compile("<span id=\"ctl00_ContentBody_LongDescription\">(.*?)</span>[^<]*</div>[^<]*<p>[^<]*</p>[^<]*<p>[^<]*<strong>\\W*Additional Hints</strong>");
- public final static List<MockedCache> MOCKED_CACHES = new ArrayList<MockedCache>();
- static {
- MOCKED_CACHES.add(new GC2CJPF());
- MOCKED_CACHES.add(new GC1ZXX2());
- MOCKED_CACHES.add(new GC2JVEH());
- }
+ public final static MockedCache[] MOCKED_CACHES = { new GC2CJPF(), new GC1ZXX2(), new GC2JVEH() };
public static void testRegEx() {
List<String> output = doTheTests(10);
@@ -115,7 +110,7 @@ public class RegExPerformanceTest extends TestCase {
diff2 = parse(page, p2, iterations);
output.add("Time pattern 2:\t" + diff2 + " ms");
}
- Float reduction = new Float((float) diff2 * 100 / diff1);
+ float reduction = (float) diff2 * 100 / diff1;
output.add("New runtime:\t" + String.format("%.1f", reduction) + "%\n");
}
diff --git a/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java b/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java
index b920772..3867082 100644
--- a/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java
+++ b/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java
@@ -1,9 +1,9 @@
package cgeo.geocaching.test;
-import cgeo.geocaching.Settings;
+
+import cgeo.geocaching.utils.Log;
import android.test.AndroidTestCase;
-import android.util.Log;
import java.util.List;
@@ -20,7 +20,7 @@ public class RegExRealPerformanceTest extends AndroidTestCase {
List<String> output = RegExPerformanceTest.doTheTests(10);
for (String s : output) {
- Log.d(Settings.tag, s);
+ Log.d(s);
}
}
diff --git a/tests/src/cgeo/geocaching/test/WhitespaceTest.java b/tests/src/cgeo/geocaching/test/WhitespaceTest.java
index d2d21dc..a78f2fa 100644
--- a/tests/src/cgeo/geocaching/test/WhitespaceTest.java
+++ b/tests/src/cgeo/geocaching/test/WhitespaceTest.java
@@ -1,17 +1,11 @@
package cgeo.geocaching.test;
-import cgeo.geocaching.Settings;
import cgeo.geocaching.utils.BaseUtils;
+import cgeo.geocaching.utils.Log;
import org.apache.commons.lang3.StringUtils;
-import android.test.AndroidTestCase;
-import android.util.Log;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -20,25 +14,15 @@ import java.util.regex.Pattern;
* It does not test semantical correctness.
*
*/
-public class WhitespaceTest extends AndroidTestCase {
+public class WhitespaceTest extends AbstractResourceInstrumentationTestCase {
private final static int EXPECTED_SIZE = 122907;
private String data;
@Override
protected void setUp() throws Exception {
- final StringBuilder buffer = new StringBuilder(4096);
- final InputStream is = this.getClass().getResourceAsStream("/cgeo/geocaching/test/mock/GC2CJPF.html");
- final BufferedReader br = new BufferedReader(new InputStreamReader(is), 4096);
-
- String line = null;
-
- while ((line = br.readLine()) != null) {
- buffer.append(line).append('\n');
- }
- data = buffer.toString();
-
- br.close();
+ super.setUp();
+ data = getFileContent(R.raw.gc2cjpf_html);
}
/**
@@ -79,7 +63,7 @@ public class WhitespaceTest extends AndroidTestCase {
String result = matcher.replaceAll(" ").trim();
final long end = System.currentTimeMillis();
assertEquals(EXPECTED_SIZE - 1, result.length());
- Log.d(Settings.tag, (end - start) + " ms regex");
+ Log.d((end - start) + " ms regex");
}
public void testReplaceAll() {
@@ -87,7 +71,7 @@ public class WhitespaceTest extends AndroidTestCase {
String result = data.replaceAll("\\s+", " ");
final long end = System.currentTimeMillis();
assertEquals(EXPECTED_SIZE + 1, result.length());
- Log.d(Settings.tag, (end - start) + " ms replaceAll");
+ Log.d((end - start) + " ms replaceAll");
}
public void testActualImplementation() {
@@ -96,7 +80,7 @@ public class WhitespaceTest extends AndroidTestCase {
result = BaseUtils.replaceWhitespace(data);
final long end = System.currentTimeMillis();
assertEquals(EXPECTED_SIZE, result.length());
- Log.d(Settings.tag, (end - start) + " ms actual implementation");
+ Log.d((end - start) + " ms actual implementation");
}
public void testManually() {
@@ -105,7 +89,7 @@ public class WhitespaceTest extends AndroidTestCase {
result = replaceWhitespaceManually(data);
final long end = System.currentTimeMillis();
assertEquals(EXPECTED_SIZE, result.length());
- Log.d(Settings.tag, (end - start) + " ms manually");
+ Log.d((end - start) + " ms manually");
}
public void testStringUtils() {
@@ -114,6 +98,6 @@ public class WhitespaceTest extends AndroidTestCase {
result = replaceWhitespaceStringUtils(data);
final long end = System.currentTimeMillis();
assertEquals(EXPECTED_SIZE - 1, result.length());
- Log.d(Settings.tag, (end - start) + " ms StringUtils");
+ Log.d((end - start) + " ms StringUtils");
}
} \ No newline at end of file
diff --git a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java
index bf4d0cf..7376718 100644
--- a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java
+++ b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java
@@ -1,10 +1,10 @@
package cgeo.geocaching.test.mock;
+import cgeo.geocaching.connector.gc.Login;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.network.Login;
import java.text.ParseException;
import java.util.Arrays;
@@ -17,7 +17,7 @@ import java.util.Map;
public class GC1ZXX2 extends MockedCache {
public GC1ZXX2() {
- super(new Geopoint(52373217, 9710800));
+ super(new Geopoint(52.373217, 9.710800));
}
@Override
diff --git a/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java b/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java
index b97d2bc..670fee4 100644
--- a/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java
+++ b/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java
@@ -1,11 +1,11 @@
package cgeo.geocaching.test.mock;
import cgeo.geocaching.Settings;
+import cgeo.geocaching.connector.gc.Login;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.network.Login;
import java.text.ParseException;
import java.util.Arrays;
@@ -18,7 +18,7 @@ import java.util.Map;
public class GC2CJPF extends MockedCache {
public GC2CJPF() {
- super(new Geopoint(52425067, 9664200));
+ super(new Geopoint(52.425067, 9.664200));
}
@Override
diff --git a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
index 43128cf..dd1f9be 100644
--- a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
+++ b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
@@ -2,11 +2,11 @@ package cgeo.geocaching.test.mock;
import cgeo.geocaching.cgImage;
import cgeo.geocaching.cgTrackable;
+import cgeo.geocaching.connector.gc.Login;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.network.Login;
import java.text.ParseException;
import java.util.ArrayList;
@@ -24,7 +24,7 @@ public class GC2JVEH extends MockedCache {
}
public GC2JVEH() {
- super(new Geopoint(52.37225, 9.73537));
+ super(new Geopoint(52.37225, 9.735367));
}
@Override
diff --git a/tests/src/cgeo/geocaching/test/mock/MockedCache.java b/tests/src/cgeo/geocaching/test/mock/MockedCache.java
index 61369ee..21f67e6 100644
--- a/tests/src/cgeo/geocaching/test/mock/MockedCache.java
+++ b/tests/src/cgeo/geocaching/test/mock/MockedCache.java
@@ -5,7 +5,6 @@ import cgeo.geocaching.cgImage;
import cgeo.geocaching.cgTrackable;
import cgeo.geocaching.connector.gc.GCConstants;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.utils.BaseUtils;
import org.apache.commons.lang3.StringUtils;
@@ -60,7 +59,7 @@ public abstract class MockedCache implements ICache {
final BufferedReader br = new BufferedReader(new InputStreamReader(is), 150000);
final StringBuilder buffer = new StringBuilder();
- String line = null;
+ String line;
while ((line = br.readLine()) != null) {
buffer.append(line).append('\n');
@@ -75,16 +74,6 @@ public abstract class MockedCache implements ICache {
}
@Override
- public String getLatitude() {
- return coords.format(GeopointFormatter.Format.LAT_DECMINUTE);
- }
-
- @Override
- public String getLongitude() {
- return coords.format(GeopointFormatter.Format.LON_DECMINUTE);
- }
-
- @Override
public boolean isArchived() {
return false;
}
diff --git a/tests/src/cgeo/geocaching/utils/AbstractLRUTest.java b/tests/src/cgeo/geocaching/utils/AbstractLRUTest.java
new file mode 100644
index 0000000..83a796b
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/AbstractLRUTest.java
@@ -0,0 +1,20 @@
+package cgeo.geocaching.utils;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.test.AndroidTestCase;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+public abstract class AbstractLRUTest extends AndroidTestCase {
+
+ protected static String colToStr(Collection<?> col) {
+ final ArrayList<String> list = new ArrayList<String>(col.size());
+ for (Object o : col) {
+ list.add(o.toString());
+ }
+ return StringUtils.join(list, ", ");
+ }
+
+} \ No newline at end of file
diff --git a/tests/src/cgeo/geocaching/utils/BaseUtilsTest.java b/tests/src/cgeo/geocaching/utils/BaseUtilsTest.java
new file mode 100644
index 0000000..e174d1f
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/BaseUtilsTest.java
@@ -0,0 +1,26 @@
+package cgeo.geocaching.utils;
+
+import cgeo.geocaching.connector.gc.GCConstants;
+import cgeo.geocaching.test.mock.MockedCache;
+
+import android.test.AndroidTestCase;
+
+public class BaseUtilsTest extends AndroidTestCase {
+ public static void testRegEx() {
+ String page = MockedCache.readCachePage("GC2CJPF");
+ assertEquals("blafoo", BaseUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???"));
+ assertTrue(page.contains("id=\"ctl00_hlRenew\"") || "Premium Member".equals(BaseUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???")));
+ int cachesFound = 0;
+ try {
+ cachesFound = Integer.parseInt(BaseUtils.getMatch(page, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", ""));
+ } catch (NumberFormatException e) {
+ fail();
+ }
+ assertTrue(cachesFound >= 491);
+ }
+
+ public static void testReplaceWhitespaces() {
+ assertEquals("foo bar baz ", BaseUtils.replaceWhitespace(" foo\n\tbar \r baz "));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java
new file mode 100644
index 0000000..723b7153
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java
@@ -0,0 +1,85 @@
+package cgeo.geocaching.utils;
+
+import cgeo.geocaching.cgCache;
+
+import java.util.Map;
+
+public class LeastRecentlyUsedMapTest extends AbstractLRUTest {
+
+ public static void testLruMode() {
+ final Map<String, String> map = new LeastRecentlyUsedMap.LruCache<String, String>(4);
+ map.put("one", "1");
+ map.put("two", "2");
+ map.put("three", "3");
+ // keep in cache
+ map.get("one");
+ map.put("four", "4");
+ map.put("five", "5");
+ map.put("six", "6");
+ // keep in cache
+ map.get("one");
+ // re-add
+ map.put("five", "5");
+ map.put("seven", "7");
+
+ assertEquals("six, one, five, seven", colToStr(map.keySet()));
+ }
+
+ public static void testBoundedMode() {
+ final Map<String, String> map = new LeastRecentlyUsedMap.Bounded<String, String>(5);
+ map.put("one", "1");
+ map.put("two", "2");
+ map.put("three", "3");
+ // read does not change anything
+ map.get("one");
+ map.put("four", "4");
+ // re-put should update the order
+ map.put("three", "3");
+ map.put("five", "5");
+ // read does not change anything
+ map.get("one");
+ map.put("six", "6");
+ map.put("seven", "7");
+
+ assertEquals("four, three, five, six, seven", colToStr(map.keySet()));
+ }
+
+ public static void testRemoveEldestEntry() {
+ final LeastRecentlyUsedMap<String, cgCache> cache = new LeastRecentlyUsedMap.LruCache<String, cgCache>(10);
+ final cgCache first = new cgCache();
+ assertNull(cache.put("1", first));
+
+ final cgCache second = new cgCache();
+ assertNull(cache.put("2", second));
+
+ assertEquals(2, cache.size());
+ assertTrue(cache.containsKey("1"));
+ assertTrue(cache.containsValue(first));
+ assertTrue(cache.containsKey("2"));
+ assertTrue(cache.containsValue(second));
+
+ for (int i = 3; i <= 10; i++) {
+ assertNull(cache.put(Integer.toString(i), new cgCache()));
+ }
+
+ assertEquals(10, cache.size());
+ assertTrue(cache.containsKey("1"));
+ assertTrue(cache.containsValue(first));
+ assertTrue(cache.containsKey("2"));
+ assertTrue(cache.containsValue(second));
+
+ assertNotNull(cache.remove("1")); // just replacing the old entry would not work
+ assertNull(cache.put("1", new cgCache()));
+ assertNull(cache.put("11", new cgCache()));
+
+ assertEquals(10, cache.size());
+
+ // first has been overwritten by new value, but key must be in, because it is very new
+ assertTrue(cache.containsKey("1"));
+
+ // second has been overwritten by 11
+ assertFalse(cache.containsKey("2"));
+ assertTrue(cache.containsKey("11"));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java
new file mode 100644
index 0000000..4b4e5f7
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java
@@ -0,0 +1,66 @@
+package cgeo.geocaching.utils;
+
+import cgeo.geocaching.cgCache;
+
+import java.util.Set;
+
+public class LeastRecentlyUsedSetTest extends AbstractLRUTest {
+
+ public static void testLruMode() {
+ final Set<String> set = new LeastRecentlyUsedSet<String>(5);
+ set.add("one");
+ set.add("two");
+ set.add("three");
+ // read does not change anything
+ set.contains("one");
+ set.add("four");
+ // re-put should update the order
+ set.add("three");
+ set.add("five");
+ // read does not change anything
+ set.contains("one");
+ set.add("six");
+ set.add("seven");
+
+ assertEquals("four, three, five, six, seven", colToStr(set));
+ }
+
+ public static void testRemoveEldestEntry() {
+ final LeastRecentlyUsedSet<cgCache> caches = new LeastRecentlyUsedSet<cgCache>(10);
+ final cgCache first = new cgCache();
+ first.setGeocode("1");
+ assertTrue(caches.add(first));
+
+ final cgCache second = new cgCache();
+ second.setGeocode("2");
+ assertTrue(caches.add(second));
+
+ assertEquals(2, caches.size());
+ assertTrue(caches.contains(first));
+ assertTrue(caches.contains(second));
+
+ // adding first cache again does not change set
+ assertFalse(caches.add(first));
+ assertEquals(2, caches.size());
+
+ for (int i = 3; i <= 10; i++) {
+ final cgCache cache = new cgCache();
+ cache.setGeocode(Integer.toString(i));
+ assertTrue(caches.add(cache));
+ }
+
+ assertEquals(10, caches.size());
+ assertTrue(caches.contains(first));
+ assertTrue(caches.contains(second));
+
+ final cgCache c11 = new cgCache();
+ c11.setGeocode("11");
+ assertTrue(caches.add(c11));
+
+ assertEquals(10, caches.size());
+
+ // first was used again, there second is the oldest and has been overwritten by 11
+ assertTrue(caches.contains(first));
+ assertFalse(caches.contains(second));
+ }
+} \ No newline at end of file
diff --git a/tests/src/cgeo/geocaching/utils/MemorySubjectTest.java b/tests/src/cgeo/geocaching/utils/MemorySubjectTest.java
new file mode 100644
index 0000000..30e4f60
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/MemorySubjectTest.java
@@ -0,0 +1,78 @@
+package cgeo.geocaching.utils;
+
+import android.test.AndroidTestCase;
+
+public class MemorySubjectTest extends AndroidTestCase {
+
+ private static class Observer implements IObserver<Integer> {
+ public int times = 0;
+ public Integer value;
+
+ @Override
+ public void update(final Integer data) {
+ value = data;
+ times++;
+ }
+ }
+
+ private Observer observer;
+ private MemorySubject<Integer> memorySubject;
+
+ @Override
+ public void setUp() {
+ observer = new Observer();
+ memorySubject = new MemorySubject<Integer>();
+ }
+
+ public void testInitial() {
+ assertNull(observer.value);
+ assertEquals(0, observer.times);
+ assertNull(memorySubject.getMemory());
+ }
+
+ public void testMemory() {
+ memorySubject.addObserver(observer);
+ memorySubject.notifyObservers(10);
+ assertEquals(Integer.valueOf(10), observer.value);
+ assertEquals(1, observer.times);
+ assertEquals(Integer.valueOf(10), memorySubject.getMemory());
+ memorySubject.notifyObservers(20);
+ assertEquals(Integer.valueOf(20), observer.value);
+ assertEquals(2, observer.times);
+ assertEquals(Integer.valueOf(20), memorySubject.getMemory());
+ }
+
+ public void testAttach() {
+ memorySubject.notifyObservers(10);
+ assertNull(observer.value);
+ assertEquals(0, observer.times);
+ memorySubject.addObserver(observer);
+ assertEquals(Integer.valueOf(10), observer.value);
+ assertEquals(1, observer.times);
+ memorySubject.notifyObservers(20);
+ assertEquals(Integer.valueOf(20), observer.value);
+ assertEquals(2, observer.times);
+ }
+
+ public void testDetach() {
+ memorySubject.addObserver(observer);
+ memorySubject.notifyObservers(10);
+ assertEquals(Integer.valueOf(10), observer.value);
+ assertEquals(1, observer.times);
+ assertEquals(Integer.valueOf(10), memorySubject.getMemory());
+ memorySubject.deleteObserver(observer);
+ memorySubject.notifyObservers(20);
+ assertEquals(Integer.valueOf(10), observer.value);
+ assertEquals(1, observer.times);
+ assertEquals(Integer.valueOf(20), memorySubject.getMemory());
+ }
+
+ public void testMultiple() {
+ final Observer otherObserver = new Observer();
+ memorySubject.addObserver(otherObserver);
+ testDetach();
+ assertEquals(Integer.valueOf(20), otherObserver.value);
+ assertEquals(2, otherObserver.times);
+ }
+
+}