aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/files/GPXParserTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/cgeo/geocaching/files/GPXParserTest.java')
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java94
1 files changed, 42 insertions, 52 deletions
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index c195953..1849124 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -1,11 +1,11 @@
package cgeo.geocaching.files;
+import cgeo.geocaching.Geocache;
import cgeo.geocaching.LogEntry;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.StoredList;
-import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgWaypoint;
-import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.cgData;
+import cgeo.geocaching.Waypoint;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
@@ -24,21 +24,22 @@ import java.util.Collection;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
- private static final SimpleDateFormat LOG_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // 2010-04-20T07:00:00Z
+ private static final SimpleDateFormat LOG_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); // 2010-04-20T07:00:00Z
private int listId;
public void testGPXVersion100() throws Exception {
testGPXVersion(R.raw.gc1bkp3_gpx100);
}
- private cgCache testGPXVersion(final int resourceId) throws IOException, ParserException {
- final List<cgCache> caches = readGPX10(resourceId);
+ private Geocache testGPXVersion(final int resourceId) throws IOException, ParserException {
+ final List<Geocache> caches = readGPX10(resourceId);
assertNotNull(caches);
assertEquals(1, caches.size());
- final cgCache cache = caches.get(0);
+ final Geocache cache = caches.get(0);
assertEquals("GC1BKP3", cache.getGeocode());
assertEquals("9946f030-a514-46d8-a050-a60e92fd2e1a", cache.getGuid());
assertEquals(CacheType.TRADITIONAL, cache.getType());
@@ -57,14 +58,14 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
}
public void testGPXVersion101() throws IOException, ParserException {
- final cgCache cache = testGPXVersion(R.raw.gc1bkp3_gpx101);
+ final Geocache cache = testGPXVersion(R.raw.gc1bkp3_gpx101);
assertNotNull(cache.getAttributes());
assertEquals(10, cache.getAttributes().size());
}
public void testOC() throws IOException, ParserException {
- final List<cgCache> caches = readGPX10(R.raw.oc5952_gpx);
- final cgCache cache = caches.get(0);
+ final List<Geocache> caches = readGPX10(R.raw.oc5952_gpx);
+ final Geocache cache = caches.get(0);
assertEquals("OC5952", cache.getGeocode());
assertEquals(CacheType.TRADITIONAL, cache.getType());
assertEquals(false, cache.isArchived());
@@ -83,9 +84,9 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
public void testGc31j2h() throws IOException, ParserException {
removeCacheCompletely("GC31J2H");
- final List<cgCache> caches = readGPX10(R.raw.gc31j2h);
+ final List<Geocache> caches = readGPX10(R.raw.gc31j2h);
assertEquals(1, caches.size());
- final cgCache cache = caches.get(0);
+ final Geocache cache = caches.get(0);
assertGc31j2h(cache);
assertSame(cache, caches.get(0));
@@ -97,15 +98,15 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
public void testGc31j2hWpts() throws IOException, ParserException {
removeCacheCompletely("GC31J2H");
- List<cgCache> caches = readGPX10(R.raw.gc31j2h, R.raw.gc31j2h_wpts);
+ List<Geocache> caches = readGPX10(R.raw.gc31j2h, R.raw.gc31j2h_wpts);
assertEquals(1, caches.size());
- cgCache cache = caches.get(0);
+ Geocache cache = caches.get(0);
assertGc31j2h(cache);
assertGc31j2hWaypoints(cache);
}
public void testGc31j2hWptsWithoutCache() throws IOException, ParserException {
- final List<cgCache> caches = readGPX10(R.raw.gc31j2h_wpts);
+ final List<Geocache> caches = readGPX10(R.raw.gc31j2h_wpts);
assertEquals(0, caches.size());
}
@@ -122,7 +123,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertEquals(WaypointType.PARKING, GPXParser.convertWaypointSym2Type(WaypointType.PARKING.getL10n()));
}
- private static void assertGc31j2h(final cgCache cache) {
+ private static void assertGc31j2h(final Geocache cache) {
assertEquals("GC31J2H", cache.getGeocode());
assertEquals("Hockenheimer City-Brunnen", cache.getName());
assertTrue("Hockenheimer City-Brunnen by vptsz, Multi-cache (2/1)", cache.getShortDescription().startsWith("Kurzer informativer Multi entlang der Brunnen"));
@@ -140,7 +141,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertFalse(cache.isDisabled());
assertFalse(cache.isEventCache());
assertFalse(cache.isPremiumMembersOnly());
- assertFalse(cache.isOwn());
+ assertFalse(cache.isOwner());
assertTrue(cache.isFound());
assertEquals("Station3: Der zerbrochene Stein zählt doppelt.\nFinal: Oben neben dem Tor", cache.getHint());
// logs
@@ -163,10 +164,10 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
}
}
- private static void assertGc31j2hWaypoints(final cgCache cache) {
+ private static void assertGc31j2hWaypoints(final Geocache cache) {
assertNotNull(cache.getWaypoints());
assertEquals(2, cache.getWaypoints().size());
- cgWaypoint wp = cache.getWaypoints().get(0);
+ Waypoint wp = cache.getWaypoints().get(0);
assertEquals("GC31J2H", wp.getGeocode());
assertEquals("00", wp.getPrefix());
assertEquals("---", wp.getLookup());
@@ -187,24 +188,24 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertEquals(8.545100, wp.getCoords().getLongitude(), 0.000001);
}
- private List<cgCache> readGPX10(int... resourceIds) throws IOException, ParserException {
+ private List<Geocache> readGPX10(int... resourceIds) throws IOException, ParserException {
final GPX10Parser parser = new GPX10Parser(listId);
return readVersionedGPX(parser, resourceIds);
}
- private List<cgCache> readGPX11(int... resourceIds) throws IOException, ParserException {
+ private List<Geocache> readGPX11(int... resourceIds) throws IOException, ParserException {
final GPX11Parser parser = new GPX11Parser(listId);
return readVersionedGPX(parser, resourceIds);
}
- private List<cgCache> readVersionedGPX(final GPXParser parser, int... resourceIds) throws IOException, ParserException {
+ private List<Geocache> readVersionedGPX(final GPXParser parser, int... resourceIds) throws IOException, ParserException {
final Set<String> result = new HashSet<String>();
for (int resourceId : resourceIds) {
final InputStream instream = getResourceStream(resourceId);
try {
- Collection<cgCache> caches = parser.parse(instream, null);
+ Collection<Geocache> caches = parser.parse(instream, null);
assertNotNull(caches);
- for (cgCache cache : caches) {
+ for (Geocache cache : caches) {
result.add(cache.getGeocode());
}
} finally {
@@ -212,47 +213,37 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
}
}
// reload caches, because the parser only returns the minimum version of each cache
- return new ArrayList<cgCache>(cgeoapplication.getInstance().loadCaches(result, LoadFlags.LOAD_ALL_DB_ONLY));
+ return new ArrayList<Geocache>(cgData.loadCaches(result, LoadFlags.LOAD_ALL_DB_ONLY));
}
- public static void testParseDateWithFractionalSeconds() {
+ public static void testParseDateWithFractionalSeconds() throws ParseException {
// was experienced in GSAK file
final String dateString = "2011-08-13T02:52:18.103Z";
- try {
- GPXParser.parseDate(dateString);
- } catch (ParseException e) {
- fail();
- e.printStackTrace();
- }
+ GPXParser.parseDate(dateString);
}
- public static void testParseDateWithHugeFraction() {
+ public static void testParseDateWithHugeFraction() throws ParseException {
// see issue 821
String dateString = "2011-11-07T00:00:00.0000000-07:00";
- try {
- GPXParser.parseDate(dateString);
- } catch (ParseException e) {
- fail();
- e.printStackTrace();
- }
+ GPXParser.parseDate(dateString);
}
public void testSelfmadeGPXWithoutGeocodes() throws Exception {
- final List<cgCache> caches = readGPX11(R.raw.no_connector);
+ final List<Geocache> caches = readGPX11(R.raw.no_connector);
assertEquals(13, caches.size());
}
public void testTexasChallenge2012() throws Exception {
- final List<cgCache> caches = readGPX10(R.raw.challenge);
+ final List<Geocache> caches = readGPX10(R.raw.challenge);
// previously these caches overwrote each other during parsing
assertEquals(130, caches.size());
}
public void testGeoToad() throws Exception {
- final List<cgCache> caches = readGPX10(R.raw.geotoad);
+ final List<Geocache> caches = readGPX10(R.raw.geotoad);
assertEquals(2, caches.size());
List<String> codes = new ArrayList<String>();
- for (cgCache cache : caches) {
+ for (Geocache cache : caches) {
codes.add(cache.getGeocode());
}
assertTrue(codes.contains("GC2KN6K"));
@@ -263,12 +254,11 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
// this test should be in CacheTest, but it is easier to create here due to the GPX import abilities
final String geocode = "GC31J2H";
removeCacheCompletely(geocode);
- final List<cgCache> caches = readGPX10(R.raw.lazy);
+ final List<Geocache> caches = readGPX10(R.raw.lazy);
assertEquals(1, caches.size());
- cgeoapplication.getInstance().removeAllFromCache();
-
+ cgData.removeAllFromCache();
// load only the minimum cache, it has several members missing
- final cgCache minimalCache = cgeoapplication.getInstance().loadCache(geocode, EnumSet.of(LoadFlag.LOAD_DB_MINIMAL));
+ final Geocache minimalCache = cgData.loadCache(geocode, EnumSet.of(LoadFlag.LOAD_DB_MINIMAL));
// now check that we load lazy members on demand
assertFalse(minimalCache.getAttributes().isEmpty());
@@ -282,7 +272,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
removeCacheCompletely(geocode);
// first import
- List<cgCache> caches = readGPX10(R.raw.lazy);
+ List<Geocache> caches = readGPX10(R.raw.lazy);
assertEquals(1, caches.size());
assertEquals(6, caches.get(0).getLogs().size());
@@ -297,17 +287,17 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- listId = cgeoapplication.getInstance().createList("Temporary unit testing");
+ listId = cgData.createList("Temporary unit testing");
assertTrue(listId != StoredList.TEMPORARY_LIST_ID);
assertTrue(listId != StoredList.STANDARD_LIST_ID);
}
@Override
protected void tearDown() throws Exception {
- SearchResult search = cgeoapplication.getInstance().getBatchOfStoredCaches(false, null, CacheType.ALL, listId);
+ SearchResult search = cgData.getBatchOfStoredCaches(null, CacheType.ALL, listId);
assertNotNull(search);
- cgeoapplication.getInstance().removeCaches(search.getGeocodes(), LoadFlags.REMOVE_ALL);
- cgeoapplication.getInstance().removeList(listId);
+ cgData.removeCaches(search.getGeocodes(), LoadFlags.REMOVE_ALL);
+ cgData.removeList(listId);
super.tearDown();
}
}