diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/connector/gc')
6 files changed, 156 insertions, 14 deletions
diff --git a/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java new file mode 100644 index 0000000..234ff26 --- /dev/null +++ b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java @@ -0,0 +1,25 @@ +package cgeo.geocaching.connector.gc; + +import cgeo.geocaching.geopoint.Geopoint; + +import junit.framework.TestCase; + +public class AutoZoomTest extends TestCase { + + public static void testZoom1() { + Geopoint bottomLeft = new Geopoint(49.3, 8.3); + Geopoint topRight = new Geopoint(49.4, 8.4); + + int zoom = Tile.calcZoomLat(bottomLeft, topRight); + + assertTrue(Math.abs(new Tile(bottomLeft, zoom).getY() - new Tile(topRight, zoom).getY()) == 1); + assertTrue(Math.abs(new Tile(bottomLeft, zoom + 1).getY() - new Tile(topRight, zoom + 1).getY()) > 1); + + zoom = Tile.calcZoomLon(bottomLeft, topRight); + + assertTrue(new Tile(bottomLeft, zoom).getX() + 1 == new Tile(topRight, zoom).getX()); + assertTrue(new Tile(bottomLeft, zoom + 1).getX() + 1 < new Tile(topRight, zoom + 1).getX()); + + } + +} diff --git a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java index e6a2474..88873a1 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java @@ -1,11 +1,11 @@ package cgeo.geocaching.connector.gc; import cgeo.geocaching.SearchResult; -import cgeo.geocaching.cgBaseTest; import cgeo.geocaching.cgCache; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.test.mock.GC2CJPF; import cgeo.geocaching.test.mock.MockedCache; +import cgeo.test.Compare; import java.util.HashSet; import java.util.Set; @@ -37,7 +37,7 @@ public class GCBaseTest extends TestCase { SearchResult result = GCBase.searchByGeocodes(geocodes); cgCache parsedCache = result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY); - cgBaseTest.testCompareCaches(mockedCache, parsedCache, false); + Compare.assertCompareCaches(mockedCache, parsedCache, false); } } diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java index dfa9a8b..f85a697 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java @@ -4,7 +4,6 @@ import cgeo.geocaching.SearchResult; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Viewport; -import cgeo.geocaching.network.Login; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; public class GCConnectorTest extends AbstractResourceInstrumentationTestCase { @@ -18,7 +17,7 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase { final Viewport viewport = new Viewport(new Geopoint("N 52° 25.369 E 9° 35.499"), new Geopoint("N 52° 25.600 E 9° 36.200")); SearchResult searchResult = ConnectorFactory.searchByViewport(viewport, tokens); assertNotNull(searchResult); - assertTrue(searchResult.getCount() >= 1); + assertFalse(searchResult.isEmpty()); assertTrue(searchResult.getGeocodes().contains("GC211WG")); // Spiel & Sport GC211WG N 52° 25.413 E 009° 36.049 } @@ -32,12 +31,7 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase { } public static void testBaseCodings() { - assertEquals(2045702, GCBase.newidToGCId("CpLB")); - assertEquals("CpLB", GCBase.gcidToNewId(2045702)); assertEquals(2045702, GCBase.gccodeToGCId("GC2MEGA")); - assertEquals("GC2MEGA", GCBase.gcidToGCCode(2045702)); - - assertEquals("GC211WG", GCBase.newidToGeocode("gEaR")); } /** Tile computation with different zoom levels */ diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java index c930ab5..809318a 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java @@ -1,6 +1,5 @@ package cgeo.geocaching.connector.gc; -import cgeo.geocaching.connector.gc.GCConstants; import cgeo.geocaching.test.mock.MockedCache; import cgeo.geocaching.utils.BaseUtils; @@ -31,7 +30,11 @@ public class GCConstantsTest extends AndroidTestCase { } private static void assertCacheCount(final int count, final String html) { - assertEquals(count, Integer.parseInt(BaseUtils.getMatch(html, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", ""))); + try { + assertEquals(count, Integer.parseInt(BaseUtils.getMatch(html, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", ""))); + } catch (NumberFormatException e) { + fail(); + } } public static void testConstants() { diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java new file mode 100644 index 0000000..54f69ce --- /dev/null +++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java @@ -0,0 +1,121 @@ +package cgeo.geocaching.connector.gc; + +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.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.CancellableHandler; +import cgeo.test.Compare; + +import org.apache.commons.lang3.StringUtils; + +import android.test.suitebuilder.annotation.MediumTest; + +import java.util.ArrayList; + +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()); + } + + 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(); + + SearchResult searchResult; + try { + Settings.setGcCustomDate(MockedCache.getDateFormat()); + searchResult = GCParser.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; + } + + /** + * Test {@link cgBase#parseCacheFromText(String, int, CancellableHandler)} with "mocked" data + * + */ + @MediumTest + public static void testParseCacheFromTextWithMockedData() { + String gcCustomDate = Settings.getGcCustomDate(); + try { + 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 = GCParser.parseCacheFromText(mockedCache.getData(), null); + cgCache parsedCache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); + assertTrue(StringUtils.isNotBlank(mockedCache.getMockedDataUser())); + Compare.assertCompareCaches(mockedCache, parsedCache, true); + } + } finally { + Settings.setGcCustomDate(gcCustomDate); + } + } + + public static void testWaypointsFromNote() { + final cgCache cache = createCache(0); + + final Geopoint[] empty = new Geopoint[] {}; + final Geopoint[] one = new Geopoint[] { new Geopoint("N51 21.523", "E7 2.680") }; + assertWaypointsFromNote(cache, empty, " "); + assertWaypointsFromNote(cache, empty, "some random strings 1 with n 2 numbers"); + assertWaypointsFromNote(cache, empty, "Station3 some coords"); + assertWaypointsFromNote(cache, one, "Station3: N51 21.523 / E07 02.680"); + assertWaypointsFromNote(cache, one, "N51 21.523 / E07 02.680"); + assertWaypointsFromNote(cache, empty, "N51 21.523"); + assertWaypointsFromNote(cache, one, " n 51° 21.523 - E07 02.680"); + assertWaypointsFromNote(cache, new Geopoint[] { + new Geopoint("N51 21.523", "E7 2.680"), + new Geopoint("N52 21.523", "E12 2.680") }, + "Station3: N51 21.523 / E07 02.680\r\n Station4: N52 21.523 / E012 02.680"); + assertWaypointsFromNote(cache, empty, "51 21 523 / 07 02 680"); + assertWaypointsFromNote(cache, empty, "N51"); + assertWaypointsFromNote(cache, empty, "N 821 O 321"); // issue 922 + assertWaypointsFromNote(cache, empty, "N 821-211 O 322+11"); + assertWaypointsFromNote(cache, empty, "von 240 meter"); + assertWaypointsFromNote(cache, new Geopoint[] { + new Geopoint("N 51 19.844", "E 7 03.625") }, + "A=7 bis B=12 Quellen\r\nC= 66 , Quersumme von 240 m NN\r\nD= 67 , Quersumme von 223 m NN\r\nParken:\r\nN 51 19.844\r\nE 7 03.625"); + assertWaypointsFromNote(cache, new Geopoint[] { + new Geopoint("N51 21.444", "E07 02.600"), + new Geopoint("N51 21.789", "E07 02.800"), + new Geopoint("N51 21.667", "E07 02.800"), + new Geopoint("N51 21.444", "E07 02.706"), + new Geopoint("N51 21.321", "E07 02.700"), + new Geopoint("N51 21.123", "E07 02.477"), + new Geopoint("N51 21.734", "E07 02.500"), + new Geopoint("N51 21.733", "E07 02.378"), + new Geopoint("N51 21.544", "E07 02.566") }, + "Station3: N51 21.444 / E07 02.600\r\nStation4: N51 21.789 / E07 02.800\r\nStation5: N51 21.667 / E07 02.800\r\nStation6: N51 21.444 / E07 02.706\r\nStation7: N51 21.321 / E07 02.700\r\nStation8: N51 21.123 / E07 02.477\r\nStation9: N51 21.734 / E07 02.500\r\nStation10: N51 21.733 / E07 02.378\r\nFinal: N51 21.544 / E07 02.566"); + } + + private static void assertWaypointsFromNote(final cgCache cache, Geopoint[] expected, String note) { + cache.setPersonalNote(note); + cache.setWaypoints(new ArrayList<cgWaypoint>(), false); + cache.parseWaypointsFromNote(); + assertEquals(expected.length, cache.getWaypoints().size()); + for (int i = 0; i < expected.length; i++) { + assertTrue(expected[i].equals(cache.getWaypoint(i).getCoords())); + } + } + +} 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()); |
