diff --git a/test_suite/FGTestApi/testGlobals.cxx b/test_suite/FGTestApi/testGlobals.cxx
index fb40df8ca..687886631 100644
--- a/test_suite/FGTestApi/testGlobals.cxx
+++ b/test_suite/FGTestApi/testGlobals.cxx
@@ -444,7 +444,7 @@ void shutdownTestGlobals()
delete globals;
globals = nullptr;
- if (global_loggingToKML) {
+ if (global_kmlStream) {
if (global_lineStringOpen) {
endCurrentLineString();
}
diff --git a/test_suite/test_data/AI/Traffic/H/TST.xml b/test_suite/test_data/AI/Traffic/H/TST.xml
new file mode 100644
index 000000000..6656aecb1
--- /dev/null
+++ b/test_suite/test_data/AI/Traffic/H/TST.xml
@@ -0,0 +1,62 @@
+
+
+
+
+ Aircraft/BN-2/BN-2-Hebridean.xml
+ TST
+ TST
+ YSSY
+ TST_BN_2
+ BN2
+ 0
+ 8
+ gate
+ turboprop_transport
+ G-HEBO
+ false
+
+
+ Aircraft/BN-2/BN-2-Hebridean.xml
+ TST
+ TST
+ YBBN
+ TST_BN_2
+ BN2
+ 0
+ 8
+ gate
+ turboprop_transport
+ G-HEBS
+ false
+
+
+ Hebridean_1000
+ TST_BN_2
+ VFR
+
+ YBBN
+
+
+ 50
+
+ YSSY
+
+
+ Hr
+
+
+ Hebridean_1000
+ TST_BN_2
+ VFR
+
+ YSSY
+
+
+ 50
+
+ YBBN
+
+
+ Hr
+
+
diff --git a/test_suite/unit_tests/AI/CMakeLists.txt b/test_suite/unit_tests/AI/CMakeLists.txt
index 59d869ff6..0f00d5075 100644
--- a/test_suite/unit_tests/AI/CMakeLists.txt
+++ b/test_suite/unit_tests/AI/CMakeLists.txt
@@ -5,6 +5,7 @@ set(TESTSUITE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/test_AIFlightPlan.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_AIManager.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_traffic.cxx
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_TrafficMgr.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_groundnet.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_submodels.cxx
PARENT_SCOPE
@@ -15,6 +16,7 @@ set(TESTSUITE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/test_AIFlightPlan.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_AIManager.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_traffic.hxx
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_TrafficMgr.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 db7ed87fe..4b6e4a7d7 100644
--- a/test_suite/unit_tests/AI/TestSuite.cxx
+++ b/test_suite/unit_tests/AI/TestSuite.cxx
@@ -21,6 +21,7 @@
#include "test_AIManager.hxx"
#include "test_groundnet.hxx"
#include "test_traffic.hxx"
+#include "test_TrafficMgr.hxx"
#include "test_submodels.hxx"
#include "test_AIFlightPlan.hxx"
@@ -28,4 +29,5 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AIFlightPlanTests, "Unit tests");
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(TrafficMgrTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SubmodelsTests, "Unit tests");
diff --git a/test_suite/unit_tests/AI/test_TrafficMgr.cxx b/test_suite/unit_tests/AI/test_TrafficMgr.cxx
new file mode 100644
index 000000000..bed1279f2
--- /dev/null
+++ b/test_suite/unit_tests/AI/test_TrafficMgr.cxx
@@ -0,0 +1,153 @@
+/*
+ * 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_TrafficMgr.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
+
+// Set up function for each test.
+void TrafficMgrTests::setUp()
+{
+ FGTestApi::setUp::initTestGlobals("TrafficMgr");
+ FGTestApi::setUp::initNavDataCache();
+ fgSetBool("sim/ai/enabled", true);
+ fgSetBool("sim/traffic-manager/enabled", true);
+ fgSetBool("/environment/realwx/enabled", false);
+ fgSetBool("/environment/metar/valid", false);
+ //Otherwise TrafficMgr won't load
+ fgSetBool("sim/signals/fdm-initialized", true);
+ globals->set_fg_root(SGPath::fromUtf8(FG_TEST_SUITE_DATA));
+}
+
+// Clean up after each test.
+void TrafficMgrTests::tearDown()
+{
+ FGTestApi::tearDown::shutdownTestGlobals();
+}
+
+void TrafficMgrTests::testParse() {
+ globals->add_new_subsystem();
+
+ globals->get_subsystem_mgr()->bind();
+ globals->get_subsystem_mgr()->init();
+ globals->get_subsystem_mgr()->postinit();
+
+ FGTrafficManager *tmgr = (FGTrafficManager *) globals->get_subsystem("traffic-manager");
+ FGScheduledFlightVecIterator fltBegin, fltEnd;
+
+ for (size_t i = 0; i < 1000000; i++)
+ {
+ FGTestApi::runForTime(10.0);
+ // We have to wait for async parser
+ fltBegin = tmgr->getFirstFlight("TST_BN_2");
+ fltEnd = tmgr->getLastFlight("TST_BN_2");
+ if (fltBegin != fltEnd) {
+ break;
+ }
+ }
+
+ int counter = 0;
+ for (FGScheduledFlightVecIterator i = fltBegin; i != fltEnd; i++) {
+ cout << (*i)->getCallSign() << counter++ << endl;
+ }
+ CPPUNIT_ASSERT_EQUAL(2, counter);
+}
+
+void TrafficMgrTests::testTrafficManager()
+{
+ FGAirportRef egeo = FGAirport::getByIdent("EGEO");
+
+ fgSetString("/sim/presets/airport-id", "EGEO");
+
+ std::cout << globals->get_fg_root() << "\r\n";
+ globals->set_fg_root(SGPath::fromUtf8(FG_TEST_SUITE_DATA));
+ std::cout << globals->get_fg_root() << "\r\n";
+
+ fgSetBool("/sim/traffic-manager/enabled", true);
+ fgSetBool("/sim/traffic-manager/active", false);
+ fgSetBool("/sim/ai/enabled", true);
+ fgSetBool("/environment/realwx/enabled", false);
+ fgSetBool("/environment/metar/valid", false);
+ fgSetBool("/sim/terrasync/ai-data-update-now", false);
+
+ fgSetBool("/sim/traffic-manager/instantaneous-action", true);
+ fgSetBool("/sim/traffic-manager/heuristics", true);
+ fgSetBool("/sim/traffic-manager/dumpdata", false);
+
+ fgSetBool("/sim/signals/fdm-initialized", true);
+
+ FGTestApi::setPositionAndStabilise(egeo->geod());
+
+ auto tmgr = globals->add_new_subsystem();
+
+ tmgr->bind();
+ tmgr->init();
+
+ for( int i = 0; i < 30; i++) {
+ bool active = fgGetBool("/sim/traffic-manager/inited");
+ // std::cout << "Inited " << "\t" << i << "\t" << active << "\r\n";
+ FGTestApi::runForTime(5.0);
+ if(active) {
+ break;
+ }
+ }
+
+ const SGPropertyNode *tm = fgGetNode("/sim/traffic-manager", true);
+
+ for (int i = 0; i < tm->nChildren(); i++) {
+ const SGPropertyNode *model = tm->getChild(i);
+ std::cout << "TM : " << model->getDisplayName() << "\t" << model->nChildren() << "\n";
+ for (int g = 0; g < model->nChildren(); g++) {
+ const SGPropertyNode *v;
+ v = model->getChild(g);
+ std::cout << "Node " << g << "\t" << v->getDisplayName() << "\n";
+ }
+ }
+
+ FGTestApi::runForTime(360.0);
+
+ FGScheduledFlightVecIterator fltBegin, fltEnd;
+ fltBegin = tmgr->getFirstFlight("HBR_BN_2");
+ fltEnd = tmgr->getLastFlight("HBR_BN_2");
+
+ if (fltBegin == fltEnd) {
+ CPPUNIT_FAIL("No Traffic found");
+ }
+
+ int counter = 0;
+ for (FGScheduledFlightVecIterator i = fltBegin; i != fltEnd; i++) {
+ cout << (*i)->getDepartureAirport()->getId() << "\t" << (*i)->getArrivalAirport()->getId() << "\t" << (*i)->getDepartureTime() << "\n";
+ counter++;
+ }
+ CPPUNIT_ASSERT_EQUAL(25, counter);
+}
\ No newline at end of file
diff --git a/test_suite/unit_tests/AI/test_TrafficMgr.hxx b/test_suite/unit_tests/AI/test_TrafficMgr.hxx
new file mode 100644
index 000000000..1fc8c8943
--- /dev/null
+++ b/test_suite/unit_tests/AI/test_TrafficMgr.hxx
@@ -0,0 +1,53 @@
+/*
+ * 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;
+
+class FGAIAircraft;
+
+// The flight plan unit tests.
+class TrafficMgrTests : public CppUnit::TestFixture
+{
+ // Set up the test suite.
+ CPPUNIT_TEST_SUITE(TrafficMgrTests);
+ CPPUNIT_TEST(testParse);
+ CPPUNIT_TEST(testTrafficManager);
+ CPPUNIT_TEST_SUITE_END();
+
+
+public:
+ // Set up function for each test.
+ void setUp();
+
+ // Clean up after each test.
+ void tearDown();
+
+ // The tests.
+ void testTrafficManager();
+ void testParse();
+};
diff --git a/test_suite/unit_tests/AI/test_traffic.cxx b/test_suite/unit_tests/AI/test_traffic.cxx
index 12d47b708..d38af69c6 100644
--- a/test_suite/unit_tests/AI/test_traffic.cxx
+++ b/test_suite/unit_tests/AI/test_traffic.cxx
@@ -28,9 +28,7 @@
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include "test_suite/FGTestApi/TestDataLogger.hxx"
#include "test_suite/FGTestApi/testGlobals.hxx"
-#include "test_suite/FGTestApi/mock_scenery.hxx"
-#include
#include
#include
#include
@@ -39,8 +37,9 @@
#include
#include
#include
-#include
#include