android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / test / src / TestIGCParser.cpp
blob93c159d23a27633a7ff19b4b9a2723a0c6f82e3b
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "IGC/IGCParser.hpp"
24 #include "IGC/IGCExtensions.hpp"
25 #include "IGC/IGCFix.hpp"
26 #include "IGC/IGCHeader.hpp"
27 #include "IGC/IGCDeclaration.hpp"
28 #include "Time/BrokenDate.hpp"
29 #include "Time/BrokenTime.hpp"
30 #include "TestUtil.hpp"
32 #include <string.h>
34 static void
35 TestHeader()
37 IGCHeader header;
38 ok1(!IGCParseHeader("", header));
39 ok1(!IGCParseHeader("B1122385103117N00742367EA004900048700000", header));
40 ok1(!IGCParseHeader("AXYZAA", header));
42 ok1(IGCParseHeader("AXCSfoo", header));
43 ok1(strcmp(header.manufacturer, "XCS") == 0);
44 ok1(strcmp(header.id, "foo") == 0);
45 ok1(header.flight == 0);
47 ok1(IGCParseHeader("ACAM3OV", header));
48 ok1(strcmp(header.manufacturer, "CAM") == 0);
49 ok1(strcmp(header.id, "3OV") == 0);
50 ok1(header.flight == 0);
52 ok1(IGCParseHeader("ALXN13103FLIGHT:1", header));
53 ok1(strcmp(header.manufacturer, "LXN") == 0);
54 ok1(strcmp(header.id, "A3Z") == 0);
55 ok1(header.flight == 1);
58 static void
59 TestExtensions()
61 IGCExtensions extensions;
62 ok1(!IGCParseExtensions("", extensions));
63 ok1(!IGCParseExtensions("B1122385103117N00742367EA004900048700000", extensions));
64 ok1(!IGCParseExtensions("AXYZAA", extensions));
66 ok1(IGCParseExtensions("I043638FXA3941ENL4246GSP4749TRT", extensions));
67 ok1(extensions.size() == 4);
68 ok1(extensions[0].start == 36);
69 ok1(extensions[0].finish == 38);
70 ok1(strcmp(extensions[0].code, "FXA") == 0);
71 ok1(extensions[1].start == 39);
72 ok1(extensions[1].finish == 41);
73 ok1(strcmp(extensions[1].code, "ENL") == 0);
74 ok1(extensions[2].start == 42);
75 ok1(extensions[2].finish == 46);
76 ok1(strcmp(extensions[2].code, "GSP") == 0);
77 ok1(extensions[3].start == 47);
78 ok1(extensions[3].finish == 49);
79 ok1(strcmp(extensions[3].code, "TRT") == 0);
82 static void
83 TestDate()
85 BrokenDate date;
86 ok1(!IGCParseDateRecord("", date));
87 ok1(!IGCParseDateRecord("B1122385103117N00742367EA004900048700000", date));
88 ok1(!IGCParseDateRecord("HFDTEXXX", date));
90 ok1(IGCParseDateRecord("HFDTE040910", date));
91 ok1(date.year == 2010);
92 ok1(date.month == 9);
93 ok1(date.day == 4);
95 ok1(IGCParseDateRecord("HFDTE010100", date));
96 ok1(date.year == 2000);
97 ok1(date.month == 1);
98 ok1(date.day == 1);
100 ok1(IGCParseDateRecord("HFDTE311299", date));
101 ok1(date.year == 1999);
102 ok1(date.month == 12);
103 ok1(date.day == 31);
106 static void
107 TestLocation()
109 GeoPoint location;
110 ok1(!IGCParseLocation("", location));
111 ok1(!IGCParseLocation("9103117N00742367E", location));
112 ok1(!IGCParseLocation("-203117N00742367E", location));
113 ok1(!IGCParseLocation("5103117N20742367E", location));
115 ok1(IGCParseLocation("5103117N00742367E", location));
116 ok1(equals(location, 51.05195, 7.706116667));
118 ok1(IGCParseLocation("1234500S12345678E", location));
119 ok1(equals(location, -12.575, 123.7613));
120 ok1(IGCParseLocation("1234500N12345678W", location));
121 ok1(equals(location, 12.575, -123.7613));
122 ok1(IGCParseLocation("1234500S12345678W", location));
123 ok1(equals(location, -12.575, -123.7613));
126 static void
127 TestFix()
129 IGCFix fix;
130 ok1(!IGCParseFix("", fix));
131 ok1(!IGCParseFix("B1122385103117N00742367EA", fix));
133 ok1(!IGCParseFix("B1122385103117X00742367EA0049000487", fix));
134 ok1(!IGCParseFix("B1122385103117N00742367XA0049000487", fix));
135 ok1(!IGCParseFix("B1122389003117N00742367EA0049000487", fix));
136 ok1(!IGCParseFix("B1122385103117N18042367EA0049000487", fix));
137 ok1(!IGCParseFix("B1122385163117N00742367EA0049000487", fix));
138 ok1(!IGCParseFix("B1122385103117N00762367EA0049000487", fix));
140 ok1(IGCParseFix("B1122385103117N00742367EA0049000487", fix));
141 ok1(fix.time == BrokenTime(11, 22, 38));
142 ok1(equals(fix.location, 51.05195, 7.70611667));
143 ok1(fix.gps_valid);
144 ok1(fix.pressure_altitude == 490);
145 ok1(fix.gps_altitude == 487);
147 ok1(IGCParseFix("B1122385103117N00742367EV0049000487", fix));
148 ok1(fix.time == BrokenTime(11, 22, 38));
149 ok1(equals(fix.location, 51.05195, 7.70611667));
150 ok1(!fix.gps_valid);
151 ok1(fix.pressure_altitude == 490);
152 ok1(fix.gps_altitude == 487);
154 ok1(!IGCParseFix("B1122385103117N00742367EX0049000487", fix));
156 ok1(IGCParseFix("B1122435103117N00742367EA004900000000000", fix));
157 ok1(fix.time == BrokenTime(11, 22, 43));
158 ok1(fix.gps_valid);
159 ok1(fix.pressure_altitude == 490);
160 ok1(fix.gps_altitude == 0);
162 ok1(IGCParseFix("B1122535103117S00742367WA104900000700000", fix));
163 ok1(fix.time == BrokenTime(11, 22, 53));
164 ok1(fix.gps_valid);
165 ok1(equals(fix.location, -51.05195, -7.70611667));
166 ok1(fix.pressure_altitude == 10490);
167 ok1(fix.gps_altitude == 7);
170 static void
171 TestFixTime()
173 BrokenTime time;
174 ok1(!IGCParseTime("", time));
176 ok1(IGCParseTime("000000", time));
177 ok1(time == BrokenTime(00, 00, 00));
179 ok1(IGCParseTime("112238", time));
180 ok1(time == BrokenTime(11, 22, 38));
182 ok1(IGCParseTime("235959", time));
183 ok1(time == BrokenTime(23, 59, 59));
185 ok1(!IGCParseTime("235960", time));
186 ok1(!IGCParseTime("236059", time));
187 ok1(!IGCParseTime("240000", time));
189 ok1(IGCParseTime("0123375103117N00742367EV0049000487", time));
190 ok1(time == BrokenTime(01, 23, 37));
193 static void
194 TestDeclarationHeader()
196 IGCDeclarationHeader header;
197 ok1(!IGCParseDeclarationHeader("", header));
198 ok1(!IGCParseDeclarationHeader("C0309111642280309110001-2", header));
200 ok1(IGCParseDeclarationHeader("C020811084345000000000002Task", header));
201 ok1(header.datetime.day == 2);
202 ok1(header.datetime.month == 8);
203 ok1(header.datetime.year == 2011);
204 ok1(header.datetime.hour == 8);
205 ok1(header.datetime.minute == 43);
206 ok1(header.datetime.second == 45);
207 ok1(!header.flight_date.Plausible());
208 ok1(header.num_turnpoints == 2);
209 ok1(header.task_id[0] == '0' &&
210 header.task_id[1] == '0' &&
211 header.task_id[2] == '0' &&
212 header.task_id[3] == '0');
213 ok1(header.task_name == "Task");
215 ok1(IGCParseDeclarationHeader("C210706120510210706000103", header));
216 ok1(header.datetime.day == 21);
217 ok1(header.datetime.month == 7);
218 ok1(header.datetime.year == 2006);
219 ok1(header.datetime.hour == 12);
220 ok1(header.datetime.minute == 5);
221 ok1(header.datetime.second == 10);
222 ok1(header.flight_date.day == 21);
223 ok1(header.flight_date.month == 7);
224 ok1(header.flight_date.year == 2006);
225 ok1(header.num_turnpoints == 3);
226 ok1(header.task_id[0] == '0' &&
227 header.task_id[1] == '0' &&
228 header.task_id[2] == '0' &&
229 header.task_id[3] == '1');
230 ok1(header.task_name.empty());
233 static void
234 TestDeclarationTurnpoint()
236 IGCDeclarationTurnpoint tp;
237 ok1(!IGCParseDeclarationTurnpoint("", tp));
239 ok1(IGCParseDeclarationTurnpoint("C5000633N01015083ESchweinfurtsued", tp));
240 ok1(equals(tp.location, 50.01055, 10.251383333));
241 ok1(tp.name == "Schweinfurtsued");
243 ok1(IGCParseDeclarationTurnpoint("C5100633S00015083W", tp));
244 ok1(equals(tp.location, -51.01055, -0.251383333));
245 ok1(tp.name.empty());
248 int main(int argc, char **argv)
250 plan_tests(136);
252 TestHeader();
253 TestDate();
254 TestLocation();
255 TestExtensions();
256 TestFix();
257 TestFixTime();
258 TestDeclarationHeader();
259 TestDeclarationTurnpoint();
261 return exit_status();