diff options
author | Patrick Valsecchi <patrick@thus.ch> | 2015-02-04 09:30:24 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-02-04 10:51:27 -0800 |
commit | bd9a44379367cb6c66781bf301e3af19833a9c02 (patch) | |
tree | f81a2c5cec327b52d892b5b61ea55c7b74ac9b22 /tests | |
parent | e82a0cdec5768a89037537fe20aa9dd3a7358630 (diff) | |
download | subsurface-bd9a44379367cb6c66781bf301e3af19833a9c02.tar.gz |
More tolerant when parsing GPS coordinates.
Refactored the parsing logic to make it more solid (no more guessing) and
more flexible (support more formats).
Added a test for checking that.
Fixed a few warnings.
[Dirk Hohndel: some changes to coding style]
Signed-off-by: Patrick Valsecchi <patrick@thus.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testgpscoords.cpp | 95 | ||||
-rw-r--r-- | tests/testgpscoords.h | 28 |
2 files changed, 123 insertions, 0 deletions
diff --git a/tests/testgpscoords.cpp b/tests/testgpscoords.cpp new file mode 100644 index 000000000..a38dcc807 --- /dev/null +++ b/tests/testgpscoords.cpp @@ -0,0 +1,95 @@ +#include <dive.h> +#include "testgpscoords.h" + +//unit under test +extern bool parseGpsText(const QString &gps_text, double *latitude, double *longitude); + + +void TestGpsCoords::testISO6709DParse() +{ + testParseOK("52°49'02.388\"N 1°36'17.388\"E", + coord2double(52, 49, 2.388), coord2double(1, 36, 17.388)); +} + +void TestGpsCoords::testNegativeISO6709DParse() +{ + testParseOK("52°49'02.388\"S 1°36'17.388\"W", + coord2double(-52, -49, -2.388), coord2double(-1, -36, -17.388)); +} + +void TestGpsCoords::testSpaceISO6709DParse() +{ + testParseOK("52 ° 49 ' 02.388 \" N 1 ° 36 ' 17.388 \" E", + coord2double(52, 49, 2.388), coord2double(1, 36, 17.388)); +} + +void TestGpsCoords::testSecondsParse() +{ + testParseOK("N52°49'02.388\" E1°36'17.388\"", + coord2double(52, 49, 2.388), coord2double(1, 36, 17.388)); +} + +void TestGpsCoords::testSpaceSecondsParse() +{ + testParseOK(" N 52 ° 49 ' 02.388 \" E 1 ° 36 ' 17.388 \"", + coord2double(52, 49, 2.388), coord2double(1, 36, 17.388)); +} + +void TestGpsCoords::testNegativeSecondsParse() +{ + testParseOK("-52°49'02.388\" -1°36'17.388\"", + coord2double(-52, -49, -2.388), coord2double(-1, -36, -17.388)); +} + +void TestGpsCoords::testMinutesParse() +{ + testParseOK("N52°49.03' E1d36.23'", + coord2double(52, 49.03), coord2double(1, 36.23)); +} + +void TestGpsCoords::testSpaceMinutesParse() +{ + testParseOK(" N 52 ° 49.03 ' E 1 ° 36.23 ' ", + coord2double(52, 49.03), coord2double(1, 36.23)); +} + +void TestGpsCoords::testMinutesInversedParse() +{ + testParseOK("2° 53.836' N 73° 32.839' E", + coord2double(2, 53.836), coord2double(73, 32.839)); +} + +void TestGpsCoords::testDecimalParse() +{ + testParseOK("N52.83° E1.61", + coord2double(52.83), coord2double(1.61)); +} + +void TestGpsCoords::testDecimalInversedParse() +{ + testParseOK("52.83N 1.61E", + coord2double(52.83), coord2double(1.61)); +} + +void TestGpsCoords::testSpaceDecimalParse() +{ + testParseOK(" N 52.83 E 1.61 ", + coord2double(52.83), coord2double(1.61)); +} + + +void TestGpsCoords::testParseOK(const QString &txt, double expectedLat, + double expectedLon) +{ + double actualLat, actualLon; + QVERIFY(parseGpsText(txt, &actualLat, &actualLon)); + QCOMPARE(actualLat, expectedLat); + QCOMPARE(actualLon, expectedLon); +} + +double TestGpsCoords::coord2double(double deg, double min, double sec) +{ + return deg + min / 60.0 + sec / 3600.0; +} + +QTEST_MAIN(TestGpsCoords) diff --git a/tests/testgpscoords.h b/tests/testgpscoords.h new file mode 100644 index 000000000..5add3da93 --- /dev/null +++ b/tests/testgpscoords.h @@ -0,0 +1,28 @@ +#ifndef TESTGPSCOORDS_H +#define TESTGPSCOORDS_H + +#include <QtTest> + +class TestGpsCoords : public QObject { +Q_OBJECT +private slots: + void testISO6709DParse(); + void testNegativeISO6709DParse(); + void testSpaceISO6709DParse(); + void testSecondsParse(); + void testSpaceSecondsParse(); + void testNegativeSecondsParse(); + void testMinutesParse(); + void testSpaceMinutesParse(); + void testMinutesInversedParse(); + void testDecimalParse(); + void testSpaceDecimalParse(); + void testDecimalInversedParse(); + +private: + static void testParseOK(const QString &txt, double expectedLat, + double expectedLon); + static double coord2double(double deg, double min = 0.0, double sec = 0.0); +}; + +#endif |