| 1 | /* |
| 2 | * Copyright (C) 2021 Keith Paterson |
| 3 | * |
| 4 | * This file is part of the program FlightGear. |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "config.h" |
| 21 | |
| 22 | #include "test_groundnet.hxx" |
| 23 | |
| 24 | #include <cstring> |
| 25 | #include <memory> |
| 26 | #include <iostream> |
| 27 | |
| 28 | |
| 29 | #include "test_suite/FGTestApi/NavDataCache.hxx" |
| 30 | #include "test_suite/FGTestApi/TestDataLogger.hxx" |
| 31 | #include "test_suite/FGTestApi/testGlobals.hxx" |
| 32 | |
| 33 | #include <AIModel/AIAircraft.hxx> |
| 34 | #include <AIModel/AIFlightPlan.hxx> |
| 35 | #include <AIModel/AIManager.hxx> |
| 36 | #include <AIModel/performancedb.hxx> |
| 37 | #include <Airports/airport.hxx> |
| 38 | #include <Airports/airportdynamicsmanager.hxx> |
| 39 | #include <Airports/groundnetwork.hxx> |
| 40 | #include <Airports/parking.hxx> |
| 41 | #include <Traffic/TrafficMgr.hxx> |
| 42 | |
| 43 | #include <ATC/atc_mgr.hxx> |
| 44 | |
| 45 | #include <Main/fg_props.hxx> |
| 46 | #include <Main/globals.hxx> |
| 47 | |
| 48 | ///////////////////////////////////////////////////////////////////////////// |
| 49 | |
| 50 | // Set up function for each test. |
| 51 | void GroundnetTests::setUp() |
| 52 | { |
| 53 | FGTestApi::setUp::initTestGlobals("Traffic"); |
| 54 | FGTestApi::setUp::initNavDataCache(); |
| 55 | |
| 56 | |
| 57 | auto props = globals->get_props(); |
| 58 | props->setBoolValue("sim/ai/enabled", true); |
| 59 | props->setBoolValue("sim/signals/fdm-initialized", false); |
| 60 | |
| 61 | |
| 62 | // ensure EGPH has a valid ground net for parking testing |
| 63 | FGAirport::clearAirportsCache(); |
| 64 | FGAirportRef egph = FGAirport::getByIdent("EGPH"); |
| 65 | egph->testSuiteInjectGroundnetXML(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "EGPH.groundnet.xml"); |
| 66 | |
| 67 | FGAirportRef ybbn = FGAirport::getByIdent("YBBN"); |
| 68 | ybbn->testSuiteInjectGroundnetXML(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "YBBN.groundnet.xml"); |
| 69 | |
| 70 | |
| 71 | globals->get_subsystem_mgr()->add<PerformanceDB>(); |
| 72 | globals->get_subsystem_mgr()->add<FGATCManager>(); |
| 73 | globals->get_subsystem_mgr()->add<FGAIManager>(); |
| 74 | globals->get_subsystem_mgr()->add<flightgear::AirportDynamicsManager>(); |
| 75 | |
| 76 | globals->get_subsystem_mgr()->bind(); |
| 77 | globals->get_subsystem_mgr()->init(); |
| 78 | globals->get_subsystem_mgr()->postinit(); |
| 79 | } |
| 80 | |
| 81 | // Clean up after each test. |
| 82 | void GroundnetTests::tearDown() |
| 83 | { |
| 84 | FGTestApi::tearDown::shutdownTestGlobals(); |
| 85 | } |
| 86 | |
| 87 | void GroundnetTests::testShortestRoute() |
| 88 | { |
| 89 | FGAirportRef egph = FGAirport::getByIdent("EGPH"); |
| 90 | |
| 91 | FGGroundNetwork* network = egph->groundNetwork(); |
| 92 | FGParkingRef startParking = network->findParkingByName("main-apron10"); |
| 93 | FGRunwayRef runway = egph->getRunwayByIndex(0); |
| 94 | FGTaxiNodeRef end = network->findNearestNodeOnRunwayEntry(runway->threshold()); |
| 95 | FGTaxiRoute route = network->findShortestRoute(startParking, end); |
| 96 | CPPUNIT_ASSERT_EQUAL(true, network->exists()); |
| 97 | CPPUNIT_ASSERT_EQUAL(29, route.size()); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Tests various find methods. |
| 102 | */ |
| 103 | |
| 104 | void GroundnetTests::testFind() |
| 105 | { |
| 106 | FGAirportRef ybbn = FGAirport::getByIdent("YBBN"); |
| 107 | |
| 108 | FGGroundNetwork* network = ybbn->groundNetwork(); |
| 109 | FGParkingRef startParking = network->findParkingByName("GA1"); |
| 110 | CPPUNIT_ASSERT_EQUAL(1020, startParking->getIndex()); |
| 111 | FGTaxiSegment* segment1 = network->findSegment(startParking, NULL); |
| 112 | CPPUNIT_ASSERT(segment1); |
| 113 | FGTaxiSegment* segment2 = network->findSegment(startParking, segment1->getEnd()); |
| 114 | CPPUNIT_ASSERT(segment2); |
| 115 | FGTaxiNodeVector segmentList = network->findSegmentsFrom(startParking); |
| 116 | CPPUNIT_ASSERT_EQUAL(2, (int)segmentList.size()); |
| 117 | CPPUNIT_ASSERT_EQUAL(1026, segmentList.front()->getIndex()); |
| 118 | CPPUNIT_ASSERT_EQUAL(1027, segmentList.back()->getIndex()); |
| 119 | FGTaxiSegment* pushForwardSegment = network->findSegmentByHeading(startParking, startParking->getHeading()); |
| 120 | CPPUNIT_ASSERT(pushForwardSegment); |
| 121 | CPPUNIT_ASSERT_EQUAL(1027, pushForwardSegment->getEnd()->getIndex()); |
| 122 | } |