aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/cgeo/geocaching/GeocacheTest.java134
-rw-r--r--tests/src/cgeo/geocaching/cgDataTest.java6
-rw-r--r--tests/src/cgeo/geocaching/settings/TestSettings.java2
-rw-r--r--tests/src/cgeo/geocaching/sorting/NameComparatorTest.java25
-rw-r--r--tests/src/cgeo/geocaching/test/RegExPerformanceTest.java4
-rw-r--r--tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java4
6 files changed, 162 insertions, 13 deletions
diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java
index 5431835..91497f1 100644
--- a/tests/src/cgeo/geocaching/GeocacheTest.java
+++ b/tests/src/cgeo/geocaching/GeocacheTest.java
@@ -78,4 +78,138 @@ public class GeocacheTest extends AndroidTestCase {
}
cache.drop(new Handler());
}
+
+ public static void testMergeDownloadedStored() {
+
+ Geocache stored = new Geocache();
+ stored.setGeocode("GC12345");
+ stored.setDetailed(true);
+ stored.setDisabled(true);
+ stored.setType(CacheType.TRADITIONAL);
+ stored.setCoords(new Geopoint(40.0, 8.0));
+ stored.setDescription("Test1");
+
+ Geocache download = new Geocache();
+ download.setGeocode("GC12345");
+ download.setDetailed(true);
+ download.setDisabled(false);
+ download.setType(CacheType.MULTI);
+ download.setCoords(new Geopoint(41.0, 9.0));
+ download.setDescription("Test2");
+
+ download.gatherMissingFrom(stored);
+
+ assertTrue("Detailed not merged correctly", download.isDetailed());
+ assertFalse("Disabled not merged correctly", download.isDisabled());
+ assertEquals("Type not merged correctly", CacheType.MULTI, download.getType());
+ assertEquals("Longitude not merged correctly", 9.0, download.getCoords().getLongitude(), 0.1);
+ assertEquals("Latitude not merged correctly", 41.0, download.getCoords().getLatitude(), 0.1);
+ assertEquals("Description not merged correctly", "Test2", download.getDescription());
+ }
+
+ public static void testMergeLivemapStored() {
+
+ Geocache stored = new Geocache();
+ stored.setGeocode("GC12345");
+ stored.setDetailed(true);
+ stored.setDisabled(true);
+ stored.setType(CacheType.TRADITIONAL);
+ stored.setCoords(new Geopoint(40.0, 8.0));
+
+ Geocache livemap = new Geocache();
+ livemap.setGeocode("GC12345");
+ livemap.setType(CacheType.MULTI);
+ livemap.setCoords(new Geopoint(41.0, 9.0), 12);
+
+ livemap.gatherMissingFrom(stored);
+
+ assertTrue("Detailed not merged correctly", livemap.isDetailed());
+ assertTrue("Disabled not merged correctly", livemap.isDisabled());
+ assertEquals("Type not merged correctly", CacheType.TRADITIONAL, livemap.getType());
+ assertEquals("Longitude not merged correctly", 8.0, livemap.getCoords().getLongitude(), 0.1);
+ assertEquals("Latitude not merged correctly", 40.0, livemap.getCoords().getLatitude(), 0.1);
+ assertEquals("Zoomlevel not merged correctly", stored.getZoomLevel(), livemap.getZoomLevel());
+ }
+
+ public static void testMergeLivemapZoomin() {
+
+ Geocache livemapFirst = new Geocache();
+ livemapFirst.setGeocode("GC12345");
+ livemapFirst.setType(CacheType.TRADITIONAL);
+ livemapFirst.setCoords(new Geopoint(40.0, 8.0), 11);
+
+ Geocache livemapSecond = new Geocache();
+ livemapSecond.setGeocode("GC12345");
+ livemapSecond.setType(CacheType.MULTI);
+ livemapSecond.setCoords(new Geopoint(41.0, 9.0), 12);
+
+ livemapSecond.gatherMissingFrom(livemapFirst);
+
+ assertEquals("Type not merged correctly", CacheType.MULTI, livemapSecond.getType());
+ assertEquals("Longitude not merged correctly", 9.0, livemapSecond.getCoords().getLongitude(), 0.1);
+ assertEquals("Latitude not merged correctly", 41.0, livemapSecond.getCoords().getLatitude(), 0.1);
+ assertEquals("Zoomlevel not merged correctly", 12, livemapSecond.getZoomLevel());
+ }
+
+ public static void testMergeLivemapZoomout() {
+
+ Geocache livemapFirst = new Geocache();
+ livemapFirst.setGeocode("GC12345");
+ livemapFirst.setType(CacheType.TRADITIONAL);
+ livemapFirst.setCoords(new Geopoint(40.0, 8.0), 12);
+
+ Geocache livemapSecond = new Geocache();
+ livemapSecond.setGeocode("GC12345");
+ livemapSecond.setType(CacheType.MULTI);
+ livemapSecond.setCoords(new Geopoint(41.0, 9.0), 11);
+
+ livemapSecond.gatherMissingFrom(livemapFirst);
+
+ assertEquals("Type not merged correctly", CacheType.TRADITIONAL, livemapSecond.getType());
+ assertEquals("Longitude not merged correctly", 8.0, livemapSecond.getCoords().getLongitude(), 0.1);
+ assertEquals("Latitude not merged correctly", 40.0, livemapSecond.getCoords().getLatitude(), 0.1);
+ assertEquals("Zoomlevel not merged correctly", 12, livemapSecond.getZoomLevel());
+ }
+
+ public static void testMergePopupLivemap() {
+
+ Geocache livemap = new Geocache();
+ livemap.setGeocode("GC12345");
+ livemap.setCoords(new Geopoint(40.0, 8.0), 12);
+ livemap.setFound(true);
+
+ Geocache popup = new Geocache();
+ popup.setGeocode("GC12345");
+ popup.setType(CacheType.MULTI);
+
+ popup.gatherMissingFrom(livemap);
+
+ assertEquals("Type not merged correctly", CacheType.MULTI, popup.getType());
+ assertEquals("Longitude not merged correctly", 8.0, popup.getCoords().getLongitude(), 0.1);
+ assertEquals("Latitude not merged correctly", 40.0, popup.getCoords().getLatitude(), 0.1);
+ assertTrue("Found not merged correctly", popup.isFound());
+ assertEquals("Zoomlevel not merged correctly", 12, popup.getZoomLevel());
+ }
+
+ public static void testMergeLivemapBMSearched() {
+
+ Geocache bmsearched = new Geocache();
+ bmsearched.setGeocode("GC12345");
+
+ Geocache livemap = new Geocache();
+ livemap.setGeocode("GC12345");
+ livemap.setCoords(new Geopoint(40.0, 8.0), 12);
+
+ livemap.gatherMissingFrom(bmsearched);
+
+ assertEquals("Longitude not merged correctly", 8.0, livemap.getCoords().getLongitude(), 0.1);
+ assertEquals("Latitude not merged correctly", 40.0, livemap.getCoords().getLatitude(), 0.1);
+ assertEquals("Zoomlevel not merged correctly", 12, livemap.getZoomLevel());
+ }
+
+ public static void testNameForSorting() {
+ Geocache cache = new Geocache();
+ cache.setName("GR8 01-01");
+ assertEquals("GR000008 000001-000001", cache.getNameForSorting());
+ }
}
diff --git a/tests/src/cgeo/geocaching/cgDataTest.java b/tests/src/cgeo/geocaching/cgDataTest.java
index e175603..c82053e 100644
--- a/tests/src/cgeo/geocaching/cgDataTest.java
+++ b/tests/src/cgeo/geocaching/cgDataTest.java
@@ -165,8 +165,7 @@ public class cgDataTest extends CGeoTestCase {
main.setCoords(new Geopoint("N49 44.0 E8 37.0"));
final Geocache inTileLowZoom = new Geocache();
inTileLowZoom.setGeocode("GC12346");
- inTileLowZoom.setCoords(new Geopoint("N49 44.001 E8 37.001"));
- inTileLowZoom.setZoomlevel(Tile.ZOOMLEVEL_MIN_PERSONALIZED - 5);
+ inTileLowZoom.setCoords(new Geopoint("N49 44.001 E8 37.001"), Tile.ZOOMLEVEL_MIN_PERSONALIZED - 5);
final Geocache outTile = new Geocache();
outTile.setGeocode("GC12347");
outTile.setCoords(new Geopoint(tile.getViewport().getLatitudeMin() - 0.1, tile.getViewport().getLongitudeMin() - 0.1));
@@ -175,8 +174,7 @@ public class cgDataTest extends CGeoTestCase {
otherConnector.setCoords(new Geopoint("N49 44.0 E8 37.0"));
final Geocache inTileHighZoom = new Geocache();
inTileHighZoom.setGeocode("GC12348");
- inTileHighZoom.setCoords(new Geopoint("N49 44.001 E8 37.001"));
- inTileHighZoom.setZoomlevel(Tile.ZOOMLEVEL_MIN_PERSONALIZED + 1);
+ inTileHighZoom.setCoords(new Geopoint("N49 44.001 E8 37.001"), Tile.ZOOMLEVEL_MIN_PERSONALIZED + 1);
// put in cache
cgData.saveCache(main, EnumSet.of(SaveFlag.SAVE_CACHE));
diff --git a/tests/src/cgeo/geocaching/settings/TestSettings.java b/tests/src/cgeo/geocaching/settings/TestSettings.java
index 6585ee4..6c31dcc 100644
--- a/tests/src/cgeo/geocaching/settings/TestSettings.java
+++ b/tests/src/cgeo/geocaching/settings/TestSettings.java
@@ -4,8 +4,6 @@ package cgeo.geocaching.settings;
/**
* provide write-access proxy to settings for testing purposes
*
- * @author rschuman
- *
*/
public class TestSettings {
diff --git a/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java b/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java
index 18db4b7..8e020c4 100644
--- a/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java
+++ b/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java
@@ -4,6 +4,9 @@ import cgeo.geocaching.Geocache;
import android.test.AndroidTestCase;
+import java.util.ArrayList;
+import java.util.Collections;
+
public class NameComparatorTest extends AndroidTestCase {
private static class NamedCache extends Geocache {
@@ -26,9 +29,29 @@ public class NameComparatorTest extends AndroidTestCase {
assertSorted(new NamedCache("2"), new NamedCache("11"));
}
+ public void testDuplicateNumericalParts() {
+ assertSortedNames("GR8 01-01", "GR8 01-02", "GR8 01-03", "GR8 01-04", "GR8 01-05", "GR8 01-06", "GR8 01-07", "GR8 01-08", "GR8 01-09");
+ }
+
+ /**
+ * Assert that a given collection of names is already sorted correctly.
+ *
+ * @param names
+ */
+ private void assertSortedNames(String... names) {
+ ArrayList<Geocache> caches = new ArrayList<Geocache>(names.length);
+ for (String name : names) {
+ caches.add(new NamedCache(name));
+ }
+ Collections.sort(caches, comp);
+ for (int i = 0; i < caches.size(); i++) {
+ assertEquals(names[i], caches.get(i).getName());
+ }
+ }
+
public void testNumericalWithSuffix() {
assertSorted(new NamedCache("abc123def"), new NamedCache("abc123xyz"));
- assertEquals("abc000123def456", (new NamedCache("abc123def456")).getNameForSorting());
+ assertEquals("abc000123def000456", (new NamedCache("abc123def456")).getNameForSorting());
}
private void assertSorted(final Geocache cache1, final Geocache cache2) {
diff --git a/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java b/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java
index 03ca18f..7c3b195 100644
--- a/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java
+++ b/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java
@@ -16,10 +16,8 @@ import junit.framework.TestCase;
/**
* Test class to compare the performance of two regular expressions on given data.
- * Can be used to improve the time needed to parse the cache data
+ * Can be used to improve the time needed to parse the cache data.
* Run As "JUnit Test"
- *
- * @author blafoo
*/
public class RegExPerformanceTest extends TestCase {
diff --git a/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java b/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java
index 1793722..fd47e5b 100644
--- a/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java
+++ b/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java
@@ -8,9 +8,7 @@ import java.util.List;
/**
* Test class to compare the performance of two regular expressions on given data.
- * Can be used to improve the time needed to parse the cache data
- *
- * @author blafoo
+ * Can be used to improve the time needed to parse the cache data.
*/
public class RegExRealPerformanceTest extends AndroidTestCase {