aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/export/GpxSerializerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/cgeo/geocaching/export/GpxSerializerTest.java')
-rw-r--r--tests/src/cgeo/geocaching/export/GpxSerializerTest.java45
1 files changed, 45 insertions, 0 deletions
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();
+ }
+
}