aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2012-03-10 21:46:32 +0100
committerBananeweizen <bananeweizen@gmx.de>2012-03-10 21:46:32 +0100
commit491fdefaf2ab8adff5c62898fa00f9af2220b214 (patch)
tree9091734e7f8786b8fcc5f1adc3cf23e822c9eae8 /tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java
parentd40313cf48a9956487afd2b591b34d588bb4ae82 (diff)
downloadcgeo-491fdefaf2ab8adff5c62898fa00f9af2220b214.zip
cgeo-491fdefaf2ab8adff5c62898fa00f9af2220b214.tar.gz
cgeo-491fdefaf2ab8adff5c62898fa00f9af2220b214.tar.bz2
fix #1262: icon decoding does not work well
Diffstat (limited to 'tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java')
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java52
1 files changed, 52 insertions, 0 deletions
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;
+ }
+}