aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2012-11-11 11:40:27 +0100
committerBananeweizen <bananeweizen@gmx.de>2012-11-11 11:40:27 +0100
commit47c20caaefce9a11ef1a8247ad25e97231f29979 (patch)
tree32c60377edb0f066ae2243c4b919b9cc25667f08 /tests/src
parentce6b28bb617a2ec02c68356159ac5ba9bd531c0c (diff)
downloadcgeo-47c20caaefce9a11ef1a8247ad25e97231f29979.zip
cgeo-47c20caaefce9a11ef1a8247ad25e97231f29979.tar.gz
cgeo-47c20caaefce9a11ef1a8247ad25e97231f29979.tar.bz2
fix #1973: Logs gone after online logging
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java21
-rw-r--r--tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java27
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 4b4f286..6f8a76d 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -7,6 +7,7 @@ import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
+import cgeo.geocaching.enumerations.LoadFlags.LoadFlag;
import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
@@ -18,6 +19,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -253,4 +255,23 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertTrue(codes.contains("GC2KN6K"));
assertTrue(codes.contains("GC1T3MK"));
}
+
+ public void testLazyLogLoading() throws IOException, ParserException {
+ // 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);
+ assertEquals(1, caches.size());
+ cgeoapplication.getInstance().removeAllFromCache();
+
+ // load only the minimum cache, it has several members missing
+ final cgCache minimalCache = cgeoapplication.getInstance().loadCache(geocode, EnumSet.of(LoadFlag.LOAD_DB_MINIMAL));
+
+ // now check that we load lazy members on demand
+ assertFalse(minimalCache.getAttributes().isEmpty());
+ assertFalse(minimalCache.getLogs().isEmpty());
+
+ removeCacheCompletely(geocode);
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java b/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java
new file mode 100644
index 0000000..1d0767e
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java
@@ -0,0 +1,27 @@
+package cgeo.geocaching.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class LazyInitializedListTest extends TestCase {
+ public static void testAccess() {
+ final LazyInitializedList<String> list = new LazyInitializedList<String>() {
+ @Override
+ protected List<String> loadFromDatabase() {
+ return new ArrayList<String>();
+ }
+ };
+ assertTrue(list.isEmpty());
+ list.add("Test");
+ assertFalse(list.isEmpty());
+ assertEquals(1, list.size());
+ int iterations = 0;
+ for (String element : list) {
+ assertEquals("Test", element);
+ iterations++;
+ }
+ assertEquals(1, iterations);
+ }
+}