aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/cgeo/geocaching/connector/gc/GCParserTest.java')
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCParserTest.java80
1 files changed, 64 insertions, 16 deletions
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
index c8cb8fb..4063ed0 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
@@ -1,10 +1,10 @@
package cgeo.geocaching.connector.gc;
+import cgeo.geocaching.Geocache;
+import cgeo.geocaching.Image;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Settings;
-import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgImage;
-import cgeo.geocaching.cgWaypoint;
+import cgeo.geocaching.Waypoint;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.geopoint.Geopoint;
@@ -18,32 +18,61 @@ import cgeo.test.Compare;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import android.os.Handler;
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);
+
+ public void testUnpublishedCacheNotOwner() {
+ final int cache = R.raw.cache_unpublished;
+ assertUnpublished(cache);
+ }
+
+ public void testUnpublishedCacheOwner() {
+ final int cache = R.raw.gc433yc_owner_unpublished;
+ assertUnpublished(cache);
+ }
+
+ private void assertUnpublished(final int cache) {
+ final String page = getFileContent(cache);
SearchResult result = GCParser.parseCacheFromText(page, null);
assertNotNull(result);
assertTrue(result.isEmpty());
assertEquals(StatusCode.UNPUBLISHED_CACHE, result.getError());
}
+ public void testPublishedCacheWithUnpublishedInDescription1() {
+ assertPublishedCache(R.raw.gc430fm_published, "Cache is Unpublished");
+ }
+
+ public void testPublishedCacheWithUnpublishedInDescription2() {
+ assertPublishedCache(R.raw.gc431f2_published, "Needle in a Haystack");
+ }
+
+ private void assertPublishedCache(final int cachePage, final String cacheName) {
+ final String page = getFileContent(cachePage);
+ SearchResult result = GCParser.parseCacheFromText(page, null);
+ assertNotNull(result);
+ assertEquals(1, result.getCount());
+ Geocache cache = result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
+ assertEquals(cacheName, cache.getName());
+ }
+
public void testOwnCache() {
- final cgCache cache = parseCache(R.raw.own_cache);
+ final Geocache cache = parseCache(R.raw.own_cache);
assertNotNull(cache);
assertTrue(CollectionUtils.isNotEmpty(cache.getSpoilers()));
assertEquals(1, cache.getSpoilers().size());
- final cgImage spoiler = cache.getSpoilers().get(0);
+ final Image spoiler = cache.getSpoilers().get(0);
assertEquals("http://img.geocaching.com/cache/large/3f9365c3-f55c-4e55-9992-ee0e5175712c.jpg", spoiler.getUrl());
assertEquals("SPOILER", spoiler.getTitle());
assertNull(spoiler.getDescription());
}
- private static cgCache createCache(int index) {
- final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES[index];
+ private static Geocache createCache(int index) {
+ final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES.get(index);
// to get the same results we have to use the date format used when the mocked data was created
String oldCustomDate = Settings.getGcCustomDate();
@@ -58,7 +87,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
assertNotNull(searchResult);
assertEquals(1, searchResult.getCount());
- final cgCache cache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
+ final Geocache cache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
assertNotNull(cache);
return cache;
}
@@ -75,7 +104,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
// 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);
+ Geocache parsedCache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
assertTrue(StringUtils.isNotBlank(mockedCache.getMockedDataUser()));
Compare.assertCompareCaches(mockedCache, parsedCache, true);
}
@@ -85,7 +114,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
}
public static void testWaypointsFromNote() {
- final cgCache cache = createCache(0);
+ final Geocache cache = createCache(0);
final Geopoint[] empty = new Geopoint[] {};
final Geopoint[] one = new Geopoint[] { new Geopoint("N51 21.523", "E7 2.680") };
@@ -121,9 +150,28 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
"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) {
+ @MediumTest
+ public static void testEditModifiedCoordinates() {
+ Geocache cache = new Geocache();
+ cache.setGeocode("GC2ZN4G");
+ // upload coordinates
+ GCParser.editModifiedCoordinates(cache, new Geopoint("N51 21.544", "E07 02.566"));
+ cache.drop(new Handler());
+ String page = GCParser.requestHtmlPage(cache.getGeocode(), null, "n", "0");
+ Geocache cache2 = GCParser.parseCacheFromText(page, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
+ assertTrue(cache2.hasUserModifiedCoords());
+ assertEquals(new Geopoint("N51 21.544", "E07 02.566"), cache2.getCoords());
+ // delete coordinates
+ GCParser.deleteModifiedCoordinates(cache2);
+ cache2.drop(new Handler());
+ String page2 = GCParser.requestHtmlPage(cache.getGeocode(), null, "n", "0");
+ Geocache cache3 = GCParser.parseCacheFromText(page2, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
+ assertFalse(cache3.hasUserModifiedCoords());
+ }
+
+ private static void assertWaypointsFromNote(final Geocache cache, Geopoint[] expected, String note) {
cache.setPersonalNote(note);
- cache.setWaypoints(new ArrayList<cgWaypoint>(), false);
+ cache.setWaypoints(new ArrayList<Waypoint>(), false);
cache.parseWaypointsFromNote();
assertEquals(expected.length, cache.getWaypoints().size());
for (int i = 0; i < expected.length; i++) {
@@ -132,14 +180,14 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
}
public void testWaypointParsing() {
- cgCache cache = parseCache(R.raw.gc366bq);
+ Geocache cache = parseCache(R.raw.gc366bq);
assertEquals(13, cache.getWaypoints().size());
//make sure that waypoints are not duplicated
cache = parseCache(R.raw.gc366bq);
assertEquals(13, cache.getWaypoints().size());
}
- private cgCache parseCache(int resourceId) {
+ private Geocache parseCache(int resourceId) {
final String page = getFileContent(resourceId);
SearchResult result = GCParser.parseCacheFromText(page, null);
assertNotNull(result);