Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / test / src / TestLogger.cpp
blob6ef9cd08eb16166789c1bd21d887d00921129b23
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/IGCWriter.hpp"
24 #include "OS/FileUtil.hpp"
25 #include "NMEA/Info.hpp"
26 #include "IO/FileLineReader.hpp"
27 #include "TestUtil.hpp"
29 #include <assert.h>
30 #include <cstdio>
32 static void
33 CheckTextFile(const TCHAR *path, const char *const* expect)
35 FileLineReaderA reader(path);
36 ok1(!reader.error());
38 const char *line;
39 while ((line = reader.ReadLine()) != NULL) {
40 if (*line == 'G')
41 break;
43 ok1(*expect != NULL);
45 if (strncmp(*expect, "HFFTYFRTYPE:", 12) == 0) {
46 ok1(strncmp(line, "HFFTYFRTYPE:", 12) == 0);
47 } else {
48 if (strcmp(line, *expect)) {
49 printf("# \"%s\" fails to match with \"%s\"\n", line, *expect);
51 ok1(strcmp(line, *expect) == 0);
54 ++expect;
57 ok1(*expect == NULL);
60 static const char *const expect[] = {
61 "AXCSFOO",
62 "HFDTE040910",
63 "HFFXA050",
64 "HFPLTPILOT:Pilot Name",
65 "HFGTYGLIDERTYPE:ASK-21",
66 "HFGIDGLIDERID:D-1234",
67 "HFCIDCOMPETITIONID:34",
68 "HFFTYFRTYPE:XCSOAR XCSOAR",
69 "HFGPS:bar",
70 "HFDTM100DATUM:WGS-84",
71 "I023638FXA3940SIU",
72 "C040910112233000000000001",
73 "C0000000N00000000ETAKEOFF",
74 "C5103117N00742367EBERGNEUSTADT",
75 "C5037932N01043567ESUHL",
76 "C5103117N00742367EBERGNEUSTADT",
77 "C0000000N00000000ELANDING",
78 "F112233",
79 "B1122385103117N00742367EA004900048700000",
80 "E112243my_event",
81 "B1122435103117N00742367EA004900048700000",
82 "LPLTmy_note",
83 "F112253121701",
84 "B1122535103117S00742367WA004900048700000",
85 NULL
88 static void
89 Run(IGCWriter &writer)
91 static const GeoPoint home(Angle::Degrees(7.7061111111111114),
92 Angle::Degrees(51.051944444444445));
93 static const GeoPoint tp(Angle::Degrees(10.726111111111111),
94 Angle::Degrees(50.6322));
96 static NMEAInfo i;
97 i.clock = fixed(1);
98 i.time = fixed(1);
99 i.time_available.Update(i.clock);
100 i.date_time_utc.year = 2010;
101 i.date_time_utc.month = 9;
102 i.date_time_utc.day = 4;
103 i.date_time_utc.hour = 11;
104 i.date_time_utc.minute = 22;
105 i.date_time_utc.second = 33;
106 i.location = home;
107 i.location_available.Update(i.clock);
108 i.gps_altitude = fixed(487);
109 i.gps_altitude_available.Update(i.clock);
110 i.ProvidePressureAltitude(fixed(490));
111 i.ProvideBaroAltitudeTrue(fixed(400));
113 writer.WriteHeader(i.date_time_utc, _T("Pilot Name"), _T("ASK-21"),
114 _T("D-1234"), _T("34"), "FOO", _T("bar"), false);
115 writer.StartDeclaration(i.date_time_utc, 3);
116 writer.AddDeclaration(home, _T("Bergneustadt"));
117 writer.AddDeclaration(tp, _T("Suhl"));
118 writer.AddDeclaration(home, _T("Bergneustadt"));
119 writer.EndDeclaration();
121 writer.LogEmptyFRecord(i.date_time_utc);
123 i.date_time_utc.second += 5;
124 writer.LogPoint(i);
125 i.date_time_utc.second += 5;
126 writer.LogEvent(i, "my_event");
127 i.date_time_utc.second += 5;
128 writer.LoggerNote(_T("my_note"));
130 int satellites[GPSState::MAXSATELLITES];
131 for (unsigned i = 0; i < GPSState::MAXSATELLITES; ++i)
132 satellites[i] = 0;
134 satellites[2] = 12;
135 satellites[4] = 17;
136 satellites[7] = 1;
138 i.date_time_utc.second += 5;
139 writer.LogFRecord(i.date_time_utc, satellites);
141 i.location = GeoPoint(Angle::Degrees(-7.7061111111111114),
142 Angle::Degrees(-51.051944444444445));
143 writer.LogPoint(i);
145 writer.Flush();
146 writer.Sign();
149 static void
150 Run(const TCHAR *path)
152 IGCWriter writer(path);
153 Run(writer);
156 int main(int argc, char **argv)
158 plan_tests(51);
160 const TCHAR *path = _T("output/test/test.igc");
161 File::Delete(path);
163 Run(path);
165 CheckTextFile(path, expect);
167 GRecord grecord;
168 grecord.Initialize();
169 ok1(grecord.VerifyGRecordInFile(path));
171 return exit_status();