diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/export')
| -rw-r--r-- | tests/src/cgeo/geocaching/export/ExportTest.java | 16 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/export/GpxSerializerTest.java | 37 |
2 files changed, 44 insertions, 9 deletions
diff --git a/tests/src/cgeo/geocaching/export/ExportTest.java b/tests/src/cgeo/geocaching/export/ExportTest.java index 7befacf..3e5505a 100644 --- a/tests/src/cgeo/geocaching/export/ExportTest.java +++ b/tests/src/cgeo/geocaching/export/ExportTest.java @@ -24,7 +24,7 @@ public class ExportTest extends CGeoTestCase { assertEquals("Non matching export " + logStr.toString(), "GCX1234,2012-11-18T13:20:20Z,Found it,\"Hidden in a tree\"\n", logStr.toString()); } - public static void testGpxExportSmilies() { + public static void testGpxExportSmilies() throws InterruptedException, ExecutionException { final Geocache cache = new Geocache(); cache.setGeocode("GCX1234"); cache.setCoords(new Geopoint("N 49 44.000 E 8 37.000")); @@ -37,10 +37,6 @@ public class ExportTest extends CGeoTestCase { File result = null; try { result = gpxExport.testExportSync(exportList); - } catch (InterruptedException e) { - fail(e.getCause().toString()); - } catch (ExecutionException e) { - fail(e.getCause().toString()); } finally { cgData.removeCache(cache.getGeocode(), LoadFlags.REMOVE_ALL); } @@ -57,10 +53,12 @@ public class ExportTest extends CGeoTestCase { } public File testExportSync(List<Geocache> caches) throws InterruptedException, ExecutionException { - ExportTask task = new ExportTask(caches, null); - - task.execute((Void) null); - + final ArrayList<String> geocodes = new ArrayList<String>(caches.size()); + for (final Geocache cache : caches) { + geocodes.add(cache.getGeocode()); + } + final ExportTask task = new ExportTask(null); + task.execute(geocodes.toArray(new String[geocodes.size()])); return task.get(); } diff --git a/tests/src/cgeo/geocaching/export/GpxSerializerTest.java b/tests/src/cgeo/geocaching/export/GpxSerializerTest.java new file mode 100644 index 0000000..0080b76 --- /dev/null +++ b/tests/src/cgeo/geocaching/export/GpxSerializerTest.java @@ -0,0 +1,37 @@ +package cgeo.geocaching.export; + +import cgeo.geocaching.Geocache; +import cgeo.geocaching.files.ParserException; +import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; +import cgeo.geocaching.test.R; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collections; +import java.util.concurrent.atomic.AtomicReference; + +public class GpxSerializerTest extends AbstractResourceInstrumentationTestCase { + + public static void testWriteEmptyGPX() throws Exception { + final StringWriter writer = new StringWriter(); + new GpxSerializer().writeGPX(Collections.<String> emptyList(), writer, null); + assertEquals("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><gpx version=\"1.0\" creator=\"c:geo - http://www.cgeo.org/\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0 http://www.groundspeak.com/cache/1/0/1/cache.xsd\" xmlns=\"http://www.topografix.com/GPX/1/0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:groundspeak=\"http://www.groundspeak.com/cache/1/0\" />", writer.getBuffer().toString()); + } + + public void testProgressReporting() throws IOException, ParserException { + final AtomicReference<Integer> importedCount = new AtomicReference<Integer>(0); + final StringWriter writer = new StringWriter(); + + Geocache cache = loadCacheFromResource(R.raw.gc1bkp3_gpx101); + assertNotNull(cache); + + new GpxSerializer().writeGPX(Collections.singletonList("GC1BKP3"), writer, new GpxSerializer.ProgressListener() { + + @Override + public void publishProgress(int countExported) { + importedCount.set(countExported); + } + }); + assertEquals("Progress listener not called", 1, importedCount.get().intValue()); + } +} |
