diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/export')
| -rw-r--r-- | tests/src/cgeo/geocaching/export/ExportTest.java | 6 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/export/GpxSerializerTest.java | 45 |
2 files changed, 48 insertions, 3 deletions
diff --git a/tests/src/cgeo/geocaching/export/ExportTest.java b/tests/src/cgeo/geocaching/export/ExportTest.java index 3e5505a..6d39f8d 100644 --- a/tests/src/cgeo/geocaching/export/ExportTest.java +++ b/tests/src/cgeo/geocaching/export/ExportTest.java @@ -1,9 +1,9 @@ package cgeo.geocaching.export; import cgeo.CGeoTestCase; +import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; import cgeo.geocaching.LogEntry; -import cgeo.geocaching.cgData; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.geopoint.Geopoint; @@ -30,7 +30,7 @@ public class ExportTest extends CGeoTestCase { cache.setCoords(new Geopoint("N 49 44.000 E 8 37.000")); final LogEntry log = new LogEntry(1353244820000L, LogType.FOUND_IT, "Smile: \ud83d\ude0a"); cache.getLogs().add(log); - cgData.saveCache(cache, LoadFlags.SAVE_ALL); + DataStore.saveCache(cache, LoadFlags.SAVE_ALL); ArrayList<Geocache> exportList = new ArrayList<Geocache>(); exportList.add(cache); GpxExportTester gpxExport = new GpxExportTester(); @@ -38,7 +38,7 @@ public class ExportTest extends CGeoTestCase { try { result = gpxExport.testExportSync(exportList); } finally { - cgData.removeCache(cache.getGeocode(), LoadFlags.REMOVE_ALL); + DataStore.removeCache(cache.getGeocode(), LoadFlags.REMOVE_ALL); } assertNotNull(result); diff --git a/tests/src/cgeo/geocaching/export/GpxSerializerTest.java b/tests/src/cgeo/geocaching/export/GpxSerializerTest.java index 0080b76..5c83b35 100644 --- a/tests/src/cgeo/geocaching/export/GpxSerializerTest.java +++ b/tests/src/cgeo/geocaching/export/GpxSerializerTest.java @@ -1,12 +1,19 @@ package cgeo.geocaching.export; import cgeo.geocaching.Geocache; +import cgeo.geocaching.files.GPX10Parser; import cgeo.geocaching.files.ParserException; +import cgeo.geocaching.list.StoredList; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; import cgeo.geocaching.test.R; +import org.apache.commons.lang3.CharEncoding; + +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.StringWriter; +import java.util.Collection; import java.util.Collections; import java.util.concurrent.atomic.AtomicReference; @@ -34,4 +41,42 @@ public class GpxSerializerTest extends AbstractResourceInstrumentationTestCase { }); assertEquals("Progress listener not called", 1, importedCount.get().intValue()); } + + /** + * This test verifies that a loop of import, export, import leads to the same cache information. + * + * @throws IOException + * @throws ParserException + */ + public void testStableExportImportExport() throws IOException, ParserException { + final String geocode = "GC1BKP3"; + final int cacheResource = R.raw.gc1bkp3_gpx101; + final Geocache cache = loadCacheFromResource(cacheResource); + assertNotNull(cache); + + final String gpxFirst = getGPXFromCache(geocode); + + assertTrue(gpxFirst.length() > 0); + + final GPX10Parser parser = new GPX10Parser(StoredList.TEMPORARY_LIST_ID); + + final InputStream stream = new ByteArrayInputStream(gpxFirst.getBytes(CharEncoding.UTF_8)); + Collection<Geocache> caches = parser.parse(stream, null); + assertNotNull(caches); + assertEquals(1, caches.size()); + + final String gpxSecond = getGPXFromCache(geocode); + assertEquals(replaceLogIds(gpxFirst), replaceLogIds(gpxSecond)); + } + + private static String replaceLogIds(String gpx) { + return gpx.replaceAll("log id=\"\\d*\"", ""); + } + + private static String getGPXFromCache(String geocode) throws IOException { + final StringWriter writer = new StringWriter(); + new GpxSerializer().writeGPX(Collections.singletonList(geocode), writer, null); + return writer.toString(); + } + } |
