aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching
diff options
context:
space:
mode:
authorBananeweizen <Bananeweizen@gmx.de>2011-12-31 00:08:32 +0100
committerBananeweizen <Bananeweizen@gmx.de>2011-12-31 00:08:32 +0100
commit90d5cf89533b26d846de06b67470df34ec2924d8 (patch)
treeebb78b5af5ce82c76bb4859987b56c87ffa0b55c /tests/src/cgeo/geocaching
parent690e0aa8eb798150a8973f115ad73c855698c46b (diff)
downloadcgeo-90d5cf89533b26d846de06b67470df34ec2924d8.zip
cgeo-90d5cf89533b26d846de06b67470df34ec2924d8.tar.gz
cgeo-90d5cf89533b26d846de06b67470df34ec2924d8.tar.bz2
fix #920: WPs created from Personal Notes not correct
Diffstat (limited to 'tests/src/cgeo/geocaching')
-rw-r--r--tests/src/cgeo/geocaching/cgBaseTest.java32
-rw-r--r--tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java15
2 files changed, 44 insertions, 3 deletions
diff --git a/tests/src/cgeo/geocaching/cgBaseTest.java b/tests/src/cgeo/geocaching/cgBaseTest.java
index bdd8ea2..3aee275 100644
--- a/tests/src/cgeo/geocaching/cgBaseTest.java
+++ b/tests/src/cgeo/geocaching/cgBaseTest.java
@@ -10,6 +10,7 @@ import cgeo.geocaching.utils.CancellableHandler;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.MediumTest;
+import java.util.ArrayList;
import java.util.Date;
import junit.framework.Assert;
@@ -91,4 +92,35 @@ public class cgBaseTest extends AndroidTestCase {
assertEquals("?", cgBase.getHumanDistance(null));
assertEquals("123 km", cgBase.getHumanDistance(123.456f));
}
+
+ public static void testWaypointsFromNote() {
+ final cgCache cache = createCache();
+ assertNotNull(cache);
+
+ assertWaypointsFromNote(cache, 0, " ");
+ assertWaypointsFromNote(cache, 0, "some random strings 1 with n 2 numbers");
+ assertWaypointsFromNote(cache, 0, "Station3 some coords");
+ assertWaypointsFromNote(cache, 1, "Station3: N51 21.523 / E07 02.680");
+ assertWaypointsFromNote(cache, 1, "N51 21.523 / E07 02.680");
+ assertWaypointsFromNote(cache, 0, "N51 21.523");
+ assertWaypointsFromNote(cache, 1, " n 51° 21.523 - E07 02.680");
+ assertWaypointsFromNote(cache, 2, "Station3: N51 21.523 / E07 02.680\n\r Station4: N52 21.523 / E012 02.680");
+ assertWaypointsFromNote(cache, 0, "51 21 523 / 07 02 680");
+ assertWaypointsFromNote(cache, 0, "N51");
+ }
+
+ private static void assertWaypointsFromNote(final cgCache cache, int waypoints, String note) {
+ cache.setPersonalNote(note);
+ cache.setWaypoints(new ArrayList<cgWaypoint>());
+ cache.parseWaypointsFromNote();
+ assertEquals(waypoints, cache.getWaypoints().size());
+ }
+
+ private static cgCache createCache() {
+ final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES.get(0);
+ // to get the same results we have to use the date format used when the mocked data was created
+ Settings.setGcCustomDate(mockedCache.getDateFormat());
+ final ParseResult parseResult = cgBase.parseCacheFromText(mockedCache.getData(), 0, null);
+ return parseResult.cacheList.get(0);
+ }
} \ No newline at end of file
diff --git a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
index a21fa58..95100c9 100644
--- a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
@@ -1,8 +1,5 @@
package cgeo.geocaching.geopoint;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.GeopointParser;
-
import android.test.AndroidTestCase;
import junit.framework.Assert;
@@ -27,6 +24,18 @@ public class GeoPointParserTest extends AndroidTestCase {
Assert.assertTrue(goal.isEqualTo(GeopointParser.parse("N 49° 56.031 | E 8° 38.564"), 1e-6));
}
+ public static void testCoordinateMissingPart() {
+ // we are trying to parse a _point_, but have only one a latitude. Don't accept the numerical part as longitude!
+ Geopoint point = null;
+ try {
+ point = GeopointParser.parse("N 49° 56.031");
+ } catch (Exception e) {
+ // expected
+ }
+ Assert.assertEquals(null, point);
+ }
+
+
public static void testSouth() {
Assert.assertEquals(-refLatitude, GeopointParser.parseLatitude("S 49° 56.031"), 1e-8);
}