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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#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::testXmlFormatParse()
{
testParseOK("46.473881 6.784696",
coord2double(46.473881), coord2double(6.784696));
}
void TestGpsCoords::testNegativeXmlFormatParse()
{
testParseOK("46.473881 -6.784696",
coord2double(46.473881), -coord2double(6.784696));
}
void TestGpsCoords::testNoUnitParse()
{
testParseOK("48 51.491n 2 17.677e",
coord2double(48, 51.491), coord2double(2, 17.677));
}
void TestGpsCoords::testPrefixNoUnitParse()
{
testParseOK("n48 51.491 w2 17.677",
coord2double(48, 51.491), -coord2double(2, 17.677));
}
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)
|