aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java16
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java89
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java52
3 files changed, 76 insertions, 81 deletions
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java
index 5f07f60..32ab1f2 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java
@@ -1,14 +1,18 @@
package cgeo.geocaching.connector.gc;
-import java.util.Arrays;
-
import junit.framework.TestCase;
public class GCBaseTest extends TestCase {
public static void testSplitJSONKey() {
- assertTrue(Arrays.equals(new int[] { 1, 2 }, GCBase.splitJSONKey("(1, 2)")));
- assertTrue(Arrays.equals(new int[] { 12, 34 }, GCBase.splitJSONKey("(12, 34)")));
- assertTrue(Arrays.equals(new int[] { 1234, 56 }, GCBase.splitJSONKey("(1234,56)")));
- assertTrue(Arrays.equals(new int[] { 1234, 567 }, GCBase.splitJSONKey("(1234, 567)")));
+ assertKey("(1, 2)", 1, 2);
+ assertKey("(12, 34)", 12, 34);
+ assertKey("(1234,56)", 1234, 56);
+ assertKey("(1234, 567)", 1234, 567);
+ }
+
+ private static void assertKey(String key, int x, int y) {
+ UTFGridPosition pos = UTFGridPosition.fromString(key);
+ assertEquals(x, pos.getX());
+ assertEquals(y, pos.getY());
}
}
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
index 3696568..dfa9a8b 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
@@ -1,19 +1,11 @@
package cgeo.geocaching.connector.gc;
import cgeo.geocaching.SearchResult;
-import cgeo.geocaching.Settings;
-import cgeo.geocaching.cgCache;
import cgeo.geocaching.connector.ConnectorFactory;
-import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.network.Login;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
-import cgeo.geocaching.test.R;
-
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.util.Log;
public class GCConnectorTest extends AbstractResourceInstrumentationTestCase {
@@ -50,78 +42,25 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase {
/** Tile computation with different zoom levels */
public static void testTile() {
- {
- // http://coord.info/GC2CT8K = N 52° 30.462 E 013° 27.906
- Tile tile = new Tile(new Geopoint(52.5077, 13.4651), 14);
- assertEquals(8804, tile.getX());
- assertEquals(5374, tile.getY());
- }
- {
- // (8633, 5381); N 52° 24,516 E 009° 42,592
- Tile tile = new Tile(new Geopoint("N 52° 24,516 E 009° 42,592"), 14);
- assertEquals(8633, tile.getX());
- assertEquals(5381, tile.getY());
- }
- {
- // Hannover, GC22VTB UKM Memorial Tour
- Tile tile = new Tile(new Geopoint("N 52° 22.177 E 009° 45.385"), 12);
- assertEquals(2159, tile.getX());
- assertEquals(1346, tile.getY());
- }
- {
- // Seatle, GCK25B Groundspeak Headquarters
- Tile tile = new Tile(new Geopoint("N 47° 38.000 W 122° 20.000"), 15);
- assertEquals(5248, tile.getX());
- assertEquals(11440, tile.getY());
- }
- {
- // Sydney, GCXT2R Victoria Cross
- Tile tile = new Tile(new Geopoint("S 33° 50.326 E 151° 12.426"), 13);
- assertEquals(7536, tile.getX());
- assertEquals(4915, tile.getY());
- }
- }
+ // http://coord.info/GC2CT8K = N 52° 30.462 E 013° 27.906
+ assertTileAt(8804, 5374, new Tile(new Geopoint(52.5077, 13.4651), 14));
- public void testparseMapPNG() {
- // createApplication();
- // cgBase.initialize(getApplication());
+ // (8633, 5381); N 52° 24,516 E 009° 42,592
+ assertTileAt(8633, 5381, new Tile(new Geopoint("N 52° 24,516 E 009° 42,592"), 14));
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inScaled = false;
- Bitmap bitmap = BitmapFactory.decodeStream(getInstrumentation().getContext().getResources().openRawResource(R.raw.tile14));
- assert bitmap.getWidth() == Tile.TILE_SIZE : "Wrong size";
+ // Hannover, GC22VTB UKM Memorial Tour
+ assertTileAt(2159, 1346, new Tile(new Geopoint("N 52° 22.177 E 009° 45.385"), 12));
- Log.d(Settings.tag, "Bitmap=" + bitmap.getWidth() + "x" + bitmap.getHeight());
+ // Seattle, GCK25B Groundspeak Headquarters
+ assertTileAt(5248, 11440, new Tile(new Geopoint("N 47° 38.000 W 122° 20.000"), 15));
- cgCache cache = new cgCache();
-
- // Tradi
- GCBase.parseMapPNG14(cache, bitmap, new UTFGridPosition(97 / 4, 136 / 4));
- assertEquals(CacheType.TRADITIONAL, cache.getType());
- // Mystery
- GCBase.parseMapPNG14(cache, bitmap, new UTFGridPosition(226 / 4, 104 / 4));
- assertEquals(CacheType.MYSTERY, cache.getType());
- // Multi
- GCBase.parseMapPNG14(cache, bitmap, new UTFGridPosition(54 / 4, 97 / 4));
- assertEquals(CacheType.MULTI, cache.getType());
- // Found
- GCBase.parseMapPNG14(cache, bitmap, new UTFGridPosition(119 / 4, 108 / 4));
- assertTrue(cache.isFound());
- cache.setFound(false); // reset
-
- bitmap = BitmapFactory.decodeStream(getInstrumentation().getContext().getResources().openRawResource(R.raw.tile13));
-
- // Tradi
- GCBase.parseMapPNG13(cache, bitmap, new UTFGridPosition(146 / 4, 225 / 4));
- assertEquals(CacheType.TRADITIONAL, cache.getType());
- // Mystery
- GCBase.parseMapPNG13(cache, bitmap, new UTFGridPosition(181 / 4, 116 / 4));
- assertEquals(CacheType.MYSTERY, cache.getType());
- // Multi
- GCBase.parseMapPNG13(cache, bitmap, new UTFGridPosition(118 / 4, 230 / 4));
- assertEquals(CacheType.MULTI, cache.getType());
- // Found - not available in parseMapPNG13
+ // Sydney, GCXT2R Victoria Cross
+ assertTileAt(7536, 4915, new Tile(new Geopoint("S 33° 50.326 E 151° 12.426"), 13));
}
+ private static void assertTileAt(int x, int y, final Tile tile) {
+ assertEquals(x, tile.getX());
+ assertEquals(y, tile.getY());
+ }
}
diff --git a/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java b/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java
new file mode 100644
index 0000000..db6dc44
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java
@@ -0,0 +1,52 @@
+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 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());
+
+ assertEquals(CacheType.TRADITIONAL, parse14(bitmap, 97 / 4, 136 / 4).getType());
+ assertEquals(CacheType.MYSTERY, parse14(bitmap, 226 / 4, 104 / 4).getType());
+ assertEquals(CacheType.MULTI, parse14(bitmap, 54 / 4, 97 / 4).getType());
+ assertTrue(parse14(bitmap, 119 / 4, 108 / 4).isFound());
+ }
+
+ private Bitmap getBitmap(int resourceId) {
+ final BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inScaled = false;
+ final Bitmap bitmap = BitmapFactory.decodeStream(getInstrumentation().getContext().getResources().openRawResource(resourceId));
+ assert bitmap.getWidth() == Tile.TILE_SIZE : "Wrong size";
+ return bitmap;
+ }
+
+ private static cgCache parse14(Bitmap bitmap, int x, int y) {
+ final cgCache cache = new cgCache();
+ IconDecoder.parseMapPNG14(cache, bitmap, new UTFGridPosition(x, y));
+ return cache;
+ }
+
+ public void testParseMap13() {
+ final Bitmap bitmap = getBitmap(R.raw.tile13);
+
+ assertEquals(CacheType.TRADITIONAL, parse13(bitmap, 146 / 4, 225 / 4).getType());
+ assertEquals(CacheType.MYSTERY, parse13(bitmap, 181 / 4, 116 / 4).getType());
+ assertEquals(CacheType.MULTI, parse13(bitmap, 118 / 4, 230 / 4).getType());
+ }
+
+ private static cgCache parse13(Bitmap bitmap, int x, int y) {
+ final cgCache cache = new cgCache();
+ IconDecoder.parseMapPNG13(cache, bitmap, new UTFGridPosition(x, y));
+ return cache;
+ }
+}