| 1 | #include "test_fpNasal.hxx" |
| 2 | |
| 3 | #include "test_suite/FGTestApi/testGlobals.hxx" |
| 4 | #include "test_suite/FGTestApi/NavDataCache.hxx" |
| 5 | |
| 6 | #include <simgear/misc/strutils.hxx> |
| 7 | #include <simgear/timing/sg_time.hxx> |
| 8 | |
| 9 | #include <Navaids/FlightPlan.hxx> |
| 10 | #include <Navaids/routePath.hxx> |
| 11 | #include <Navaids/NavDataCache.hxx> |
| 12 | #include <Navaids/waypoint.hxx> |
| 13 | #include <Navaids/navlist.hxx> |
| 14 | #include <Navaids/navrecord.hxx> |
| 15 | #include <Navaids/airways.hxx> |
| 16 | #include <Navaids/fix.hxx> |
| 17 | |
| 18 | #include <Airports/airport.hxx> |
| 19 | #include <Autopilot/route_mgr.hxx> |
| 20 | |
| 21 | #include <Main/globals.hxx> |
| 22 | |
| 23 | using namespace flightgear; |
| 24 | using namespace std::string_literals; |
| 25 | |
| 26 | static bool static_haveProcedures = false; |
| 27 | |
| 28 | // Set up function for each test. |
| 29 | void FPNasalTests::setUp() |
| 30 | { |
| 31 | FGTestApi::setUp::initTestGlobals("flightplan"); |
| 32 | FGTestApi::setUp::initNavDataCache(); |
| 33 | |
| 34 | SGPath proceduresPath = SGPath::fromEnv("FG_PROCEDURES_PATH"); |
| 35 | if (proceduresPath.exists()) { |
| 36 | static_haveProcedures = true; |
| 37 | globals->append_fg_scenery(proceduresPath); |
| 38 | } |
| 39 | |
| 40 | // flightplan() acces needs the route manager |
| 41 | globals->get_subsystem_mgr()->add<FGRouteMgr>(); |
| 42 | |
| 43 | globals->get_subsystem_mgr()->bind(); |
| 44 | globals->get_subsystem_mgr()->init(); |
| 45 | |
| 46 | FGTestApi::setUp::initStandardNasal(); |
| 47 | globals->get_subsystem_mgr()->postinit(); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | // Clean up after each test. |
| 52 | void FPNasalTests::tearDown() |
| 53 | { |
| 54 | FGTestApi::tearDown::shutdownTestGlobals(); |
| 55 | } |
| 56 | |
| 57 | static FlightPlanRef makeTestFP(const std::string& depICAO, const std::string& depRunway, |
| 58 | const std::string& destICAO, const std::string& destRunway, |
| 59 | const std::string& waypoints) |
| 60 | { |
| 61 | FlightPlanRef f = FlightPlan::create(); |
| 62 | FGTestApi::setUp::populateFPWithNasal(f, depICAO, depRunway, destICAO, destRunway, waypoints); |
| 63 | return f; |
| 64 | } |
| 65 | |
| 66 | void FPNasalTests::testBasic() |
| 67 | { |
| 68 | |
| 69 | FlightPlanRef fp1 = makeTestFP("EGCC", "23L", "EHAM", "24", |
| 70 | "TNT CLN"); |
| 71 | fp1->setIdent("testplan"); |
| 72 | |
| 73 | // setup the FP on the route-manager, so flightplan() call works |
| 74 | auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 75 | rm->setFlightPlan(fp1); |
| 76 | rm->activate(); |
| 77 | |
| 78 | // modify leg data dfrom Nasal |
| 79 | bool ok = FGTestApi::executeNasal(R"( |
| 80 | var fp = flightplan(); # retrieve the global flightplan |
| 81 | var leg = fp.getWP(3); |
| 82 | leg.setAltitude(6000, 'AT'); |
| 83 | )"); |
| 84 | CPPUNIT_ASSERT(ok); |
| 85 | |
| 86 | // check the value updated in the leg |
| 87 | CPPUNIT_ASSERT_EQUAL(RESTRICT_AT, fp1->legAtIndex(3)->altitudeRestriction()); |
| 88 | CPPUNIT_ASSERT_EQUAL(6000, fp1->legAtIndex(3)->altitudeFt()); |
| 89 | |
| 90 | // insert some waypoints from Nasal |
| 91 | |
| 92 | ok = FGTestApi::executeNasal(R"( |
| 93 | var fp = flightplan(); |
| 94 | var leg = fp.getWP(2); |
| 95 | var newWP = createWPFrom(navinfo(leg.lat, leg.lon, 'COA')[0]); |
| 96 | fp.insertWPAfter(newWP, 2); |
| 97 | )"); |
| 98 | CPPUNIT_ASSERT(ok); |
| 99 | |
| 100 | CPPUNIT_ASSERT_EQUAL("COSTA VOR-DME"s, fp1->legAtIndex(3)->waypoint()->source()->name()); |
| 101 | |
| 102 | ok = FGTestApi::executeNasal(R"( |
| 103 | var fp = flightplan(); |
| 104 | fp.clearAll(); |
| 105 | unitTest.assert_equal(fp.getPlanSize(), 0); |
| 106 | unitTest.assert_equal(fp.current, -1); |
| 107 | unitTest.assert_equal(fp.departure, nil); |
| 108 | unitTest.assert_equal(fp.sid, nil); |
| 109 | unitTest.assert_equal(fp.cruiseSpeedKt, 0); |
| 110 | )"); |
| 111 | CPPUNIT_ASSERT(ok); |
| 112 | } |
| 113 | |
| 114 | void FPNasalTests::testRestrictions() |
| 115 | { |
| 116 | FlightPlanRef fp1 = makeTestFP("EGCC", "23L", "EHAM", "24", |
| 117 | "TNT CLN"); |
| 118 | fp1->setIdent("testplan"); |
| 119 | |
| 120 | // setup the FP on the route-manager, so flightplan() call works |
| 121 | auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 122 | rm->setFlightPlan(fp1); |
| 123 | rm->activate(); |
| 124 | |
| 125 | // modify leg data dfrom Nasal |
| 126 | bool ok = FGTestApi::executeNasal(R"( |
| 127 | var fp = flightplan(); # retrieve the global flightplan |
| 128 | var leg = fp.getWP(3); |
| 129 | leg.setAltitude(6000, 'AT'); |
| 130 | )"); |
| 131 | CPPUNIT_ASSERT(ok); |
| 132 | |
| 133 | // check the value updated in the leg |
| 134 | CPPUNIT_ASSERT_EQUAL(RESTRICT_AT, fp1->legAtIndex(3)->altitudeRestriction()); |
| 135 | CPPUNIT_ASSERT_EQUAL(6000, fp1->legAtIndex(3)->altitudeFt()); |
| 136 | |
| 137 | ok = FGTestApi::executeNasal(R"( |
| 138 | var fp = flightplan(); # retrieve the global flightplan |
| 139 | var leg = fp.getWP(3); |
| 140 | leg.setAltitude(6000, 'above'); |
| 141 | )"); |
| 142 | CPPUNIT_ASSERT(ok); |
| 143 | |
| 144 | CPPUNIT_ASSERT_EQUAL(RESTRICT_ABOVE, fp1->legAtIndex(3)->altitudeRestriction()); |
| 145 | CPPUNIT_ASSERT_EQUAL(6000, fp1->legAtIndex(3)->altitudeFt()); |
| 146 | |
| 147 | ok = FGTestApi::executeNasal(R"( |
| 148 | var fp = flightplan(); # retrieve the global flightplan |
| 149 | var leg = fp.getWP(3); |
| 150 | leg.setAltitude(6000, 'below'); |
| 151 | )"); |
| 152 | CPPUNIT_ASSERT(ok); |
| 153 | |
| 154 | CPPUNIT_ASSERT_EQUAL(RESTRICT_BELOW, fp1->legAtIndex(3)->altitudeRestriction()); |
| 155 | CPPUNIT_ASSERT_EQUAL(6000, fp1->legAtIndex(3)->altitudeFt()); |
| 156 | |
| 157 | ok = FGTestApi::executeNasal(R"( |
| 158 | var fp = flightplan(); # retrieve the global flightplan |
| 159 | var leg = fp.getWP(3); |
| 160 | leg.setAltitude(6000, 'delete'); |
| 161 | )"); |
| 162 | CPPUNIT_ASSERT(ok); |
| 163 | |
| 164 | CPPUNIT_ASSERT_EQUAL(RESTRICT_DELETE, fp1->legAtIndex(3)->altitudeRestriction()); |
| 165 | |
| 166 | ok = FGTestApi::executeNasal(R"( |
| 167 | var fp = flightplan(); # retrieve the global flightplan |
| 168 | var leg = fp.getWP(3); |
| 169 | leg.setSpeed(250, 'at'); |
| 170 | )"); |
| 171 | CPPUNIT_ASSERT(ok); |
| 172 | |
| 173 | CPPUNIT_ASSERT_EQUAL(RESTRICT_AT, fp1->legAtIndex(3)->speedRestriction()); |
| 174 | CPPUNIT_ASSERT_EQUAL(250, fp1->legAtIndex(3)->speedKts()); |
| 175 | |
| 176 | ok = FGTestApi::executeNasal(R"( |
| 177 | var fp = flightplan(); # retrieve the global flightplan |
| 178 | var leg = fp.getWP(3); |
| 179 | leg.setSpeed(250, 'above'); |
| 180 | )"); |
| 181 | CPPUNIT_ASSERT(ok); |
| 182 | |
| 183 | CPPUNIT_ASSERT_EQUAL(RESTRICT_ABOVE, fp1->legAtIndex(3)->speedRestriction()); |
| 184 | CPPUNIT_ASSERT_EQUAL(250, fp1->legAtIndex(3)->speedKts()); |
| 185 | |
| 186 | ok = FGTestApi::executeNasal(R"( |
| 187 | var fp = flightplan(); # retrieve the global flightplan |
| 188 | var leg = fp.getWP(3); |
| 189 | leg.setSpeed(250, 'below'); |
| 190 | )"); |
| 191 | CPPUNIT_ASSERT(ok); |
| 192 | |
| 193 | CPPUNIT_ASSERT_EQUAL(RESTRICT_BELOW, fp1->legAtIndex(3)->speedRestriction()); |
| 194 | CPPUNIT_ASSERT_EQUAL(250, fp1->legAtIndex(3)->speedKts()); |
| 195 | |
| 196 | ok = FGTestApi::executeNasal(R"( |
| 197 | var fp = flightplan(); # retrieve the global flightplan |
| 198 | var leg = fp.getWP(3); |
| 199 | leg.setSpeed(250, 'delete'); |
| 200 | )"); |
| 201 | CPPUNIT_ASSERT(ok); |
| 202 | |
| 203 | CPPUNIT_ASSERT_EQUAL(RESTRICT_DELETE, fp1->legAtIndex(3)->speedRestriction()); |
| 204 | |
| 205 | ok = FGTestApi::executeNasal(R"( |
| 206 | var fp = flightplan(); # retrieve the global flightplan |
| 207 | var leg = fp.getWP(3); |
| 208 | leg.setSpeed(0.8, 'at', "Mach"); |
| 209 | leg.setAltitude(300, 'above', 'FL'); |
| 210 | )"); |
| 211 | CPPUNIT_ASSERT(ok); |
| 212 | |
| 213 | CPPUNIT_ASSERT_EQUAL(RESTRICT_AT, fp1->legAtIndex(3)->speedRestriction()); |
| 214 | CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8, fp1->legAtIndex(3)->speedMach(), 0.01); |
| 215 | CPPUNIT_ASSERT_EQUAL(RESTRICT_ABOVE, fp1->legAtIndex(3)->altitudeRestriction()); |
| 216 | CPPUNIT_ASSERT_DOUBLES_EQUAL(30000, fp1->legAtIndex(3)->altitudeFt(), 1.0); |
| 217 | } |
| 218 | |
| 219 | void FPNasalTests::testSegfaultWaypointGhost() |
| 220 | { |
| 221 | // checking for a segfault here, no segfault indicates success. A runtime error in the log is acceptable here. |
| 222 | bool ok = FGTestApi::executeNasal(R"( |
| 223 | var fp = createFlightplan(); |
| 224 | fp.departure = airportinfo("BIKF"); |
| 225 | fp.destination = airportinfo("EGLL"); |
| 226 | var wp = fp.getWP(1); |
| 227 | fp.deleteWP(1); |
| 228 | print(wp.wp_name); |
| 229 | )"); |
| 230 | CPPUNIT_ASSERT(ok); |
| 231 | } |
| 232 | |
| 233 | void FPNasalTests::testSIDTransitionAPI() |
| 234 | { |
| 235 | if (!static_haveProcedures) { |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 240 | |
| 241 | bool ok = FGTestApi::executeNasal(R"( |
| 242 | var fp = flightplan(); |
| 243 | fp.departure = airportinfo("KJFK"); |
| 244 | fp.destination = airportinfo("EGLL"); |
| 245 | |
| 246 | var sid = fp.departure.getSid("DEEZZ5.13L"); |
| 247 | |
| 248 | unitTest.assert(sid != nil, "SID not found"); |
| 249 | unitTest.assert_equal(sid.id, "DEEZZ5.13L", "Incorrect SID loaded"); |
| 250 | |
| 251 | var trans = sid.transition('CANDR'); |
| 252 | unitTest.assert_equal(trans.id, "CANDR", "Couldn't find transition"); |
| 253 | unitTest.assert_equal(trans.tp_type, "transition", "Procedure type incorrect"); |
| 254 | |
| 255 | fp.sid = trans; |
| 256 | fp.departure_runway = fp.departure.runway('13L') |
| 257 | )"); |
| 258 | |
| 259 | CPPUNIT_ASSERT(ok); |
| 260 | |
| 261 | auto fp = rm->flightPlan(); |
| 262 | |
| 263 | CPPUNIT_ASSERT(fp->departureRunway()); |
| 264 | CPPUNIT_ASSERT(fp->sid()); |
| 265 | CPPUNIT_ASSERT(fp->sidTransition()); |
| 266 | |
| 267 | CPPUNIT_ASSERT_EQUAL(fp->departureRunway()->ident(), "13L"s); |
| 268 | CPPUNIT_ASSERT_EQUAL(fp->sid()->ident(), "DEEZZ5.13L"s); |
| 269 | CPPUNIT_ASSERT_EQUAL(fp->sidTransition()->ident(), "CANDR"s); |
| 270 | |
| 271 | // test specify SID via transition in Nasal |
| 272 | rm->setFlightPlan(FlightPlan::create()); |
| 273 | |
| 274 | ok = FGTestApi::executeNasal(R"( |
| 275 | var fp = flightplan(); |
| 276 | fp.departure = airportinfo("KJFK"); |
| 277 | fp.destination = airportinfo("EGLL"); |
| 278 | fp.departure_runway = airportinfo("KJFK").runways["13L"]; |
| 279 | fp.sid = airportinfo("KJFK").getSid("DEEZZ5.13L"); |
| 280 | fp.sid_trans = "CANDR"; |
| 281 | |
| 282 | )"); |
| 283 | |
| 284 | CPPUNIT_ASSERT(ok); |
| 285 | |
| 286 | fp = rm->flightPlan(); |
| 287 | |
| 288 | CPPUNIT_ASSERT(fp->departureRunway()); |
| 289 | CPPUNIT_ASSERT(fp->sid()); |
| 290 | CPPUNIT_ASSERT(fp->sidTransition()); |
| 291 | |
| 292 | CPPUNIT_ASSERT_EQUAL(fp->departureRunway()->ident(), "13L"s); |
| 293 | CPPUNIT_ASSERT_EQUAL(fp->sid()->ident(), "DEEZZ5.13L"s); |
| 294 | CPPUNIT_ASSERT_EQUAL(fp->sidTransition()->ident(), "CANDR"s); |
| 295 | } |
| 296 | |
| 297 | void FPNasalTests::testSTARTransitionAPI() |
| 298 | { |
| 299 | if (!static_haveProcedures) { |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 304 | |
| 305 | bool ok = FGTestApi::executeNasal(R"( |
| 306 | var fp = flightplan(); |
| 307 | fp.departure = airportinfo("EGLL"); |
| 308 | fp.destination = airportinfo("EDDM"); |
| 309 | |
| 310 | var star = fp.destination.getStar("RIXE3A.26L"); |
| 311 | |
| 312 | unitTest.assert(star != nil, "STAR not found"); |
| 313 | unitTest.assert_equal(star.id, "RIXE3A.26L", "Incorrect STAR loaded"); |
| 314 | |
| 315 | |
| 316 | fp.star = star; |
| 317 | fp.destination_runway = fp.destination.runway('26L') |
| 318 | )"); |
| 319 | |
| 320 | CPPUNIT_ASSERT(ok); |
| 321 | |
| 322 | auto fp = rm->flightPlan(); |
| 323 | |
| 324 | CPPUNIT_ASSERT(fp->star()); |
| 325 | CPPUNIT_ASSERT(fp->starTransition() == nullptr); |
| 326 | |
| 327 | CPPUNIT_ASSERT_EQUAL(fp->star()->ident(), "RIXE3A.26L"s); |
| 328 | } |
| 329 | |
| 330 | void FPNasalTests::testApproachTransitionAPI() |
| 331 | { |
| 332 | if (!static_haveProcedures) { |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 337 | |
| 338 | bool ok = FGTestApi::executeNasal(R"( |
| 339 | var fp = flightplan(); |
| 340 | fp.departure = airportinfo("EGLL"); |
| 341 | fp.destination = airportinfo("EDDM"); |
| 342 | |
| 343 | var star = fp.destination.getStar("RIXE3A.08L"); |
| 344 | |
| 345 | unitTest.assert(star != nil, "STAR not found"); |
| 346 | unitTest.assert_equal(star.id, "RIXE3A.08L", "Incorrect STAR loaded"); |
| 347 | |
| 348 | fp.star = star; |
| 349 | fp.destination_runway = fp.destination.runway('08L'); |
| 350 | |
| 351 | var approach = fp.destination.getApproach("ILS08L"); |
| 352 | unitTest.assert(approach != nil, "No approach loaded"); |
| 353 | |
| 354 | var trans = approach.transition('LUL1C'); |
| 355 | |
| 356 | unitTest.assert(trans != nil, "approach transition not found"); |
| 357 | unitTest.assert_equal(trans.id, "LUL1C", "Incorrect approach transition loaded"); |
| 358 | unitTest.assert_equal(trans.tp_type, "transition", "Procedure type incorrect"); |
| 359 | |
| 360 | fp.approach = trans; |
| 361 | |
| 362 | unitTest.assert_equal(fp.approach.id, "ILS08L", "Incorrect approach returned"); |
| 363 | unitTest.assert_equal(fp.approach_trans.id, "LUL1C", "Incorrect transition returned"); |
| 364 | unitTest.assert_equal(fp.approach_trans.tp_type, "transition", "Procedure type incorrect"); |
| 365 | )"); |
| 366 | |
| 367 | CPPUNIT_ASSERT(ok); |
| 368 | |
| 369 | auto fp = rm->flightPlan(); |
| 370 | |
| 371 | CPPUNIT_ASSERT(fp->approach()); |
| 372 | CPPUNIT_ASSERT_EQUAL("LUL1C"s, fp->approachTransition()->ident()); |
| 373 | CPPUNIT_ASSERT_EQUAL("ILS08L"s, fp->approach()->ident()); |
| 374 | } |
| 375 | |
| 376 | void FPNasalTests::testApproachTransitionAPIWithCloning() |
| 377 | { |
| 378 | if (!static_haveProcedures) { |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 383 | |
| 384 | bool ok = FGTestApi::executeNasal(R"( |
| 385 | var fp = flightplan(); |
| 386 | fp.departure = airportinfo("EGLL"); |
| 387 | fp.destination = airportinfo("EHAM"); |
| 388 | fp.star = fp.destination.getStar("REDF1A"); |
| 389 | fp.destination_runway = fp.destination.runway('06'); |
| 390 | |
| 391 | var approach = fp.destination.getApproach("ILS06"); |
| 392 | unitTest.assert(approach != nil, "No approach loaded"); |
| 393 | |
| 394 | var trans = approach.transition('SUG2A'); |
| 395 | unitTest.assert(trans != nil, "approach transition not found"); |
| 396 | |
| 397 | fp.approach = trans; |
| 398 | |
| 399 | unitTest.assert_equal(fp.approach.id, "ILS06", "Incorrect approach returned"); |
| 400 | unitTest.assert_equal(fp.approach_trans.id, "SUG2A", "Incorrect transition returned"); |
| 401 | unitTest.assert_equal(fp.approach_trans.tp_type, "transition", "Procedure type incorrect"); |
| 402 | )"); |
| 403 | |
| 404 | CPPUNIT_ASSERT(ok); |
| 405 | |
| 406 | auto fp = rm->flightPlan(); |
| 407 | |
| 408 | CPPUNIT_ASSERT(fp->approach()); |
| 409 | CPPUNIT_ASSERT_EQUAL("SUG2A"s, fp->approachTransition()->ident()); |
| 410 | CPPUNIT_ASSERT_EQUAL("ILS06"s, fp->approach()->ident()); |
| 411 | |
| 412 | auto fp2 = fp->clone("testplan2"); |
| 413 | CPPUNIT_ASSERT_EQUAL("ILS06"s, fp2->approach()->ident()); |
| 414 | CPPUNIT_ASSERT_EQUAL("SUG2A"s, fp2->approachTransition()->ident()); |
| 415 | } |
| 416 | |
| 417 | void FPNasalTests::testAirwaysAPI() |
| 418 | { |
| 419 | bool ok = FGTestApi::executeNasal(R"( |
| 420 | var airwayIdent = "L620"; |
| 421 | var airwayStore = airway(airwayIdent, "low"); |
| 422 | unitTest.assert(airwayStore != nil, "Airway " ~ airwayIdent ~ " not found"); |
| 423 | unitTest.assert(airwayStore.id == airwayIdent, "Incorrect airway found"); |
| 424 | unitTest.assert_equal(airwayStore.level, 'low', "Incorrect airway found"); |
| 425 | unitTest.assert_equal(airwayStore.level_code, Airway.LOW, "Incorrect airway found"); |
| 426 | |
| 427 | airwayIdent = "UL620"; |
| 428 | var cln = findNavaidsByID("CLN", "VOR")[0]; |
| 429 | airwayStore = airway(airwayIdent, cln); |
| 430 | unitTest.assert(airwayStore != nil, "Airway " ~ airwayIdent ~ " not found"); |
| 431 | unitTest.assert(airwayStore.id == airwayIdent, "Incorrect airway found"); |
| 432 | unitTest.assert_equal(airwayStore.level_code, Airway.HIGH, "Incorrect airway found"); |
| 433 | |
| 434 | airwayIdent = "J547"; |
| 435 | airwayStore = airway(airwayIdent); |
| 436 | unitTest.assert(airwayStore != nil, "Airway " ~ airwayIdent ~ " not found"); |
| 437 | unitTest.assert(airwayStore.id == airwayIdent, "Incorrect airway found"); |
| 438 | )"); |
| 439 | |
| 440 | CPPUNIT_ASSERT(ok); |
| 441 | |
| 442 | ok = FGTestApi::executeNasal(R"( |
| 443 | |
| 444 | var airwayIdent = "L620"; |
| 445 | var airwayStore = airway(airwayIdent, Airway.LOW); |
| 446 | var cln = findNavaidsByID("CLN", "VOR")[0]; |
| 447 | |
| 448 | var v1 = createViaTo(airwayIdent, "CLN"); |
| 449 | unitTest.assert_equal(v1.wp_type, "via"); |
| 450 | unitTest.assert_equal(v1.airway.id, 'L620'); |
| 451 | unitTest.assert_equal(v1.airway.level_code, Airway.LOW); |
| 452 | |
| 453 | var v2 = createViaTo(airwayStore, "TULIP"); |
| 454 | unitTest.assert_equal(v2.wp_type, "via"); |
| 455 | unitTest.assert_equal(v2.airway.id, airwayIdent); |
| 456 | |
| 457 | var v3 = createViaFromTo(cln, "L620", 'low', "TULIP"); |
| 458 | unitTest.assert_equal(v3.airway.id, 'L620'); |
| 459 | |
| 460 | var v4 = createViaFromTo(cln, "L620", "REDFA"); |
| 461 | unitTest.assert_equal(v4.airway.level_code, Airway.LOW); |
| 462 | |
| 463 | # test direct API (no Vias) |
| 464 | var wps = airwayStore.viaWaypoints(cln, "TULIP"); |
| 465 | unitTest.assert_equal(size(wps), 3); |
| 466 | |
| 467 | unitTest.assert_equal(wps[1].wp_ident, 'REDFA'); |
| 468 | unitTest.assert_equal(wps[1].airway.ident, 'L620'); |
| 469 | |
| 470 | )"); |
| 471 | |
| 472 | CPPUNIT_ASSERT(ok); |
| 473 | |
| 474 | } |
| 475 | |
| 476 | void FPNasalTests::testTotalDistanceAPI() |
| 477 | { |
| 478 | auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 479 | |
| 480 | bool ok = FGTestApi::executeNasal(R"( |
| 481 | var fp = flightplan(); |
| 482 | fp.departure = airportinfo("BIKF"); |
| 483 | fp.destination = airportinfo("EGLL"); |
| 484 | unitTest.assert_doubles_equal(1025.9, fp.totalDistanceNm, 0.1, "Distance assertion failed"); |
| 485 | )"); |
| 486 | |
| 487 | CPPUNIT_ASSERT(ok); |
| 488 | |
| 489 | auto fp = rm->flightPlan(); |
| 490 | CPPUNIT_ASSERT_DOUBLES_EQUAL(fp->totalDistanceNm(), 1025.9, 0.1); |
| 491 | } |
| 492 | |
| 493 | void FPNasalTests::testRunwayMagVar() |
| 494 | { |
| 495 | auto kclt = FGAirport::getByIdent("KCLT"); |
| 496 | globals->get_time_params()->update(kclt->geod(), 1773677431, 0); |
| 497 | bool ok = FGTestApi::executeNasal(R"( |
| 498 | var rwy18C = airportinfo("KCLT").runway("18C"); |
| 499 | unitTest.assert_doubles_equal(rwy18C.magnetic_heading, 184.1, 0.1, "Magnetic heading is not correct"); |
| 500 | )"); |
| 501 | |
| 502 | CPPUNIT_ASSERT(ok); |
| 503 | } |