diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/src/cgeo/geocaching/GeocacheTest.java | 29 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java | 12 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java | 4 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/test/RegExPerformanceTest.java | 8 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/test/WhitespaceTest.java | 4 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/test/mock/MockedCache.java | 6 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/utils/TextUtilsTest.java (renamed from tests/src/cgeo/geocaching/utils/BaseUtilsTest.java) | 12 |
7 files changed, 52 insertions, 23 deletions
diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java index f3c9a65..affc793 100644 --- a/tests/src/cgeo/geocaching/GeocacheTest.java +++ b/tests/src/cgeo/geocaching/GeocacheTest.java @@ -1,10 +1,13 @@ package cgeo.geocaching; import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.geopoint.Geopoint; import android.test.AndroidTestCase; +import java.util.ArrayList; import java.util.Date; +import java.util.List; public class GeocacheTest extends AndroidTestCase { @@ -47,4 +50,30 @@ public class GeocacheTest extends AndroidTestCase { cache.setGeocode("gc1234"); assertEquals("GC1234", cache.getGeocode()); } + + public static void testUpdateWaypointFromNote() { + assertWaypointsParsed("Test N51 13.888 E007 03.444", 1); + } + + public static void testUpdateWaypointsFromNote() { + assertWaypointsParsed("Test N51 13.888 E007 03.444 Test N51 13.233 E007 03.444 Test N51 09.123 E007 03.444", 3); + } + + private static void assertWaypointsParsed(String note, int expectedWaypoints) { + Geocache cache = new Geocache(); + cache.setGeocode("Test"); + cache.setWaypoints(new ArrayList<Waypoint>(), false); + for (int i = 0; i < 2; i++) { + cache.setPersonalNote(note); + cache.parseWaypointsFromNote(); + final List<Waypoint> waypoints = cache.getWaypoints(); + assertNotNull(waypoints); + assertEquals(expectedWaypoints, waypoints.size()); + final Waypoint waypoint = waypoints.get(0); + assertEquals(new Geopoint("N51 13.888 E007 03.444"), waypoint.getCoords()); + // assertEquals("Test", waypoint.getNote()); + assertEquals(cgeoapplication.getInstance().getString(R.string.cache_personal_note) + " 1", waypoint.getName()); + cache.store(StoredList.TEMPORARY_LIST_ID, null); + } + } } diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java index 4458789..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; @@ -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/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() { diff --git a/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java b/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java index d71f489..03ca18f 100644 --- a/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java +++ b/tests/src/cgeo/geocaching/test/RegExPerformanceTest.java @@ -5,7 +5,7 @@ import cgeo.geocaching.test.mock.GC2CJPF; import cgeo.geocaching.test.mock.GC2JVEH; import cgeo.geocaching.test.mock.GC3XX5J; import cgeo.geocaching.test.mock.MockedCache; -import cgeo.geocaching.utils.BaseUtils; +import cgeo.geocaching.utils.TextUtils; import java.util.ArrayList; import java.util.Arrays; @@ -98,8 +98,8 @@ public class RegExPerformanceTest extends TestCase { for (MockedCache cache : MOCKED_CACHES) { String page = cache.getData(); - String result1 = BaseUtils.getMatch(page, p1, true, ""); - String result2 = BaseUtils.getMatch(page, p2, true, ""); + String result1 = TextUtils.getMatch(page, p1, true, ""); + String result2 = TextUtils.getMatch(page, p2, true, ""); assertEquals(result1, result2); long diff1, diff2; @@ -123,7 +123,7 @@ public class RegExPerformanceTest extends TestCase { private static long parse(String page, Pattern pattern, int iterations) { final long start = System.currentTimeMillis(); for (int j = 0; j < iterations; j++) { - BaseUtils.getMatch(page, pattern, true, ""); + TextUtils.getMatch(page, pattern, true, ""); } return System.currentTimeMillis() - start; diff --git a/tests/src/cgeo/geocaching/test/WhitespaceTest.java b/tests/src/cgeo/geocaching/test/WhitespaceTest.java index 5e792d9..125a0cb 100644 --- a/tests/src/cgeo/geocaching/test/WhitespaceTest.java +++ b/tests/src/cgeo/geocaching/test/WhitespaceTest.java @@ -1,6 +1,6 @@ package cgeo.geocaching.test; -import cgeo.geocaching.utils.BaseUtils; +import cgeo.geocaching.utils.TextUtils; import cgeo.geocaching.utils.Log; import org.apache.commons.lang3.StringUtils; @@ -76,7 +76,7 @@ public class WhitespaceTest extends AbstractResourceInstrumentationTestCase { public void testActualImplementation() { final String result; final long start = System.currentTimeMillis(); - result = BaseUtils.replaceWhitespace(data); + result = TextUtils.replaceWhitespace(data); final long end = System.currentTimeMillis(); assertEquals(EXPECTED_SIZE, result.length()); Log.d((end - start) + " ms actual implementation"); diff --git a/tests/src/cgeo/geocaching/test/mock/MockedCache.java b/tests/src/cgeo/geocaching/test/mock/MockedCache.java index 7ad566a..0085a18 100644 --- a/tests/src/cgeo/geocaching/test/mock/MockedCache.java +++ b/tests/src/cgeo/geocaching/test/mock/MockedCache.java @@ -5,7 +5,7 @@ import cgeo.geocaching.Image; import cgeo.geocaching.Trackable; import cgeo.geocaching.connector.gc.GCConstants; import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.utils.BaseUtils; +import cgeo.geocaching.utils.TextUtils; import org.apache.commons.lang3.StringUtils; import org.mapsforge.core.IOUtils; @@ -28,7 +28,7 @@ public abstract class MockedCache implements ICache { this.coords = coords; this.data = MockedCache.readCachePage(getGeocode()); // for mocked caches the user logged in is the user who saved the html file(s) - this.mockedDataUser = BaseUtils.getMatch(data, GCConstants.PATTERN_LOGIN_NAME, true, ""); + this.mockedDataUser = TextUtils.getMatch(data, GCConstants.PATTERN_LOGIN_NAME, true, ""); } public String getMockedDataUser() { @@ -68,7 +68,7 @@ public abstract class MockedCache implements ICache { buffer.append(line).append('\n'); } - return BaseUtils.replaceWhitespace(buffer.toString()); + return TextUtils.replaceWhitespace(buffer.toString()); } catch (IOException e) { Assert.fail(e.getMessage()); } finally { diff --git a/tests/src/cgeo/geocaching/utils/BaseUtilsTest.java b/tests/src/cgeo/geocaching/utils/TextUtilsTest.java index 78a833c..2093383 100644 --- a/tests/src/cgeo/geocaching/utils/BaseUtilsTest.java +++ b/tests/src/cgeo/geocaching/utils/TextUtilsTest.java @@ -8,20 +8,20 @@ import android.test.AndroidTestCase; import java.util.regex.Pattern; -public class BaseUtilsTest extends AndroidTestCase { +public class TextUtilsTest extends AndroidTestCase { public static void testRegEx() { final String page = MockedCache.readCachePage("GC2CJPF"); - assertEquals(GCConstantsTest.MOCK_LOGIN_NAME, BaseUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???")); - assertTrue(page.contains("id=\"ctl00_hlRenew\"") || GCConstants.MEMBER_STATUS_PM.equals(BaseUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???"))); + assertEquals(GCConstantsTest.MOCK_LOGIN_NAME, TextUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???")); + assertTrue(page.contains("id=\"ctl00_hlRenew\"") || GCConstants.MEMBER_STATUS_PM.equals(TextUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???"))); } public static void testReplaceWhitespaces() { - assertEquals("foo bar baz ", BaseUtils.replaceWhitespace(" foo\n\tbar \r baz ")); + assertEquals("foo bar baz ", TextUtils.replaceWhitespace(" foo\n\tbar \r baz ")); } public static void testControlCharactersCleanup() { final Pattern patternAll = Pattern.compile("(.*)", Pattern.DOTALL); - assertEquals("some control characters removed", BaseUtils.getMatch("some" + "\u001C" + "control" + (char) 0x1D + "characters removed", patternAll, "")); - assertEquals("newline also removed", BaseUtils.getMatch("newline\nalso\nremoved", patternAll, "")); + assertEquals("some control characters removed", TextUtils.getMatch("some" + "\u001C" + "control" + (char) 0x1D + "characters removed", patternAll, "")); + assertEquals("newline also removed", TextUtils.getMatch("newline\nalso\nremoved", patternAll, "")); } } |
