aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/cgDataTest.java
blob: 0625585f95c86af8e26badeb886229f0fd9df5d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package cgeo.geocaching;

import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;

import android.test.ApplicationTestCase;

import java.util.HashSet;
import java.util.Set;

public class cgDataTest extends ApplicationTestCase<cgeoapplication> {

    public cgDataTest() {
        super(cgeoapplication.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        // init environment
        createApplication();
    }

    public static void testStoredLists() {

        cgeoapplication app = cgeoapplication.getInstance();
        int listId1 = StoredList.STANDARD_LIST_ID;
        int listId2 = StoredList.STANDARD_LIST_ID;

        // create caches
        final cgCache cache1 = cgBaseTest.createCache(0);
        assertNotNull(cache1);
        final cgCache cache2 = cgBaseTest.createCache(1);
        assertNotNull(cache2);

        try {

            // create lists
            listId1 = app.createList("cgData Test");
            assertTrue(listId1 > StoredList.STANDARD_LIST_ID);
            listId2 = app.createList("cgDataTest");
            assertTrue(listId2 > StoredList.STANDARD_LIST_ID);
            assertTrue(app.getLists().size() >= 2);

            cache1.setDetailed(true);
            cache1.setListId(listId1);
            cache2.setDetailed(true);
            cache2.setListId(listId1);

            // save caches to DB (cache1=listId1, cache2=listId1)
            app.saveCache(cache1, LoadFlags.SAVE_ALL);
            app.saveCache(cache2, LoadFlags.SAVE_ALL);
            assertTrue(app.getAllStoredCachesCount(false, CacheType.ALL, null) >= 2);

            // rename list (cache1=listId1, cache2=listId1)
            assertEquals(1, app.renameList(listId1, "cgData Test (renamed)"));

            // get list
            StoredList list1 = app.getList(listId1);
            assertEquals("cgData Test (renamed)", list1.title);

            // move to list (cache1=listId2, cache2=listId2)
            app.moveToList(cache1.getGeocode(), listId2);
            assertEquals(1, app.getAllStoredCachesCount(false, CacheType.ALL, listId2));

            // remove list (cache1=listId2, cache2=listId2)
            assertTrue(app.removeList(listId1));

            // mark dropped (cache1=1, cache2=0)
            app.markDropped(cache2.getGeocode());

            // mark stored (cache1=1, cache2=listId2)
            app.markStored(cache2.getGeocode(), listId2);
            assertEquals(2, app.getAllStoredCachesCount(false, CacheType.ALL, listId2));

            // drop stored (cache1=0, cache2=0)
            app.dropList(listId2);

        } finally {

            // remove caches
            Set<String> geocodes = new HashSet<String>();
            geocodes.add(cache1.getGeocode());
            geocodes.add(cache2.getGeocode());
            app.removeCaches(geocodes, LoadFlags.REMOVE_ALL);

            // remove list
            app.removeList(listId1);
            app.removeList(listId2);
        }
    }
}