From d96602fc904f362e471d641dc2cf90a54c3f9786 Mon Sep 17 00:00:00 2001 From: portree_kid Date: Mon, 1 Feb 2021 19:51:05 +0100 Subject: [PATCH] Tests for groundnet.cxx --- test_suite/unit_tests/AI/CMakeLists.txt | 2 + test_suite/unit_tests/AI/TestSuite.cxx | 2 + test_suite/unit_tests/AI/test_groundnet.cxx | 114 ++++++++++++++++++++ test_suite/unit_tests/AI/test_groundnet.hxx | 49 +++++++++ 4 files changed, 167 insertions(+) create mode 100644 test_suite/unit_tests/AI/test_groundnet.cxx create mode 100644 test_suite/unit_tests/AI/test_groundnet.hxx diff --git a/test_suite/unit_tests/AI/CMakeLists.txt b/test_suite/unit_tests/AI/CMakeLists.txt index 06176edc5..a4a31c3cf 100644 --- a/test_suite/unit_tests/AI/CMakeLists.txt +++ b/test_suite/unit_tests/AI/CMakeLists.txt @@ -4,6 +4,7 @@ set(TESTSUITE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx ${CMAKE_CURRENT_SOURCE_DIR}/test_AIManager.cxx ${CMAKE_CURRENT_SOURCE_DIR}/test_traffic.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/test_groundnet.cxx ${CMAKE_CURRENT_SOURCE_DIR}/test_submodels.cxx PARENT_SCOPE ) @@ -12,6 +13,7 @@ set(TESTSUITE_HEADERS ${TESTSUITE_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/test_AIManager.hxx ${CMAKE_CURRENT_SOURCE_DIR}/test_traffic.hxx + ${CMAKE_CURRENT_SOURCE_DIR}/test_groundnet.hxx ${CMAKE_CURRENT_SOURCE_DIR}/test_submodels.hxx PARENT_SCOPE ) diff --git a/test_suite/unit_tests/AI/TestSuite.cxx b/test_suite/unit_tests/AI/TestSuite.cxx index 4349c17ef..fe09fb499 100644 --- a/test_suite/unit_tests/AI/TestSuite.cxx +++ b/test_suite/unit_tests/AI/TestSuite.cxx @@ -18,9 +18,11 @@ */ #include "test_AIManager.hxx" +#include "test_groundnet.hxx" #include "test_traffic.hxx" #include "test_submodels.hxx" CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AIManagerTests, "Unit tests"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(GroundnetTests, "Unit tests"); CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TrafficTests, "Unit tests"); CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SubmodelsTests, "Unit tests"); diff --git a/test_suite/unit_tests/AI/test_groundnet.cxx b/test_suite/unit_tests/AI/test_groundnet.cxx new file mode 100644 index 000000000..bc3a1043c --- /dev/null +++ b/test_suite/unit_tests/AI/test_groundnet.cxx @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2021 Keith Paterson + * + * This file is part of the program FlightGear. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "config.h" + +#include "test_groundnet.hxx" + +#include +#include +#include + + +#include "test_suite/FGTestApi/NavDataCache.hxx" +#include "test_suite/FGTestApi/TestDataLogger.hxx" +#include "test_suite/FGTestApi/testGlobals.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include
+#include
+ +///////////////////////////////////////////////////////////////////////////// + +// Set up function for each test. +void GroundnetTests::setUp() +{ + FGTestApi::setUp::initTestGlobals("Traffic"); + FGTestApi::setUp::initNavDataCache(); + + + auto props = globals->get_props(); + props->setBoolValue("sim/ai/enabled", true); + props->setBoolValue("sim/signals/fdm-initialized", false); + + + // ensure EGPH has a valid ground net for parking testing + FGAirport::clearAirportsCache(); + FGAirportRef egph = FGAirport::getByIdent("EGPH"); + egph->testSuiteInjectGroundnetXML(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "EGPH.groundnet.xml"); + + + globals->add_new_subsystem(); + globals->add_new_subsystem(); + globals->add_new_subsystem(); + globals->add_new_subsystem(); + + globals->get_subsystem_mgr()->bind(); + globals->get_subsystem_mgr()->init(); + globals->get_subsystem_mgr()->postinit(); +} + +// Clean up after each test. +void GroundnetTests::tearDown() +{ + FGTestApi::tearDown::shutdownTestGlobals(); +} + +void GroundnetTests::testShortestRoute() +{ + FGAirportRef egph = FGAirport::getByIdent("EGPH"); + + FGAISchedule* schedule = new FGAISchedule; + + FGAIAircraft* aiAircraft = new FGAIAircraft{schedule}; + + // std::cout << "*** Start ***\n"; + + FGGroundNetwork* network = egph->groundNetwork(); + + FGParkingRef startParking = network->findParkingByName("main-apron10"); + + FGRunwayRef runway = egph->getRunwayByIndex(0); + + // std::cout << startParking->getName() << "\n"; + + // std::cout << runway->name() << " " << runway->begin() << " " << runway->end() << "\n"; + + FGTaxiNodeRef end = network->findNearestNodeOnRunway(runway->threshold()); + + // std::cout << end->geod() << "\n"; + + FGTaxiRoute route = network->findShortestRoute(startParking, end); + + // std::cout << route.size() << "\n"; + + CPPUNIT_ASSERT_EQUAL(true, network->exists()); + CPPUNIT_ASSERT_EQUAL(25, route.size()); +} diff --git a/test_suite/unit_tests/AI/test_groundnet.hxx b/test_suite/unit_tests/AI/test_groundnet.hxx new file mode 100644 index 000000000..6472679b7 --- /dev/null +++ b/test_suite/unit_tests/AI/test_groundnet.hxx @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2021 Keith Paterson + * + * This file is part of the program FlightGear. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include + +#include + +#include + +class SGGeod; + +// The groundnet unit tests. +class GroundnetTests : public CppUnit::TestFixture +{ + // Set up the test suite. + CPPUNIT_TEST_SUITE(GroundnetTests); + CPPUNIT_TEST(testShortestRoute); + CPPUNIT_TEST_SUITE_END(); + + +public: + // Set up function for each test. + void setUp(); + + // Clean up after each test. + void tearDown(); + + // The tests. + void testShortestRoute(); +};