Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / test / src / TestPlanes.cpp
blob5e526f268e9897fd778c247eec253f56d0aee1cc
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 "Plane/Plane.hpp"
24 #include "Plane/PlaneFileGlue.hpp"
25 #include "IO/FileLineReader.hpp"
26 #include "IO/KeyValueFileReader.hpp"
27 #include "IO/KeyValueFileWriter.hpp"
28 #include "Units/System.hpp"
29 #include "TestUtil.hpp"
31 static void
32 TestReader()
34 Plane plane;
35 PlaneGlue::ReadFile(plane, _T("test/data/D-4449.xcp"));
37 ok1(plane.registration == _T("D-4449"));
38 ok1(plane.competition_id == _T("TH"));
39 ok1(plane.type == _T("Hornet"));
40 ok1(plane.handicap == 100);
41 ok1(plane.polar_name == _T("Hornet"));
42 ok1(equals(plane.polar_shape[0].v,
43 Units::ToSysUnit(fixed(80), Unit::KILOMETER_PER_HOUR)));
44 ok1(equals(plane.polar_shape[1].v,
45 Units::ToSysUnit(fixed(120), Unit::KILOMETER_PER_HOUR)));
46 ok1(equals(plane.polar_shape[2].v,
47 Units::ToSysUnit(fixed(160), Unit::KILOMETER_PER_HOUR)));
48 ok1(equals(plane.polar_shape[0].w, -0.606));
49 ok1(equals(plane.polar_shape[1].w, -0.99));
50 ok1(equals(plane.polar_shape[2].w, -1.918));
51 ok1(equals(plane.reference_mass, 318));
52 ok1(equals(plane.dry_mass, 302));
53 ok1(equals(plane.max_ballast, 100));
54 ok1(plane.dump_time == 90);
55 ok1(equals(plane.max_speed, 41.666));
56 ok1(equals(plane.wing_area, 9.8));
59 static void
60 TestWriter()
62 Plane plane;
63 plane.registration = _T("D-4449");
64 plane.competition_id = _T("TH");
65 plane.type = _T("Hornet");
66 plane.handicap = 100;
67 plane.polar_name = _T("Hornet");
68 plane.polar_shape[0].v = Units::ToSysUnit(fixed(80), Unit::KILOMETER_PER_HOUR);
69 plane.polar_shape[1].v = Units::ToSysUnit(fixed(120), Unit::KILOMETER_PER_HOUR);
70 plane.polar_shape[2].v = Units::ToSysUnit(fixed(160), Unit::KILOMETER_PER_HOUR);
71 plane.polar_shape[0].w = fixed(-0.606);
72 plane.polar_shape[1].w = fixed(-0.99);
73 plane.polar_shape[2].w = fixed(-1.918);
74 plane.reference_mass = fixed(318);
75 plane.dry_mass = fixed(302);
76 plane.max_ballast = fixed(100);
77 plane.dump_time = 90;
78 plane.max_speed = fixed(41.666);
79 plane.wing_area = fixed(9.8);
81 PlaneGlue::WriteFile(plane, _T("output/D-4449.xcp"));
83 FileLineReader reader(_T("output/D-4449.xcp"));
84 if (reader.error())
85 return;
87 unsigned count = 0;
88 bool found1 = false, found2 = false, found3 = false, found4 = false;
89 bool found5 = false, found6 = false, found7 = false, found8 = false;
90 bool found9 = false, found10 = false, found11 = false, found12 = false;
92 TCHAR *line;
93 while ((line = reader.ReadLine()) != NULL) {
94 if (_tcscmp(line, _T("Registration=\"D-4449\"")) == 0)
95 found1 = true;
96 if (_tcscmp(line, _T("CompetitionID=\"TH\"")) == 0)
97 found2 = true;
98 if (_tcscmp(line, _T("Type=\"Hornet\"")) == 0)
99 found3 = true;
100 if (_tcscmp(line, _T("Handicap=\"100\"")) == 0)
101 found4 = true;
102 if (_tcscmp(line, _T("PolarName=\"Hornet\"")) == 0)
103 found5 = true;
104 if (_tcscmp(line, _T("PolarInformation=\"80.000,-0.606,120.000,-0.990,160.000,-1.918\"")) == 0)
105 found6 = true;
106 if (_tcscmp(line, _T("PolarReferenceMass=\"318.000000\"")) == 0)
107 found7 = true;
108 if (_tcscmp(line, _T("PolarDryMass=\"302.000000\"")) == 0)
109 found8 = true;
110 if (_tcscmp(line, _T("MaxBallast=\"100.000000\"")) == 0)
111 found9 = true;
112 if (_tcscmp(line, _T("DumpTime=\"90.000000\"")) == 0)
113 found10 = true;
114 if (_tcscmp(line, _T("MaxSpeed=\"41.666000\"")) == 0)
115 found11 = true;
116 if (_tcscmp(line, _T("WingArea=\"9.800000\"")) == 0)
117 found12 = true;
119 count++;
122 ok1(count == 12);
123 ok1(found1);
124 ok1(found2);
125 ok1(found3);
126 ok1(found4);
127 ok1(found5);
128 ok1(found6);
129 ok1(found7);
130 ok1(found8);
131 ok1(found9);
132 ok1(found10);
133 ok1(found11);
134 ok1(found12);
137 int main(int argc, char **argv)
139 plan_tests(30);
141 TestReader();
142 TestWriter();
144 return exit_status();