diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/GeocacheTest.java')
| -rw-r--r-- | tests/src/cgeo/geocaching/GeocacheTest.java | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java index 5431835..91497f1 100644 --- a/tests/src/cgeo/geocaching/GeocacheTest.java +++ b/tests/src/cgeo/geocaching/GeocacheTest.java @@ -78,4 +78,138 @@ public class GeocacheTest extends AndroidTestCase { } cache.drop(new Handler()); } + + public static void testMergeDownloadedStored() { + + Geocache stored = new Geocache(); + stored.setGeocode("GC12345"); + stored.setDetailed(true); + stored.setDisabled(true); + stored.setType(CacheType.TRADITIONAL); + stored.setCoords(new Geopoint(40.0, 8.0)); + stored.setDescription("Test1"); + + Geocache download = new Geocache(); + download.setGeocode("GC12345"); + download.setDetailed(true); + download.setDisabled(false); + download.setType(CacheType.MULTI); + download.setCoords(new Geopoint(41.0, 9.0)); + download.setDescription("Test2"); + + download.gatherMissingFrom(stored); + + assertTrue("Detailed not merged correctly", download.isDetailed()); + assertFalse("Disabled not merged correctly", download.isDisabled()); + assertEquals("Type not merged correctly", CacheType.MULTI, download.getType()); + assertEquals("Longitude not merged correctly", 9.0, download.getCoords().getLongitude(), 0.1); + assertEquals("Latitude not merged correctly", 41.0, download.getCoords().getLatitude(), 0.1); + assertEquals("Description not merged correctly", "Test2", download.getDescription()); + } + + public static void testMergeLivemapStored() { + + Geocache stored = new Geocache(); + stored.setGeocode("GC12345"); + stored.setDetailed(true); + stored.setDisabled(true); + stored.setType(CacheType.TRADITIONAL); + stored.setCoords(new Geopoint(40.0, 8.0)); + + Geocache livemap = new Geocache(); + livemap.setGeocode("GC12345"); + livemap.setType(CacheType.MULTI); + livemap.setCoords(new Geopoint(41.0, 9.0), 12); + + livemap.gatherMissingFrom(stored); + + assertTrue("Detailed not merged correctly", livemap.isDetailed()); + assertTrue("Disabled not merged correctly", livemap.isDisabled()); + assertEquals("Type not merged correctly", CacheType.TRADITIONAL, livemap.getType()); + assertEquals("Longitude not merged correctly", 8.0, livemap.getCoords().getLongitude(), 0.1); + assertEquals("Latitude not merged correctly", 40.0, livemap.getCoords().getLatitude(), 0.1); + assertEquals("Zoomlevel not merged correctly", stored.getZoomLevel(), livemap.getZoomLevel()); + } + + public static void testMergeLivemapZoomin() { + + Geocache livemapFirst = new Geocache(); + livemapFirst.setGeocode("GC12345"); + livemapFirst.setType(CacheType.TRADITIONAL); + livemapFirst.setCoords(new Geopoint(40.0, 8.0), 11); + + Geocache livemapSecond = new Geocache(); + livemapSecond.setGeocode("GC12345"); + livemapSecond.setType(CacheType.MULTI); + livemapSecond.setCoords(new Geopoint(41.0, 9.0), 12); + + livemapSecond.gatherMissingFrom(livemapFirst); + + assertEquals("Type not merged correctly", CacheType.MULTI, livemapSecond.getType()); + assertEquals("Longitude not merged correctly", 9.0, livemapSecond.getCoords().getLongitude(), 0.1); + assertEquals("Latitude not merged correctly", 41.0, livemapSecond.getCoords().getLatitude(), 0.1); + assertEquals("Zoomlevel not merged correctly", 12, livemapSecond.getZoomLevel()); + } + + public static void testMergeLivemapZoomout() { + + Geocache livemapFirst = new Geocache(); + livemapFirst.setGeocode("GC12345"); + livemapFirst.setType(CacheType.TRADITIONAL); + livemapFirst.setCoords(new Geopoint(40.0, 8.0), 12); + + Geocache livemapSecond = new Geocache(); + livemapSecond.setGeocode("GC12345"); + livemapSecond.setType(CacheType.MULTI); + livemapSecond.setCoords(new Geopoint(41.0, 9.0), 11); + + livemapSecond.gatherMissingFrom(livemapFirst); + + assertEquals("Type not merged correctly", CacheType.TRADITIONAL, livemapSecond.getType()); + assertEquals("Longitude not merged correctly", 8.0, livemapSecond.getCoords().getLongitude(), 0.1); + assertEquals("Latitude not merged correctly", 40.0, livemapSecond.getCoords().getLatitude(), 0.1); + assertEquals("Zoomlevel not merged correctly", 12, livemapSecond.getZoomLevel()); + } + + public static void testMergePopupLivemap() { + + Geocache livemap = new Geocache(); + livemap.setGeocode("GC12345"); + livemap.setCoords(new Geopoint(40.0, 8.0), 12); + livemap.setFound(true); + + Geocache popup = new Geocache(); + popup.setGeocode("GC12345"); + popup.setType(CacheType.MULTI); + + popup.gatherMissingFrom(livemap); + + assertEquals("Type not merged correctly", CacheType.MULTI, popup.getType()); + assertEquals("Longitude not merged correctly", 8.0, popup.getCoords().getLongitude(), 0.1); + assertEquals("Latitude not merged correctly", 40.0, popup.getCoords().getLatitude(), 0.1); + assertTrue("Found not merged correctly", popup.isFound()); + assertEquals("Zoomlevel not merged correctly", 12, popup.getZoomLevel()); + } + + public static void testMergeLivemapBMSearched() { + + Geocache bmsearched = new Geocache(); + bmsearched.setGeocode("GC12345"); + + Geocache livemap = new Geocache(); + livemap.setGeocode("GC12345"); + livemap.setCoords(new Geopoint(40.0, 8.0), 12); + + livemap.gatherMissingFrom(bmsearched); + + assertEquals("Longitude not merged correctly", 8.0, livemap.getCoords().getLongitude(), 0.1); + assertEquals("Latitude not merged correctly", 40.0, livemap.getCoords().getLatitude(), 0.1); + assertEquals("Zoomlevel not merged correctly", 12, livemap.getZoomLevel()); + } + + public static void testNameForSorting() { + Geocache cache = new Geocache(); + cache.setName("GR8 01-01"); + assertEquals("GR000008 000001-000001", cache.getNameForSorting()); + } } |
