aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/test/LocParserTest.java
blob: ec6d7e6c711f67a5c001f5d586f4898f482bf9a7 (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
package cgeo.geocaching.test;

import cgeo.geocaching.cgCoord;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.files.LocParser;
import cgeo.geocaching.geopoint.Geopoint;

import android.content.res.Resources;
import android.test.InstrumentationTestCase;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

public class LocParserTest extends InstrumentationTestCase {
    private Map<String, cgCoord> readLoc(int resourceId) {
        Map<String, cgCoord> caches = null;
        final Resources res = getInstrumentation().getContext().getResources();
        final InputStream instream = res.openRawResource(resourceId);
        try {
            final StringBuilder buffer = new StringBuilder();
            int ch;
            while ((ch = instream.read()) != -1) {
                buffer.append((char) ch);
            }
            caches = LocParser.parseCoordinates(buffer.toString());
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                instream.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        assertNotNull(caches);
        assertTrue(caches.size() > 0);
        return caches;
    }

    public void testOCLoc() {
        final Map<String, cgCoord> coords = readLoc(R.raw.oc5952_loc);
        final cgCoord coord = coords.get("OC5952");
        assertNotNull(coord);
        assertEquals("OC5952", coord.geocode);
        assertEquals("Die Schatzinsel / treasure island", coord.name);
        assertTrue(new Geopoint(48.85968, 9.18740).isEqualTo(coord.coords));
    }

    public void testGCLoc() {
        final Map<String, cgCoord> coords = readLoc(R.raw.gc1bkp3_loc);
        final cgCoord coord = coords.get("GC1BKP3");
        assertNotNull(coord);
        assertEquals("GC1BKP3", coord.geocode);
        assertEquals("Die Schatzinsel / treasure island", coord.name);
        assertTrue(new Geopoint(48.859683, 9.1874).isEqualTo(coord.coords));
        assertEquals(1.0f, coord.difficulty.floatValue());
        assertEquals(5.0f, coord.terrain.floatValue());
        assertEquals(CacheSize.MICRO, coord.size);
    }

}