aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.classpath1
-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/SettingsTest.java9
-rw-r--r--tests/src/cgeo/geocaching/TrackablesTest.java27
-rw-r--r--tests/src/cgeo/geocaching/cgDataTest.java7
-rw-r--r--tests/src/cgeo/geocaching/cgeoApplicationTest.java40
-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/GCParserTest.java (renamed from tests/src/cgeo/geocaching/cgBaseTest.java)133
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java5
-rw-r--r--tests/src/cgeo/geocaching/enumerations/CacheAttributeTest.java13
-rw-r--r--tests/src/cgeo/geocaching/files/GPXImporterTest.java4
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java12
-rw-r--r--tests/src/cgeo/geocaching/files/LocParserTest.java4
-rw-r--r--tests/src/cgeo/geocaching/filter/AbstractFilterTestCase.java20
-rw-r--r--tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java23
-rw-r--r--tests/src/cgeo/geocaching/filter/SizeFilterTest.java48
-rw-r--r--tests/src/cgeo/geocaching/filter/StateArchivedFilterTest.java26
-rw-r--r--tests/src/cgeo/geocaching/filter/StateDisabledFilterTest.java25
-rw-r--r--tests/src/cgeo/geocaching/filter/StateFoundFilterTest.java25
-rw-r--r--tests/src/cgeo/geocaching/filter/StatePremiumFilterTest.java25
-rw-r--r--tests/src/cgeo/geocaching/filter/TerrainFilterTest.java23
-rw-r--r--tests/src/cgeo/geocaching/filter/TypeFilterTest.java51
-rw-r--r--tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java4
-rw-r--r--tests/src/cgeo/geocaching/geopoint/GeopointTest.java27
-rw-r--r--tests/src/cgeo/geocaching/geopoint/ViewportTest.java100
-rw-r--r--tests/src/cgeo/geocaching/test/RegExPerformanceTest.java7
-rw-r--r--tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java6
-rw-r--r--tests/src/cgeo/geocaching/test/WhitespaceTest.java14
-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.java11
-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/test/Compare.java57
41 files changed, 809 insertions, 211 deletions
diff --git a/tests/.classpath b/tests/.classpath
index f351d98..78ba67f 100644
--- a/tests/.classpath
+++ b/tests/.classpath
@@ -4,5 +4,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry combineaccessrules="false" kind="src" path="/cgeo"/>
+ <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
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/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..a1c6b1b 100644
--- a/tests/src/cgeo/geocaching/cgDataTest.java
+++ b/tests/src/cgeo/geocaching/cgDataTest.java
@@ -29,9 +29,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 {
diff --git a/tests/src/cgeo/geocaching/cgeoApplicationTest.java b/tests/src/cgeo/geocaching/cgeoApplicationTest.java
index c4ab0e3..4a1fcb0 100644
--- a/tests/src/cgeo/geocaching/cgeoApplicationTest.java
+++ b/tests/src/cgeo/geocaching/cgeoApplicationTest.java
@@ -2,26 +2,28 @@ package cgeo.geocaching;
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;
@@ -44,7 +46,6 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
// init environment
createApplication();
- cgBase.initialize(getApplication());
}
/**
@@ -64,7 +65,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 +74,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,7 +101,7 @@ 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.getError() == null) {
assertEquals(1, search.getGeocodes().size());
@@ -116,7 +117,7 @@ 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(StatusCode.UNPUBLISHED_CACHE, search.getError());
}
@@ -135,7 +136,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 +149,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 +175,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 +192,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 +203,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,7 +214,7 @@ 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.getTotal());
assertTrue(search.getGeocodes().contains("GCP0A9"));
@@ -242,18 +243,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.getCoords());
+
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 {
@@ -280,6 +283,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
// non premium cache
MockedCache cache = new GC2CJPF();
deleteCacheFromDBAndLogout(cache.getGeocode());
+ GCBase.removeFromTileCache(cache.getCoords());
Viewport viewport = new Viewport(cache.getCoords(), 0.003, 0.003);
SearchResult search = ConnectorFactory.searchByViewport(viewport, tokens);
@@ -288,8 +292,8 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
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());
@@ -322,7 +326,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
mockedCache.setMockedDataUser(Settings.getUsername());
cgCache parsedCache = cgeoApplicationTest.testSearchByGeocode(mockedCache.getGeocode());
if (null != parsedCache) {
- cgBaseTest.testCompareCaches(mockedCache, parsedCache, true);
+ Compare.assertCompareCaches(mockedCache, parsedCache, true);
}
}
}
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/cgBaseTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
index b6ad561..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,73 +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 = 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 "));
- }
-
- 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.getPersonalNote(), actual.getPersonalNote());
- 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;
}
/**
@@ -98,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);
@@ -109,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") };
@@ -151,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()));
+ assertTrue(expected[i].equals(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);
- }
-
- 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/enumerations/CacheAttributeTest.java b/tests/src/cgeo/geocaching/enumerations/CacheAttributeTest.java
new file mode 100644
index 0000000..a15bd17
--- /dev/null
+++ b/tests/src/cgeo/geocaching/enumerations/CacheAttributeTest.java
@@ -0,0 +1,13 @@
+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));
+ }
+ }
+}
diff --git a/tests/src/cgeo/geocaching/files/GPXImporterTest.java b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
index b8a3354..dc1fc71 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();
}
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 3754af1..634c551 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.cgCache;
-import cgeo.geocaching.cgLog;
+import cgeo.geocaching.LogEntry;
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()));
+ assertTrue(new Geopoint(48.859683, 9.1874).equals(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()));
+ assertTrue(new Geopoint(48.85968, 9.18740).equals(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);
diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java
index 64ac7ad..ede0e81 100644
--- a/tests/src/cgeo/geocaching/files/LocParserTest.java
+++ b/tests/src/cgeo/geocaching/files/LocParserTest.java
@@ -37,7 +37,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()));
+ assertTrue(new Geopoint(48.85968, 9.18740).equals(cache.getCoords()));
}
public void testGCLoc() throws IOException, ParserException {
@@ -47,7 +47,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()));
+ assertTrue(new Geopoint(48.859683, 9.1874).equals(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/AbstractFilterTestCase.java b/tests/src/cgeo/geocaching/filter/AbstractFilterTestCase.java
new file mode 100644
index 0000000..f16d326
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/AbstractFilterTestCase.java
@@ -0,0 +1,20 @@
+package cgeo.geocaching.filter;
+
+import cgeo.geocaching.cgeoapplication;
+
+import android.test.ApplicationTestCase;
+
+public abstract class AbstractFilterTestCase extends ApplicationTestCase<cgeoapplication> {
+
+ public AbstractFilterTestCase() {
+ super(cgeoapplication.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // init environment
+ createApplication();
+ }
+}
diff --git a/tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java b/tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java
new file mode 100644
index 0000000..cf2abe2
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java
@@ -0,0 +1,23 @@
+package cgeo.geocaching.filter;
+
+import cgeo.geocaching.cgCache;
+
+public class DifficultyFilterTest extends AbstractFilterTestCase {
+
+ 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..65fd8d8
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/SizeFilterTest.java
@@ -0,0 +1,48 @@
+package cgeo.geocaching.filter;
+
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.enumerations.CacheSize;
+
+import java.util.ArrayList;
+
+public class SizeFilterTest extends AbstractFilterTestCase {
+
+ 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..660a596
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/StateArchivedFilterTest.java
@@ -0,0 +1,26 @@
+package cgeo.geocaching.filter;
+
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.filter.StateFilter.StateArchivedFilter;
+
+public class StateArchivedFilterTest extends AbstractFilterTestCase {
+
+ 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..7e8a060
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/StateDisabledFilterTest.java
@@ -0,0 +1,25 @@
+package cgeo.geocaching.filter;
+
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.filter.StateFilter.StateDisabledFilter;
+
+public class StateDisabledFilterTest extends AbstractFilterTestCase {
+
+ 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..3f0ffcc
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/StateFoundFilterTest.java
@@ -0,0 +1,25 @@
+package cgeo.geocaching.filter;
+
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.filter.StateFilter.StateFoundFilter;
+
+public class StateFoundFilterTest extends AbstractFilterTestCase {
+
+ 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..5968424
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/StatePremiumFilterTest.java
@@ -0,0 +1,25 @@
+package cgeo.geocaching.filter;
+
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.filter.StateFilter.StatePremiumFilter;
+
+public class StatePremiumFilterTest extends AbstractFilterTestCase {
+
+ 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..00c78b1
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/TerrainFilterTest.java
@@ -0,0 +1,23 @@
+package cgeo.geocaching.filter;
+
+import cgeo.geocaching.cgCache;
+
+public class TerrainFilterTest extends AbstractFilterTestCase {
+
+ 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..826ba03
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/TypeFilterTest.java
@@ -0,0 +1,51 @@
+package cgeo.geocaching.filter;
+
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.enumerations.CacheType;
+
+import java.util.ArrayList;
+
+public class TypeFilterTest extends AbstractFilterTestCase {
+
+ 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..4e24e5a 100644
--- a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
@@ -57,7 +57,7 @@ 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() {
@@ -77,6 +77,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..7990489 100644
--- a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/GeopointTest.java
@@ -4,6 +4,7 @@ import cgeo.geocaching.geopoint.Geopoint.DDD;
import cgeo.geocaching.geopoint.Geopoint.DMM;
import cgeo.geocaching.geopoint.Geopoint.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/ViewportTest.java b/tests/src/cgeo/geocaching/geopoint/ViewportTest.java
new file mode 100644
index 0000000..bd35ae6
--- /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(-1.0, 3.0, -2.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/test/RegExPerformanceTest.java b/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java
index 552c225..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);
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 59367a5..a78f2fa 100644
--- a/tests/src/cgeo/geocaching/test/WhitespaceTest.java
+++ b/tests/src/cgeo/geocaching/test/WhitespaceTest.java
@@ -1,13 +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.util.Log;
-
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -65,7 +63,7 @@ public class WhitespaceTest extends AbstractResourceInstrumentationTestCase {
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() {
@@ -73,7 +71,7 @@ public class WhitespaceTest extends AbstractResourceInstrumentationTestCase {
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() {
@@ -82,7 +80,7 @@ public class WhitespaceTest extends AbstractResourceInstrumentationTestCase {
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() {
@@ -91,7 +89,7 @@ public class WhitespaceTest extends AbstractResourceInstrumentationTestCase {
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() {
@@ -100,6 +98,6 @@ public class WhitespaceTest extends AbstractResourceInstrumentationTestCase {
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 6fdd753..590c86a 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..2c717a4 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;
@@ -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/test/Compare.java b/tests/src/cgeo/test/Compare.java
new file mode 100644
index 0000000..432f4e4
--- /dev/null
+++ b/tests/src/cgeo/test/Compare.java
@@ -0,0 +1,57 @@
+package cgeo.test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import cgeo.geocaching.ICache;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.enumerations.LogType;
+
+public abstract class Compare {
+
+ public static void assertCompareCaches(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.getCoords(), actual.getCoords());
+ 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.getPersonalNote(), actual.getPersonalNote());
+ assertEquals(expected.isFound(), actual.isFound());
+ assertEquals(expected.isFavorite(), actual.isFavorite());
+ assertEquals(expected.isWatchlist(), actual.isWatchlist());
+
+ 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));
+ }
+
+ // 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;
+ assertEquals(expectedSpoilersSize, actualSpoilersSize);
+ }
+ }
+
+}