| 1 | /* |
| 2 | * SPDX-FileCopyrightText: 2021 Keith Paterson |
| 3 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | */ |
| 5 | |
| 6 | #include "config.h" |
| 7 | |
| 8 | #include "test_airport.hxx" |
| 9 | |
| 10 | #include <iostream> |
| 11 | #include <cstring> |
| 12 | #include <memory> |
| 13 | |
| 14 | #include "test_suite/FGTestApi/NavDataCache.hxx" |
| 15 | #include "test_suite/FGTestApi/TestDataLogger.hxx" |
| 16 | #include "test_suite/FGTestApi/testGlobals.hxx" |
| 17 | |
| 18 | #include <simgear/math/sg_geodesy.hxx> |
| 19 | #include <simgear/math/SGGeod.hxx> |
| 20 | #include <AIModel/AIAircraft.hxx> |
| 21 | #include <AIModel/AIFlightPlan.hxx> |
| 22 | #include <AIModel/AIManager.hxx> |
| 23 | #include <AIModel/performancedb.hxx> |
| 24 | |
| 25 | #include <Airports/airport.hxx> |
| 26 | #include <Airports/airportdynamicsmanager.hxx> |
| 27 | #include <Airports/runways.hxx> |
| 28 | #include <Traffic/TrafficMgr.hxx> |
| 29 | #include <Time/TimeManager.hxx> |
| 30 | |
| 31 | #include <ATC/atc_mgr.hxx> |
| 32 | |
| 33 | #include <Main/fg_props.hxx> |
| 34 | #include <Main/globals.hxx> |
| 35 | |
| 36 | ///////////////////////////////////////////////////////////////////////////// |
| 37 | |
| 38 | // Set up function for each test. |
| 39 | void AirportTests::setUp() |
| 40 | { |
| 41 | FGTestApi::setUp::initTestGlobals("Airports"); |
| 42 | FGTestApi::setUp::initNavDataCache(); |
| 43 | |
| 44 | globals->get_subsystem_mgr()->bind(); |
| 45 | globals->get_subsystem_mgr()->init(); |
| 46 | FGTestApi::setUp::initStandardNasal(); |
| 47 | globals->get_subsystem_mgr()->postinit(); |
| 48 | } |
| 49 | |
| 50 | // Clean up after each test. |
| 51 | void AirportTests::tearDown() |
| 52 | { |
| 53 | FGTestApi::tearDown::shutdownTestGlobals(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @brief Read an airport from the apt.dat |
| 58 | * |
| 59 | */ |
| 60 | void AirportTests::testAirport() |
| 61 | { |
| 62 | FGAirportRef departureAirport = FGAirport::getByIdent("YSSY"); |
| 63 | CPPUNIT_ASSERT_EQUAL_MESSAGE("Must have correct id", (std::string)"YSSY", departureAirport->getId()); |
| 64 | CPPUNIT_ASSERT_EQUAL_MESSAGE("Must have runways", (unsigned int) 6, departureAirport->numRunways()); |
| 65 | CPPUNIT_ASSERT_EQUAL_MESSAGE("Must have runway 16R", true, departureAirport->hasRunwayWithIdent("16R")); |
| 66 | |
| 67 | int length = 3962; |
| 68 | |
| 69 | FGRunwayRef runway = departureAirport->getRunwayByIdent("16R"); |
| 70 | int calculated = SGGeodesy::distanceM(runway->begin(), runway->end()); |
| 71 | CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Distance between the runway endpoints should be runway length", length, calculated, 1); |
| 72 | calculated = SGGeodesy::distanceM(runway->begin(), runway->pointOnCenterline(-length)); |
| 73 | CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Distance between the runway start and point on centerline should be runway length", length, calculated, 1); |
| 74 | |
| 75 | } |
| 76 | |
| 77 | void AirportTests::testAirportNasal() |
| 78 | { |
| 79 | bool ok = FGTestApi::executeNasal(R"( |
| 80 | var apt = airportinfo('EGCC'); |
| 81 | var rwy = apt.runways['05R']; |
| 82 | unitTest.assert_doubles_equal(rwy.heading, 51, 0.1); |
| 83 | |
| 84 | var mag = magvar(apt); |
| 85 | unitTest.assert_doubles_equal(rwy.magnetic_heading, 51 - mag, 0.1); |
| 86 | )"); |
| 87 | CPPUNIT_ASSERT(ok); |
| 88 | } |