diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/connector/gc')
4 files changed, 51 insertions, 16 deletions
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java index a001f1d..8ac2177 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java @@ -1,11 +1,13 @@ package cgeo.geocaching.connector.gc; import cgeo.geocaching.SearchResult; -import cgeo.geocaching.Settings; import cgeo.geocaching.connector.ConnectorFactory; +import cgeo.geocaching.connector.trackable.TravelBugConnector; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.settings.Settings; +import cgeo.geocaching.settings.TestSettings; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; public class GCConnectorTest extends AbstractResourceInstrumentationTestCase { @@ -16,7 +18,7 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase { final CacheType cacheType = Settings.getCacheType(); try { // set up settings required for test - Settings.setExcludeMine(false); + TestSettings.setExcludeMine(false); Settings.setCacheType(CacheType.ALL); Login.login(); @@ -39,17 +41,23 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase { } } finally { // restore user settings - Settings.setExcludeMine(excludeMine); + TestSettings.setExcludeMine(excludeMine); Settings.setCacheType(cacheType); } } public static void testCanHandle() { assertTrue(GCConnector.getInstance().canHandle("GC2MEGA")); - assertTrue(GCConnector.getInstance().canHandle("TB3F651")); assertFalse(GCConnector.getInstance().canHandle("OXZZZZZ")); } + /** + * functionality moved to {@link TravelBugConnector} + */ + public static void testCanNotHandleTrackablesAnymore() { + assertFalse(GCConnector.getInstance().canHandle("TB3F651")); + } + public static void testBaseCodings() { assertEquals(2045702, GCConstants.gccodeToGCId("GC2MEGA")); } @@ -82,4 +90,3 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase { assertEquals("GC12ABC", GCConnector.getInstance().getGeocodeFromUrl("http://coord.info/GC12ABC")); } } - diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java index 8298ad7..2bec912 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java @@ -1,7 +1,7 @@ package cgeo.geocaching.connector.gc; import cgeo.geocaching.test.mock.MockedCache; -import cgeo.geocaching.utils.BaseUtils; +import cgeo.geocaching.utils.TextUtils; import android.test.AndroidTestCase; import android.text.Html; @@ -10,7 +10,7 @@ public class GCConstantsTest extends AndroidTestCase { // adapt the following after downloading new mock html files public static final String MOCK_LOGIN_NAME = "JoSaMaJa"; - public static final int MOCK_CACHES_FOUND = 419; + public static final int MOCK_CACHES_FOUND = 426; public static void testLocation() { // GC37GFJ @@ -20,7 +20,7 @@ public class GCConstantsTest extends AndroidTestCase { } private static String parseLocation(final String html) { - return BaseUtils.getMatch(html, GCConstants.PATTERN_LOCATION, true, ""); + return TextUtils.getMatch(html, GCConstants.PATTERN_LOCATION, true, ""); } public static void testCacheCount() { @@ -31,7 +31,7 @@ public class GCConstantsTest extends AndroidTestCase { private static void assertCacheCount(final int count, final String html) { try { - assertEquals(count, Integer.parseInt(BaseUtils.getMatch(html, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", ""))); + assertEquals(count, Integer.parseInt(TextUtils.getMatch(html, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", ""))); } catch (NumberFormatException e) { fail(); } @@ -53,12 +53,12 @@ public class GCConstantsTest extends AndroidTestCase { public static void testConstants() { final String session = "userSession = new Groundspeak.Map.UserSession('aKWZ', userOptions:'XPTf', sessionToken:'123pNKwdktYGZL0xd-I7yqA6nm_JE1BDUtM4KcOkifin2TRCMutBd_PZE14Ohpffs2ZgkTnxTSnxYpBigK4hBA2', subscriberType: 3, enablePersonalization: true });"; - assertEquals("aKWZ", BaseUtils.getMatch(session, GCConstants.PATTERN_USERSESSION, "")); - assertTrue(BaseUtils.getMatch(session, GCConstants.PATTERN_SESSIONTOKEN, "").startsWith("123pNK")); + assertEquals("aKWZ", TextUtils.getMatch(session, GCConstants.PATTERN_USERSESSION, "")); + assertTrue(TextUtils.getMatch(session, GCConstants.PATTERN_SESSIONTOKEN, "").startsWith("123pNK")); } public static void testTBWithSpecialChar() { final String page = "<meta name=\"og:site_name\" content=\"Geocaching.com\" property=\"og:site_name\" /><meta name=\"og:type\" content=\"article\" property=\"og:type\" /><meta name=\"fb:app_id\" content=\"100167303362705\" property=\"fb:app_id\" /><meta name=\"og:url\" content=\"http://coord.info/TB4VPZD\" property=\"og:url\" /><meta name=\"og:description\" property=\"og:description\" /><meta name=\"og:image\" content=\"http://www.geocaching.com/images/facebook/wpttypes/24.png\" property=\"og:image\" /><meta name=\"og:title\" content=\"Schlauchen&ravestorm\" property=\"og:title\" /></head>\n"; - assertEquals("Schlauchen&ravestorm", Html.fromHtml(BaseUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_NAME, "")).toString()); + assertEquals("Schlauchen&ravestorm", Html.fromHtml(TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_NAME, "")).toString()); } } diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java index cf1df46..57eb9d0 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java @@ -3,11 +3,14 @@ package cgeo.geocaching.connector.gc; import cgeo.geocaching.Geocache; import cgeo.geocaching.Image; import cgeo.geocaching.SearchResult; -import cgeo.geocaching.Settings; +import cgeo.geocaching.Trackable; import cgeo.geocaching.Waypoint; +import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.StatusCode; +import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.settings.Settings; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; import cgeo.geocaching.test.R; import cgeo.geocaching.test.RegExPerformanceTest; @@ -22,6 +25,7 @@ import android.os.Handler; import android.test.suitebuilder.annotation.MediumTest; import java.util.ArrayList; +import java.util.List; public class GCParserTest extends AbstractResourceInstrumentationTestCase { @@ -93,7 +97,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { } /** - * Test {@link cgBase#parseCacheFromText(String, int, CancellableHandler)} with "mocked" data + * Test {@link GCParser#parseCacheFromText(String, int, CancellableHandler)} with "mocked" data * */ @MediumTest @@ -187,6 +191,22 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { assertEquals(13, cache.getWaypoints().size()); } + public static void testNoteParsingWaypointTypes() { + final Geocache cache = new Geocache(); + cache.setWaypoints(new ArrayList<Waypoint>(), false); + cache.setPersonalNote("\"Parking area at PARKING=N 50° 40.666E 006° 58.222\n" + + "My calculated final coordinates: FINAL=N 50° 40.777E 006° 58.111\n" + + "Get some ice cream at N 50° 40.555E 006° 58.000\""); + + cache.parseWaypointsFromNote(); + final List<Waypoint> waypoints = cache.getWaypoints(); + + assertEquals(3, waypoints.size()); + assertEquals(WaypointType.PARKING, waypoints.get(0).getWaypointType()); + assertEquals(WaypointType.FINAL, waypoints.get(1).getWaypointType()); + assertEquals(WaypointType.WAYPOINT, waypoints.get(2).getWaypointType()); + } + private Geocache parseCache(int resourceId) { final String page = getFileContent(resourceId); final SearchResult result = GCParser.parseCacheFromText(page, null); @@ -195,4 +215,12 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { return result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); } + public void testTrackableNotActivated() { + final String page = getFileContent(R.raw.tb123e_html); + final Trackable trackable = GCParser.parseTrackable(page, "TB123E"); + assertNotNull(trackable); + assertEquals("TB123E", trackable.getGeocode()); + final String expectedDetails = cgeoapplication.getInstance().getString(cgeo.geocaching.R.string.trackable_not_activated); + assertEquals(expectedDetails, trackable.getDetails()); + } } diff --git a/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java b/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java index cd130db..4f13a7a 100644 --- a/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java @@ -7,7 +7,7 @@ import cgeo.geocaching.Trackable; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; import cgeo.geocaching.test.R; -import cgeo.geocaching.utils.BaseUtils; +import cgeo.geocaching.utils.TextUtils; import java.util.List; @@ -96,7 +96,7 @@ public class TrackablesTest extends AbstractResourceInstrumentationTestCase { private Trackable parseTrackable(int trackablePage) { final String pageContent = getFileContent(trackablePage); - return GCParser.parseTrackable(BaseUtils.replaceWhitespace(pageContent), null); + return GCParser.parseTrackable(TextUtils.replaceWhitespace(pageContent), null); } public void testParseMarkMissing() { |
