Debian Codegraph @

test_suite/unit_tests/Main/test_posinit.cxx

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 // Written by James Turner, started 2017.
2 //
3 // Copyright (C) 2017 James Turner
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 #include "config.h"
20 #include "test_posinit.hxx"
21
22 #include <thread>
23 #include <chrono>
24
25 #include "test_suite/FGTestApi/testGlobals.hxx"
26 #include "test_suite/FGTestApi/NavDataCache.hxx"
27 #include "test_suite/FGTestApi/scene_graph.hxx"
28
29 #include <simgear/props/props_io.hxx>
30 #include <AIModel/AIManager.hxx>
31
32 #include "Main/positioninit.hxx"
33 #include "Main/options.hxx"
34 #include "Main/globals.hxx"
35 #include "Main/fg_props.hxx"
36 #include "Navaids/navlist.hxx"
37
38 #include <AIModel/performancedb.hxx>
39
40 #include "Airports/airport.hxx"
41 #include "Airports/groundnetwork.hxx"
42 #include <Airports/airportdynamicsmanager.hxx>
43 #include <Airports/dynamics.hxx>
44
45 #include "ATC/atc_mgr.hxx"
46
47 using namespace std::string_literals;
48 using namespace flightgear;
49
50 void PosInitTests::setUp()
51 {
52 FGTestApi::setUp::initTestGlobals("posinit");
53 FGTestApi::setUp::initNavDataCache();
54 Options::reset();
55 fgLoadProps("defaults.xml", globals->get_props());
56
57 // ensure EDDF has a valid ground net for parking testing
58 FGAirport::clearAirportsCache();
59 auto apt = FGAirport::getByIdent("EDDF");
60
61
62 apt->testSuiteInjectGroundnetXML(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "EDDF.groundnet.xml");
63
64 globals->get_subsystem_mgr()->add<flightgear::AirportDynamicsManager>();
65 globals->get_subsystem_mgr()->add<PerformanceDB>();
66 globals->get_subsystem_mgr()->add<FGATCManager>();
67 globals->get_subsystem_mgr()->add<FGAIManager>();
68 }
69
70
71 void PosInitTests::tearDown()
72 {
73 FGTestApi::tearDown::shutdownTestGlobals();
74 }
75
76 void PosInitTests::checkAlt(float value)
77 {
78 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("/position/altitude-ft", value, globals->get_props()->getDoubleValue("/position/altitude-ft"), 10.0);
79 }
80
81 void PosInitTests::checkHeading(float value)
82 {
83 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("/orientation/heading-deg incorrect", value, globals->get_props()->getDoubleValue("/orientation/heading-deg"), 1.0);
84 }
85
86 void PosInitTests::checkPosition(SGGeod expectedPos, float delta)
87 {
88 double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
89 expectedPos);
90 CPPUNIT_ASSERT_MESSAGE("Unexpected Position", dist < delta);
91 }
92
93 void PosInitTests::checkClosestAirport(std::string icao)
94 {
95 std::string closest = globals->get_props()->getStringValue("/sim/airport/closest-airport-id");
96 CPPUNIT_ASSERT_EQUAL_MESSAGE("Closest Airport (/sim/airport/closest-airport-id) Incorrect", icao, closest);
97 }
98
99 void PosInitTests::checkStringProp(std::string property, std::string expected)
100 {
101 std::string value = globals->get_props()->getStringValue(property);
102 CPPUNIT_ASSERT_EQUAL_MESSAGE(property, expected, value);
103 }
104
105 void PosInitTests::checkRunway(std::string expected)
106 {
107 checkStringProp("/sim/presets/runway", expected);
108 }
109
110 void PosInitTests::checkOnGround()
111 {
112 CPPUNIT_ASSERT_MESSAGE("/sim/presets/onground!=true for ground start", fgGetBool("/sim/presets/onground"));
113 }
114
115 void PosInitTests::checkInAir()
116 {
117 CPPUNIT_ASSERT_MESSAGE("/sim/presets/onground != false for in air start", fgGetBool("/sim/presets/onground") == false);
118 CPPUNIT_ASSERT_MESSAGE("/sim/presets/trim != true for in air start", fgGetBool("/sim/presets/trim") == true);
119 }
120
121 void PosInitTests::testDefaultStartup()
122 {
123 {
124 Options* opts = Options::sharedInstance();
125 opts->setShouldLoadDefaultConfig(false);
126
127 const char* args[] = {"dummypath"};
128 opts->init(1, (char**) args, SGPath());
129 opts->processOptions();
130 }
131
132 initPosition();
133
134 // verify we got the location specified in location-preset.xml
135 // this unfortunately means manually parsing that file, oh well
136
137 {
138 SGPath presets = globals->get_fg_root() / "location-presets.xml";
139 CPPUNIT_ASSERT(presets.exists());
140 SGPropertyNode_ptr props(new SGPropertyNode);
141 readProperties(presets, props);
142
143 std::string icao = props->getStringValue("/sim/presets/airport-id");
144 FGAirportRef defaultAirport = FGAirport::getByIdent(icao);
145 checkClosestAirport(icao);
146 checkPosition(defaultAirport->geod(), 10000.0);
147 }
148 }
149
150 void PosInitTests::testAirportOnlyStartup()
151 {
152 {
153 Options* opts = Options::sharedInstance();
154 opts->setShouldLoadDefaultConfig(false);
155
156 const char* args[] = {"dummypath", "--airport=EDDF"};
157 opts->init(2, (char**) args, SGPath());
158 opts->processOptions();
159 }
160
161 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
162 initPosition();
163
164 checkClosestAirport("EDDF"s);
165 checkPosition(FGAirport::getByIdent("EDDF"s)->geod(), 10000.0);
166 }
167
168 void PosInitTests::testAirportAltitudeOffsetStartup()
169 {
170 {
171 Options* opts = Options::sharedInstance();
172 opts->setShouldLoadDefaultConfig(false);
173
174 const char* args[] = {"dummypath", "--airport=EDDF", "--altitude=1000", "--offset-azimuth=90", "--offset-distance=5", "--heading=45"};
175 opts->init(6, (char**) args, SGPath());
176 opts->processOptions();
177 }
178
179 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
180 initPosition();
181
182 SGGeod expectedPos = SGGeodesy::direct(FGAirport::getByIdent("EDDF")->geod(), 270, 5 * SG_NM_TO_METER);
183 checkPosition(expectedPos, 5000.0);
184 checkAlt(1000.0);
185 checkHeading(45.0);
186 }
187
188 void PosInitTests::testAirportAndRunwayStartup()
189 {
190 {
191 Options* opts = Options::sharedInstance();
192 opts->setShouldLoadDefaultConfig(false);
193
194 const char* args[] = {"dummypath", "--airport=EDDF", "--runway=25C"};
195 opts->init(3, (char**) args, SGPath());
196 opts->processOptions();
197 }
198
199 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
200 CPPUNIT_ASSERT(fgGetBool("/sim/presets/runway-requested"));
201 checkRunway("25C"s);
202 initPosition();
203
204 checkClosestAirport("EDDF"s);
205 checkPosition(FGAirport::getByIdent("EDDF")->geod(), 10000.0);
206 checkHeading(250.0);
207 }
208
209 void PosInitTests::simulateFinalizePosition()
210 {
211 auto subSyMgr = globals->get_subsystem_mgr();
212 subSyMgr->bind();
213 subSyMgr->init();
214 subSyMgr->postinit();
215
216 finalizePosition();
217 }
218
219 void PosInitTests::testAirportAndParkingStartup()
220 {
221 {
222 Options* opts = Options::sharedInstance();
223 opts->setShouldLoadDefaultConfig(false);
224
225 const char* args[] = {"dummypath", "--airport=EDDF", "--parkpos=V266"};
226 opts->init(3, (char**) args, SGPath());
227 opts->processOptions();
228 }
229
230 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
231 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
232
233 checkStringProp("/sim/presets/parkpos", "V266");
234 initPosition();
235
236 simulateFinalizePosition();
237
238 auto apt = FGAirport::getByIdent("EDDF");
239 auto parking = apt->groundNetwork()->findParkingByName("V266");
240 CPPUNIT_ASSERT(parking != nullptr);
241
242 checkClosestAirport("EDDF"s);
243 checkPosition(parking->geod(), 20);
244 }
245
246 void PosInitTests::testAirportAndAvailableParkingStartup()
247 {
248 {
249 Options* opts = Options::sharedInstance();
250 opts->setShouldLoadDefaultConfig(false);
251
252 const char* args[] = {"dummypath", "--airport=EDDF", "--parkpos=AVAILABLE"};
253 opts->init(3, (char**) args, SGPath());
254 opts->processOptions();
255 }
256
257 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
258 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
259 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/presets/parkpos") == "AVAILABLE"s);
260 initPosition();
261
262 simulateFinalizePosition();
263
264 auto assignedParking = globals->get_props()->getStringValue("/sim/presets/parkpos");
265 CPPUNIT_ASSERT(assignedParking != "AVAILABLE");
266
267 auto dynamics = FGAirport::getByIdent("EDDF");
268 auto parking = dynamics->groundNetwork()->findParkingByName(assignedParking);
269 CPPUNIT_ASSERT(parking);
270
271 checkClosestAirport("EDDF"s);
272 // Anywhere around EDDF will do!
273 checkPosition(FGAirport::getByIdent("EDDF")->geod(), 10000.0);
274 checkPosition(parking->geod(), 20.0);
275 }
276
277 void PosInitTests::testAirportAndMetarStartup()
278 {
279 {
280 Options* opts = Options::sharedInstance();
281 opts->setShouldLoadDefaultConfig(false);
282 const char* args[] = {"dummypath", "--airport=LOWI", "--metar=XXXX 271320Z 08007KT 030V130 CAVOK 17/02 Q1020 NOSIG"};
283 opts->init(3, (char**) args, SGPath());
284 opts->processOptions();
285 }
286
287 initPosition();
288
289 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/airport/closest-airport-id") == "LOWI"s);
290 double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
291 FGAirport::getByIdent("LOWI")->geod());
292 CPPUNIT_ASSERT(dist < 10000);
293 CPPUNIT_ASSERT(globals->get_props()->getStringValue("sim/atc/runway") == "26"s);
294 }
295
296 void PosInitTests::testAirportRunwayOffsetGlideslopeStartup()
297 {
298 {
299 Options* opts = Options::sharedInstance();
300 opts->setShouldLoadDefaultConfig(false);
301
302 const char* args[] = {"dummypath", "--airport=EDDF", "--runway=25C", "--offset-distance=5", "--glideslope=3.5"};
303 opts->init(5, (char**) args, SGPath());
304 opts->processOptions();
305 }
306
307 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
308 CPPUNIT_ASSERT(fgGetBool("/sim/presets/runway-requested"));
309 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/presets/runway") == "25C"s);
310 CPPUNIT_ASSERT(globals->get_props()->getIntValue("/sim/presets/offset-distance-nm") == 5);
311 initPosition();
312
313 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/airport/closest-airport-id") == "EDDF"s);
314
315 double crs = FGAirport::getByIdent("EDDF")->getRunwayByIdent("25C")->headingDeg() -180.0;
316
317 SGGeod expectedPos = SGGeodesy::direct(FGAirport::getByIdent("EDDF")->getRunwayByIdent("25C")->geod(), crs, 5 * SG_NM_TO_METER);
318
319 double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
320 expectedPos);
321 CPPUNIT_ASSERT(dist < 500);
322
323 // Check altitude based on glideslope. 5nm = 30380ft. so altitude should be 2213ft.
324 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("/position/altitude-ft", globals->get_props()->getDoubleValue("/position/altitude-ft"), 2213.0, 50.0);
325 }
326
327 void PosInitTests::testAirportRunwayOffsetAltitudeStartup()
328 {
329 {
330 Options* opts = Options::sharedInstance();
331 opts->setShouldLoadDefaultConfig(false);
332
333 const char* args[] = {"dummypath", "--airport=EDDF", "--runway=25C", "--offset-distance=5", "--altitude=3000"};
334 opts->init(5, (char**) args, SGPath());
335 opts->processOptions();
336 }
337
338 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
339 CPPUNIT_ASSERT(fgGetBool("/sim/presets/runway-requested"));
340 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/presets/runway") == "25C"s);
341 CPPUNIT_ASSERT(globals->get_props()->getIntValue("/sim/presets/offset-distance-nm") == 5);
342 initPosition();
343
344 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/airport/closest-airport-id") == "EDDF"s);
345
346 double crs = FGAirport::getByIdent("EDDF")->getRunwayByIdent("25C")->headingDeg() -180.0;
347
348 SGGeod expectedPos = SGGeodesy::direct(FGAirport::getByIdent("EDDF")->getRunwayByIdent("25C")->geod(), crs, 5 * SG_NM_TO_METER);
349
350 double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
351 expectedPos);
352 CPPUNIT_ASSERT(dist < 500);
353
354 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("/position/altitude-ft", globals->get_props()->getDoubleValue("/position/altitude-ft"), 3000.0, 10.0);
355 }
356
357 void PosInitTests::testVOROnlyStartup()
358 {
359 {
360 Options* opts = Options::sharedInstance();
361 opts->setShouldLoadDefaultConfig(false);
362
363 const char* args[] = {"dummypath", "--vor=JFK", "--vor-frequency=115.9"};
364 opts->init(3, (char**) args, SGPath());
365 opts->processOptions();
366 }
367
368 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/airport-requested"));
369 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/presets/vor-id") == "JFK"s);
370 initPosition();
371
372 FGNavList::TypeFilter filter(FGPositioned::Type::VOR);
373 const nav_list_type navlist = FGNavList::findByIdentAndFreq( "JFK", 0.0, &filter );
374
375 double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
376 navlist[0]->geod());
377
378 CPPUNIT_ASSERT(dist < 500);
379 }
380
381 void PosInitTests::testVOROffsetAltitudeHeadingStartup()
382 {
383 {
384 Options* opts = Options::sharedInstance();
385 opts->setShouldLoadDefaultConfig(false);
386
387 const char* args[] = {"dummypath", "--vor=JFK", "--offset-distance=5", "--vor-frequency=115.9", "--offset-azimuth=78", "--altitude=1000", "--heading=45", "--vc=250"};
388 opts->init(7, (char**) args, SGPath());
389 opts->processOptions();
390 }
391
392 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/airport-requested"));
393 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
394 CPPUNIT_ASSERT(globals->get_props()->getIntValue("/sim/presets/offset-distance-nm") == 5);
395 initPosition();
396
397
398 FGNavList::TypeFilter filter(FGPositioned::Type::VOR);
399 const nav_list_type navlist = FGNavList::findByIdentAndFreq( "JFK", 115.9, &filter );
400
401 double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
402 SGGeodesy::direct(navlist[0]->geod(), 180 + 78, 5 * SG_NM_TO_METER));
403
404 CPPUNIT_ASSERT(dist < 1000);
405 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("/position/altitude-ft", globals->get_props()->getDoubleValue("/position/altitude-ft"), 1000.0, 10.0);
406 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("/orientation/heading-deg incorrect", globals->get_props()->getDoubleValue("/orientation/heading-deg"), 45.0, 1.0);
407 }
408
409 void PosInitTests::testFixOnlyStartup()
410 {
411 {
412 Options* opts = Options::sharedInstance();
413 opts->setShouldLoadDefaultConfig(false);
414
415 const char* args[] = {"dummypath", "--fix=FOLER"};
416 opts->init(2, (char**) args, SGPath());
417 opts->processOptions();
418 }
419
420 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/airport-requested"));
421 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/presets/fix") == "FOLER"s);
422 initPosition();
423
424 FGNavList::TypeFilter filter(FGPositioned::Type::FIX);
425 const nav_list_type navlist = FGNavList::findByIdentAndFreq( "FOLER", 0.0, &filter );
426
427 double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
428 navlist[0]->geod());
429
430 CPPUNIT_ASSERT(dist < 500);
431 }
432
433 void PosInitTests::testFixOffsetAltitudeHeadingStartup()
434 {
435 {
436 Options* opts = Options::sharedInstance();
437 opts->setShouldLoadDefaultConfig(false);
438
439 const char* args[] = {"dummypath", "--fix=FOLER", "--offset-distance=5", "--offset-azimuth=78", "--altitude=1000", "--heading=45", "--vc=250"};
440 opts->init(6, (char**) args, SGPath());
441 opts->processOptions();
442 }
443
444 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/airport-requested"));
445 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
446 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/presets/fix") == "FOLER"s);
447 CPPUNIT_ASSERT(globals->get_props()->getIntValue("/sim/presets/offset-distance-nm") == 5);
448 initPosition();
449
450
451 FGNavList::TypeFilter filter(FGPositioned::Type::FIX);
452 const nav_list_type navlist = FGNavList::findByIdentAndFreq( "FOLER", 0.0, &filter );
453
454 double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
455 SGGeodesy::direct(navlist[0]->geod(), 180 + 78, 5 * SG_NM_TO_METER));
456
457 CPPUNIT_ASSERT(dist < 1000);
458 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("/position/altitude-ft", globals->get_props()->getDoubleValue("/position/altitude-ft"), 1000.0, 10.0);
459 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("/orientation/heading-deg incorrect", globals->get_props()->getDoubleValue("/orientation/heading-deg"), 45.0, 1.0);
460 }
461
462 void PosInitTests::testNDBOnlyStartup()
463 {
464 {
465 Options* opts = Options::sharedInstance();
466 opts->setShouldLoadDefaultConfig(false);
467
468 const char* args[] = {"dummypath", "--ndb=HHI", "--ndb-frequency=373"};
469 opts->init(3, (char**) args, SGPath());
470 opts->processOptions();
471 }
472
473 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/airport-requested"));
474 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/presets/ndb-id") == "HHI"s);
475 initPosition();
476
477 FGNavList::TypeFilter filter(FGPositioned::Type::NDB);
478 const nav_list_type navlist = FGNavList::findByIdentAndFreq( "HHI", 373, &filter );
479
480 double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
481 navlist[0]->geod());
482
483 CPPUNIT_ASSERT(dist < 500);
484 }
485
486 void PosInitTests::testNDBOffsetAltitudeHeadingStartup()
487 {
488 {
489 Options* opts = Options::sharedInstance();
490 opts->setShouldLoadDefaultConfig(false);
491
492 const char* args[] = {"dummypath", "--ndb=HHI", "--ndb-frequency=373", "--offset-distance=5", "--offset-azimuth=78", "--altitude=1000", "--heading=45", "--vc=250"};
493 opts->init(8, (char**) args, SGPath());
494 opts->processOptions();
495 }
496
497 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/airport-requested"));
498 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
499 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/presets/ndb-id") == "HHI"s);
500 //CPPUNIT_ASSERT(globals->get_props()->getIntValue("/sim/presets/offset-distance-nm") == 5);
501 initPosition();
502
503 FGNavList::TypeFilter filter(FGPositioned::Type::NDB);
504 const nav_list_type navlist = FGNavList::findByIdentAndFreq( "HHI", 373, &filter );
505
506 double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
507 SGGeodesy::direct(navlist[0]->geod(), 180 + 78, 5 * SG_NM_TO_METER));
508
509 std::cerr << "Navlist size : " << navlist.size() << " dist " << dist << "\n";
510 CPPUNIT_ASSERT(dist < 1000);
511 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("/position/altitude-ft", 1000.0, globals->get_props()->getDoubleValue("/position/altitude-ft"), 10.0);
512 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("/orientation/heading-deg incorrect", 45.0, globals->get_props()->getDoubleValue("/orientation/heading-deg"), 1.0);
513 }
514
515 void PosInitTests::testLatLonStartup()
516 {
517 {
518 Options* opts = Options::sharedInstance();
519 opts->setShouldLoadDefaultConfig(false);
520
521 const char* args[] = {"dummypath", "--lat=55.9", "--lon=-3.355", "--altitude=1000"};
522 opts->init(4, (char**) args, SGPath());
523 opts->processOptions();
524 }
525
526 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/airport-requested"));
527 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
528
529 initPosition();
530
531 SGGeod pos = SGGeod::fromDeg(-3.355, 55.9);
532 checkPosition(pos, 100.0);
533 checkAlt(1000.0);
534 }
535
536 void PosInitTests::testLatLonOffsetStartup()
537 {
538 {
539 Options* opts = Options::sharedInstance();
540 opts->setShouldLoadDefaultConfig(false);
541
542 const char* args[] = {"dummypath", "--lat=55.9", "--lon=-3.355", "--altitude=1000", "--offset-distance=5", "--offset-azimuth=90", "--heading=45"};
543 opts->init(7, (char**) args, SGPath());
544 opts->processOptions();
545 }
546
547 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/airport-requested"));
548 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
549
550 initPosition();
551
552 SGGeod pos = SGGeodesy::direct(SGGeod::fromDeg(-3.355, 55.9), 270, 5 * SG_NM_TO_METER);
553 checkPosition(pos, 1000.0);
554 checkAlt(1000.0);
555 checkHeading(45.0);
556 }
557
558 void PosInitTests::testCarrierStartup()
559 {
560 {
561 Options* opts = Options::sharedInstance();
562 opts->setShouldLoadDefaultConfig(false);
563
564 const char* args[] = {"dummypath", "--carrier=Nimitz"};
565 opts->init(2, (char**) args, SGPath());
566 opts->processOptions();
567 }
568
569 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/airport-requested"));
570 initPosition();
571
572 checkPosition(SGGeod::fromDeg(-122.6, 37.8), 100.0);
573 checkOnGround();
574 }
575
576 void PosInitTests::testAirportRepositionAirport()
577 {
578 {
579 Options* opts = Options::sharedInstance();
580 opts->setShouldLoadDefaultConfig(false);
581
582 const char* args[] = {"dummypath", "--airport=EDDF", "--runway=25C"};
583 opts->init(3, (char**) args, SGPath());
584 opts->processOptions();
585 }
586
587 std::cout << "Preset heading " << fgGetDouble("/sim/presets/heading-deg") << "\n";
588
589 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
590 CPPUNIT_ASSERT(fgGetBool("/sim/presets/runway-requested"));
591 checkRunway("25C"s);
592 initPosition();
593
594 checkClosestAirport("EDDF"s);
595 checkPosition(FGAirport::getByIdent("EDDF")->geod(), 10000.0);
596 checkHeading(250.0);
597
598 std::cout << "Preset heading " << fgGetDouble("/sim/presets/heading-deg") << "\n";
599
600 // Now re-position to KSFO runway
601 // Reset the Lat/Lon as these will be used in preference to the airport ID
602 fgSetDouble("/sim/presets/longitude-deg", -9990.00);
603 fgSetDouble("/sim/presets/latitude-deg", -9990.00);
604 fgSetString("/sim/presets/airport-id", "KHAF");
605 fgSetDouble("/sim/presets/heading-deg", 9990.00);
606 fgSetString("/sim/presets/runway", "12");
607 initPosition();
608
609 checkClosestAirport("KHAF"s);
610 checkPosition(FGAirport::getByIdent("KHAF")->geod(), 5000.0);
611 checkHeading(137.0); // Lots of magnetic variation in SF Bay area!
612 checkOnGround();
613
614
615 }
616
617 // this simulates what the C172 preflight tutorial does,
618 // where the user is likely at a random airport (on a runway), and starts
619 // the preflight tutorial, which repositions them to a ramp location
620 // at PHTO
621 void PosInitTests::testAirportRunwayRepositionAirport()
622 {
623 {
624 Options* opts = Options::sharedInstance();
625 opts->setShouldLoadDefaultConfig(false);
626 const char* args[] = {"dummypath", "--airport=EDDS", "--runway=07"};
627 opts->init(3, (char**)args, SGPath());
628 opts->processOptions();
629 }
630
631 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
632 CPPUNIT_ASSERT(fgGetBool("/sim/presets/runway-requested"));
633 checkRunway("07"s);
634 initPosition();
635 simulateFinalizePosition();
636
637 checkClosestAirport("EDDS"s);
638 checkPosition(FGAirport::getByIdent("EDDS")->geod(), 10000.0);
639
640 // Now re-position to PHTO runway
641 // Reset the Lat/Lon as these will be used in preference to the airport ID
642 fgSetDouble("/sim/presets/longitude-deg", -155.0597483);
643 fgSetDouble("/sim/presets/latitude-deg", 19.71731272);
644 fgSetString("/sim/presets/airport-id", "PHTO");
645 fgSetDouble("/sim/presets/heading-deg", 125);
646 fgSetBool("/sim/presets/on-ground", true);
647 fgSetBool("/sim/presets/runway-requested", true);
648 fgSetBool("/sim/presets/airport-requested", true);
649 fgSetBool("/sim/presets/parking-requested", true);
650
651 simulateStartReposition();
652 finalizePosition();
653
654 FGTestApi::runForTime(1.0);
655
656 checkClosestAirport("PHTO"s);
657 checkPosition(FGAirport::getByIdent("PHTO")->geod(), 5000.0);
658 checkHeading(125);
659 checkOnGround();
660
661 FGTestApi::runForTime(1.0);
662 }
663
664 void PosInitTests::testParkInvalid()
665 {
666 {
667 Options* opts = Options::sharedInstance();
668 opts->setShouldLoadDefaultConfig(false);
669 const char* args[] = {"dummypath", "--airport=EDDF", "--parkpos=foobar"};
670 opts->init(3, (char**) args, SGPath());
671 opts->processOptions();
672 }
673
674 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
675 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
676
677 checkStringProp("/sim/presets/parkpos", "foobar");
678 initPosition();
679
680 auto apt = FGAirport::getByIdent("EDDF");
681
682
683 fgSetDouble("/environment/metar/base-wind-dir-deg", 350.0);
684 fgSetBool("/environment/metar/valid", true);
685
686 simulateFinalizePosition();
687 checkClosestAirport("EDDF"s);
688 // we should be on the best runway, let's see
689 auto runway = apt->getRunwayByIdent("36");
690 checkPosition(runway->threshold());
691 }
692
693 void PosInitTests::testParkAtOccupied()
694 {
695 {
696 Options* opts = Options::sharedInstance();
697 opts->setShouldLoadDefaultConfig(false);
698
699 const char* args[] = {"dummypath", "--airport=EDDF", "--parkpos=V266"};
700 opts->init(3, (char**) args, SGPath());
701 opts->processOptions();
702 }
703
704 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
705 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
706
707 checkStringProp("/sim/presets/parkpos", "V266");
708 initPosition();
709
710 auto apt = FGAirport::getByIdent("EDDF");
711 auto parking = apt->groundNetwork()->findParkingByName("V266");
712
713 // now mark the parking as occupied
714 auto dynamics = apt->getDynamics();
715 dynamics->setParkingAvailable(parking, false);
716 fgSetDouble("/environment/metar/base-wind-dir-deg", 350.0);
717 fgSetBool("/environment/metar/valid", true);
718
719 simulateFinalizePosition();
720
721 checkClosestAirport("EDDF"s);
722
723
724 // we should be on the best runway, let's see
725
726 auto runway = apt->getRunwayByIdent("36");
727 checkPosition(runway->threshold());
728 }
729
730 void PosInitTests::simulateStartReposition()
731 {
732 initPosition();
733
734 auto atcManager = globals->get_subsystem<FGATCManager>();
735 if (atcManager) {
736 atcManager->reposition();
737 }
738 }
739
740 void PosInitTests::testRepositionAtParking()
741 {
742 {
743 Options* opts = Options::sharedInstance();
744 opts->setShouldLoadDefaultConfig(false);
745
746 const char* args[] = {"dummypath", "--airport=KSFO", "--runway=28L"};
747 opts->init(3, (char**) args, SGPath());
748 opts->processOptions();
749 }
750
751 initPosition();
752 simulateFinalizePosition();
753
754 fgSetDouble("/sim/presets/longitude-deg", -9990.00);
755 fgSetDouble("/sim/presets/latitude-deg", -9990.00);
756 fgSetString("/sim/presets/airport-id", "EDDF");
757 fgSetDouble("/sim/presets/heading-deg", 9990.00);
758 fgSetString("/sim/presets/parkpos", "V266");
759 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
760 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/presets/parkpos") == "V266"s);
761
762 simulateStartReposition();
763 finalizePosition();
764
765 auto apt = FGAirport::getByIdent("EDDF");
766 auto parking = apt->groundNetwork()->findParkingByName("V266");
767 CPPUNIT_ASSERT(parking);
768 checkClosestAirport("EDDF"s);
769 checkPosition(parking->geod(), 10.0);
770 checkOnGround();
771
772 // now checking switching back to 'AVAILABLE'
773
774
775 fgSetDouble("/sim/presets/longitude-deg", -9990.00);
776 fgSetDouble("/sim/presets/latitude-deg", -9990.00);
777 fgSetString("/sim/presets/airport-id", "EDDF");
778 fgSetDouble("/sim/presets/heading-deg", 9990.00);
779 fgSetString("/sim/presets/parkpos", "AVAILABLE");
780 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
781 CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/presets/parkpos") == "AVAILABLE"s);
782
783 simulateStartReposition();
784 finalizePosition();
785
786 auto assignedParking = globals->get_props()->getStringValue("/sim/presets/parkpos");
787 CPPUNIT_ASSERT(assignedParking != "AVAILABLE");
788
789 parking = apt->groundNetwork()->findParkingByName(assignedParking);
790
791 checkClosestAirport("EDDF"s);
792 checkPosition(parking->geod(), 20.0);
793
794 }
795
796 void PosInitTests::testRepositionAtSameParking()
797 {
798 {
799 Options* opts = Options::sharedInstance();
800 opts->setShouldLoadDefaultConfig(false);
801
802 const char* args[] = {"dummypath", "--airport=EDDF", "--parkpos=V266"};
803 opts->init(3, (char**) args, SGPath());
804 opts->processOptions();
805 }
806
807 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
808 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
809
810 checkStringProp("/sim/presets/parkpos", "V266");
811 initPosition();
812
813 simulateFinalizePosition();
814
815 auto apt = FGAirport::getByIdent("EDDF");
816 auto parking = apt->groundNetwork()->findParkingByName("V266");
817 CPPUNIT_ASSERT(parking != nullptr);
818
819 checkClosestAirport("EDDF"s);
820 checkPosition(parking->geod(), 20);
821 /////////
822 fgSetDouble("/sim/presets/longitude-deg", -9990.00);
823 fgSetDouble("/sim/presets/latitude-deg", -9990.00);
824 fgSetString("/sim/presets/airport-id", "EDDF");
825 fgSetDouble("/sim/presets/heading-deg", 9990.00);
826 fgSetString("/sim/presets/parkpos", "V266");
827
828
829 simulateStartReposition();
830 finalizePosition();
831
832 checkPosition(parking->geod(), 20);
833
834 }
835
836
837 void PosInitTests::testRepositionAtOccupied()
838 {
839 {
840 Options* opts = Options::sharedInstance();
841 opts->setShouldLoadDefaultConfig(false);
842
843 const char* args[] = {"dummypath", "--airport=EDDF", "--parkpos=F235"};
844 opts->init(3, (char**) args, SGPath());
845 opts->processOptions();
846 }
847
848 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
849 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
850
851 checkStringProp("/sim/presets/parkpos", "F235");
852 initPosition();
853
854 auto apt = FGAirport::getByIdent("EDDF");
855 auto parking1 = apt->groundNetwork()->findParkingByName("F235");
856 CPPUNIT_ASSERT(parking1);
857
858 fgSetDouble("/environment/metar/base-wind-dir-deg", 350.0);
859 fgSetBool("/environment/metar/valid", true);
860
861 simulateFinalizePosition();
862
863 checkClosestAirport("EDDF"s);
864 checkPosition(parking1->geod(), 20);
865
866 //////////
867 fgSetDouble("/sim/presets/longitude-deg", -9990.00);
868 fgSetDouble("/sim/presets/latitude-deg", -9990.00);
869 fgSetString("/sim/presets/airport-id", "EDDF");
870 fgSetDouble("/sim/presets/heading-deg", 9990.00);
871 fgSetString("/sim/presets/parkpos", "V266");
872
873 auto parking2 = apt->groundNetwork()->findParkingByName("V266");
874 // now mark the parking as occupied
875 auto dynamics = apt->getDynamics();
876 dynamics->setParkingAvailable(parking2, false);
877
878 simulateStartReposition();
879 finalizePosition();
880
881 // we should be on the best runway, let's see
882 auto runway = apt->getRunwayByIdent("36");
883 checkPosition(runway->threshold());
884 }
885
886
887 void PosInitTests::testRepositionAtInvalid()
888 {
889 {
890 Options* opts = Options::sharedInstance();
891 opts->setShouldLoadDefaultConfig(false);
892
893 const char* args[] = {"dummypath", "--airport=EDDF", "--parkpos=F235"};
894 opts->init(3, (char**) args, SGPath());
895 opts->processOptions();
896 }
897
898 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
899 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
900
901 checkStringProp("/sim/presets/parkpos", "F235");
902 initPosition();
903
904 auto apt = FGAirport::getByIdent("EDDF");
905 auto parking1 = apt->groundNetwork()->findParkingByName("F235");
906 CPPUNIT_ASSERT(parking1);
907
908 fgSetDouble("/environment/metar/base-wind-dir-deg", 350.0);
909 fgSetBool("/environment/metar/valid", true);
910
911 simulateFinalizePosition();
912
913 checkClosestAirport("EDDF"s);
914 checkPosition(parking1->geod(), 20);
915
916 //////////
917 fgSetDouble("/sim/presets/longitude-deg", -9990.00);
918 fgSetDouble("/sim/presets/latitude-deg", -9990.00);
919 fgSetString("/sim/presets/airport-id", "EDDF");
920 fgSetDouble("/sim/presets/heading-deg", 9990.00);
921 fgSetString("/sim/presets/parkpos", "foobarzot");
922
923 simulateStartReposition();
924 finalizePosition();
925
926 // we should be on the best runway, let's see
927 auto runway = apt->getRunwayByIdent("36");
928 checkPosition(runway->threshold());
929 }
930
931 void PosInitTests::testMPRunwayStart()
932 {
933 {
934 Options* opts = Options::sharedInstance();
935 opts->setShouldLoadDefaultConfig(false);
936
937 // set dummy value to pretend MP is active
938 fgSetString("/sim/multiplay/txhost", "lalalal");
939
940 const char* args[] = {"dummypath", "--airport=EDDF", "--runway=07L"};
941 opts->init(3, (char**) args, SGPath());
942 opts->processOptions();
943
944 }
945
946 initPosition();
947
948 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
949 CPPUNIT_ASSERT(fgGetBool("/sim/presets/runway-requested"));
950 CPPUNIT_ASSERT(fgGetBool("/sim/presets/avoided-mp-runway"));
951
952 auto apt = FGAirport::getByIdent("EDDF");
953 FGGroundNetwork* groundNet = apt->groundNetwork();
954
955 auto rwy = apt->getRunwayByIdent("07L");
956 FGTaxiNodeRef taxiNode = groundNet->findNearestNodeOffRunway(rwy->threshold(), rwy, 50.0);
957 checkPosition(taxiNode->geod());
958 }
959
960 void PosInitTests::testMPRunwayStartNoGroundnet()
961 {
962 {
963 Options* opts = Options::sharedInstance();
964 opts->setShouldLoadDefaultConfig(false);
965
966 // set dummy value to pretend MP is active
967 fgSetString("/sim/multiplay/txhost", "lalalal");
968
969 const char* args[] = {"dummypath", "--airport=EDDS", "--runway=07"};
970 opts->init(3, (char**) args, SGPath());
971 opts->processOptions();
972 }
973
974 initPosition();
975
976 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
977 CPPUNIT_ASSERT(fgGetBool("/sim/presets/runway-requested"));
978 CPPUNIT_ASSERT(!fgGetBool("/sim/presets/avoided-mp-runway"));
979
980 auto apt = FGAirport::getByIdent("EDDS");
981 auto rwy = apt->getRunwayByIdent("07");
982 checkPosition(rwy->threshold());
983 }
984
985 void PosInitTests::testParkNoAI()
986 {
987 fgSetBool("/sim/traffic-manager/enabled", false);
988 {
989 Options* opts = Options::sharedInstance();
990 opts->setShouldLoadDefaultConfig(false);
991
992 const char* args[] = {"dummypath", "--airport=EDDF", "--parkpos=F235"};
993 opts->init(3, (char**) args, SGPath());
994 opts->processOptions();
995 }
996
997 CPPUNIT_ASSERT(!fgGetBool("/sim/traffic-manager/enabled"));
998 CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
999 CPPUNIT_ASSERT(! fgGetBool("/sim/presets/runway-requested"));
1000
1001 checkStringProp("/sim/presets/parkpos", "F235");
1002 initPosition();
1003
1004 auto apt = FGAirport::getByIdent("EDDF");
1005 auto parking1 = apt->groundNetwork()->findParkingByName("F235");
1006 CPPUNIT_ASSERT(parking1);
1007
1008 fgSetDouble("/environment/metar/base-wind-dir-deg", 350.0);
1009 fgSetBool("/environment/metar/valid", true);
1010
1011 simulateFinalizePosition();
1012
1013 checkClosestAirport("EDDF"s);
1014 checkPosition(parking1->geod(), 20);
1015
1016 //////////
1017 fgSetDouble("/sim/presets/longitude-deg", -9990.00);
1018 fgSetDouble("/sim/presets/latitude-deg", -9990.00);
1019 fgSetString("/sim/presets/airport-id", "EDDF");
1020 fgSetDouble("/sim/presets/heading-deg", 9990.00);
1021 fgSetString("/sim/presets/parkpos", "foobarzot");
1022
1023 simulateStartReposition();
1024 finalizePosition();
1025
1026 // we should be on the best runway, let's see
1027 auto runway = apt->getRunwayByIdent("36");
1028 checkPosition(runway->threshold());
1029 }