aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/files
diff options
context:
space:
mode:
authorStephan Merker <merker.stephan@googlemail.com>2011-10-30 14:01:05 +0100
committerStephan Merker <merker.stephan@googlemail.com>2011-10-30 14:01:05 +0100
commit96fbeff00e6793eed966c15f5829e3d18e16b326 (patch)
tree348f05f68cfb1b8dbb6e09d852f002a3ffb3ce98 /tests/src/cgeo/geocaching/files
parent5687446f0dd3c3b2db5f7dc18f95ee02f94f2ccc (diff)
downloadcgeo-96fbeff00e6793eed966c15f5829e3d18e16b326.zip
cgeo-96fbeff00e6793eed966c15f5829e3d18e16b326.tar.gz
cgeo-96fbeff00e6793eed966c15f5829e3d18e16b326.tar.bz2
fix #714: Progress bar wrong when importing gpx with waypoints
- moved file handling from GPXParser to cgeopgxes - streamlined LocParser with GPXParser - removed cache counting in favor of progress bar - added error dialog if import went wrong - fixed stream handling when importing attachement
Diffstat (limited to 'tests/src/cgeo/geocaching/files')
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java36
-rw-r--r--tests/src/cgeo/geocaching/files/LocParserTest.java75
2 files changed, 46 insertions, 65 deletions
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 8a229ef..8fed2ae 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -14,7 +14,6 @@ import android.content.res.Resources;
import android.os.Handler;
import android.test.InstrumentationTestCase;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
@@ -30,7 +29,7 @@ public class GPXParserTest extends InstrumentationTestCase {
testGPXVersion(R.raw.gc1bkp3_gpx100);
}
- private cgCache testGPXVersion(final int resourceId) throws IOException {
+ private cgCache testGPXVersion(final int resourceId) throws IOException, ParserException {
final List<cgCache> caches = readGPX(resourceId);
assertNotNull(caches);
assertEquals(1, caches.size());
@@ -51,13 +50,13 @@ public class GPXParserTest extends InstrumentationTestCase {
return cache;
}
- public void testGPXVersion101() throws IOException {
+ public void testGPXVersion101() throws IOException, ParserException {
final cgCache cache = testGPXVersion(R.raw.gc1bkp3_gpx101);
assertNotNull(cache.attributes);
assertEquals(10, cache.attributes.size());
}
- public void testOC() throws IOException {
+ public void testOC() throws IOException, ParserException {
final List<cgCache> caches = readGPX(R.raw.oc5952_gpx);
final cgCache cache = caches.get(0);
assertEquals("OC5952", cache.geocode);
@@ -74,7 +73,7 @@ public class GPXParserTest extends InstrumentationTestCase {
assertTrue(new Geopoint(48.85968, 9.18740).isEqualTo(cache.coords));
}
- public void testGc31j2h() throws IOException {
+ public void testGc31j2h() throws IOException, ParserException {
final List<cgCache> caches = readGPX(R.raw.gc31j2h);
assertEquals(1, caches.size());
final cgCache cache = caches.get(0);
@@ -86,7 +85,7 @@ public class GPXParserTest extends InstrumentationTestCase {
assertNull(cache.waypoints);
}
- public void testGc31j2hWpts() throws IOException {
+ public void testGc31j2hWpts() throws IOException, ParserException {
List<cgCache> caches = readGPX(R.raw.gc31j2h, R.raw.gc31j2h_wpts);
assertEquals(1, caches.size());
cgCache cache = caches.get(0);
@@ -94,7 +93,7 @@ public class GPXParserTest extends InstrumentationTestCase {
assertGc31j2hWaypoints(cache);
}
- public void testGc31j2hWptsWithoutCache() throws IOException {
+ public void testGc31j2hWptsWithoutCache() throws IOException, ParserException {
final List<cgCache> caches = readGPX(R.raw.gc31j2h_wpts);
assertEquals(0, caches.size());
}
@@ -175,33 +174,20 @@ public class GPXParserTest extends InstrumentationTestCase {
assertEquals(8.545100, wp.coords.getLongitude(), 0.000001);
}
- public static void testGetWaypointsFileForGpx() {
- assertEquals(new File("1234567-wpts.gpx"), GPXParser.getWaypointsFileForGpx(new File("1234567.gpx")));
- assertEquals(new File("/mnt/sdcard/1234567-wpts.gpx"), GPXParser.getWaypointsFileForGpx(new File("/mnt/sdcard/1234567.gpx")));
- assertEquals(new File("/mnt/sdcard/1-wpts.gpx"), GPXParser.getWaypointsFileForGpx(new File("/mnt/sdcard/1.gpx")));
- assertEquals(new File("/mnt/sd.card/1-wpts.gpx"), GPXParser.getWaypointsFileForGpx(new File("/mnt/sd.card/1.gpx")));
- assertEquals(new File("1234567.9-wpts.gpx"), GPXParser.getWaypointsFileForGpx(new File("1234567.9.gpx")));
- assertEquals(new File("1234567-wpts.gpx"), GPXParser.getWaypointsFileForGpx(new File("1234567.GPX")));
- assertEquals(new File("gpx.gpx-wpts.gpx"), GPXParser.getWaypointsFileForGpx(new File("gpx.gpx.gpx")));
- assertNull(GPXParser.getWaypointsFileForGpx(new File("123.gpy")));
- assertNull(GPXParser.getWaypointsFileForGpx(new File("gpx")));
- assertNull(GPXParser.getWaypointsFileForGpx(new File(".gpx")));
- assertNull(GPXParser.getWaypointsFileForGpx(new File("/mnt/sdcard/.gpx")));
- }
-
- private List<cgCache> readGPX(int... resourceIds) throws IOException {
+ private List<cgCache> readGPX(int... resourceIds) throws IOException, ParserException {
final GPX10Parser parser = new GPX10Parser(1);
+ Collection<cgCache> caches = null;
for (int resourceId : resourceIds) {
final Resources res = getInstrumentation().getContext().getResources();
final InputStream instream = res.openRawResource(resourceId);
try {
- assertTrue(parser.parse(instream, new Handler()));
+ caches = parser.parse(instream, new Handler());
+ assertNotNull(caches);
} finally {
instream.close();
}
}
- Collection<cgCache> caches = parser.getParsedCaches();
- assertNotNull(caches);
+
List<cgCache> cacheList = new ArrayList<cgCache>(caches);
// TODO: may need to sort by geocode when a test imports more than one cache
return cacheList;
diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java
index 9d90ef4..9b633e3 100644
--- a/tests/src/cgeo/geocaching/files/LocParserTest.java
+++ b/tests/src/cgeo/geocaching/files/LocParserTest.java
@@ -1,64 +1,59 @@
package cgeo.geocaching.files;
-import cgeo.geocaching.cgCoord;
+import cgeo.geocaching.cgCache;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.test.R;
import android.content.res.Resources;
+import android.os.Handler;
import android.test.InstrumentationTestCase;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
public class LocParserTest extends InstrumentationTestCase {
- private Map<String, cgCoord> readLoc(int resourceId) {
- Map<String, cgCoord> caches = null;
+ private List<cgCache> readLoc(int resourceId) throws IOException, ParserException {
+ LocParser parser = new LocParser(1);
+ Collection<cgCache> caches = null;
final Resources res = getInstrumentation().getContext().getResources();
final InputStream instream = res.openRawResource(resourceId);
try {
- final StringBuilder buffer = new StringBuilder();
- int ch;
- while ((ch = instream.read()) != -1) {
- buffer.append((char) ch);
- }
- caches = LocParser.parseCoordinates(buffer.toString());
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ caches = parser.parse(instream, new Handler());
+ assertNotNull(caches);
+ assertTrue(caches.size() > 0);
} finally {
- try {
- instream.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ instream.close();
}
- assertNotNull(caches);
- assertTrue(caches.size() > 0);
- return caches;
- }
- public void testOCLoc() {
- final Map<String, cgCoord> coords = readLoc(R.raw.oc5952_loc);
- final cgCoord coord = coords.get("OC5952");
- assertNotNull(coord);
- assertEquals("OC5952", coord.geocode);
- assertEquals("Die Schatzinsel / treasure island", coord.name);
- assertTrue(new Geopoint(48.85968, 9.18740).isEqualTo(coord.coords));
+ List<cgCache> cacheList = new ArrayList<cgCache>(caches);
+ // TODO: may need to sort by geocode when a test imports more than one cache
+ return cacheList;
}
- public void testGCLoc() {
- final Map<String, cgCoord> coords = readLoc(R.raw.gc1bkp3_loc);
- final cgCoord coord = coords.get("GC1BKP3");
- assertNotNull(coord);
- assertEquals("GC1BKP3", coord.geocode);
- assertEquals("Die Schatzinsel / treasure island", coord.name);
- assertTrue(new Geopoint(48.859683, 9.1874).isEqualTo(coord.coords));
- assertEquals(1.0f, coord.difficulty.floatValue());
- assertEquals(5.0f, coord.terrain.floatValue());
- assertEquals(CacheSize.MICRO, coord.size);
+ public void testOCLoc() throws IOException, ParserException {
+ final List<cgCache> caches = readLoc(R.raw.oc5952_loc);
+ assertEquals(1, caches.size());
+ final cgCache cache = caches.get(0);
+ assertNotNull(cache);
+ assertEquals("OC5952", cache.geocode);
+ assertEquals("Die Schatzinsel / treasure island", cache.name);
+ assertTrue(new Geopoint(48.85968, 9.18740).isEqualTo(cache.coords));
}
+ public void testGCLoc() throws IOException, ParserException {
+ final List<cgCache> caches = readLoc(R.raw.gc1bkp3_loc);
+ assertEquals(1, caches.size());
+ final cgCache cache = caches.get(0);
+ assertNotNull(cache);
+ assertEquals("GC1BKP3", cache.geocode);
+ assertEquals("Die Schatzinsel / treasure island", cache.name);
+ assertTrue(new Geopoint(48.859683, 9.1874).isEqualTo(cache.coords));
+ assertEquals(1.0f, cache.difficulty.floatValue());
+ assertEquals(5.0f, cache.terrain.floatValue());
+ assertEquals(CacheSize.MICRO, cache.size);
+ }
}