first commit

This commit is contained in:
Your Name
2022-10-20 20:29:11 +08:00
commit 4d531f8044
3238 changed files with 1387862 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
set(TESTSUITE_SOURCES
${TESTSUITE_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx
${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
${CMAKE_CURRENT_SOURCE_DIR}/test_VectorMath.cxx
PARENT_SCOPE
)
set(TESTSUITE_HEADERS
${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
${CMAKE_CURRENT_SOURCE_DIR}/test_VectorMath.hxx
PARENT_SCOPE
)
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2020 James Turner
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "test_AIFlightPlan.hxx"
#include "test_AIManager.hxx"
#include "test_groundnet.hxx"
#include "test_traffic.hxx"
#include "test_TrafficMgr.hxx"
#include "test_submodels.hxx"
#include "test_AIFlightPlan.hxx"
#include "test_VectorMath.hxx"
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");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(VectorMathTests, "Unit tests");
@@ -0,0 +1,363 @@
/*
* Copyright (C) 2020 James Turner
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "test_AIFlightPlan.hxx"
#include <cstring>
#include <memory>
#include "config.h"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include "test_suite/FGTestApi/TestDataLogger.hxx"
#include "test_suite/FGTestApi/TestPilot.hxx"
#include <AIModel/AIAircraft.hxx>
#include <AIModel/AIFlightPlan.hxx>
#include <AIModel/AIManager.hxx>
#include <Airports/airport.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <Navaids/NavDataCache.hxx>
#include <Navaids/navrecord.hxx>
using namespace flightgear;
/////////////////////////////////////////////////////////////////////////////
// Set up function for each test.
void AIFlightPlanTests::setUp()
{
FGTestApi::setUp::initTestGlobals("AI");
FGTestApi::setUp::initNavDataCache();
globals->add_new_subsystem<FGAIManager>(SGSubsystemMgr::GENERAL);
auto props = globals->get_props();
props->setBoolValue("sim/ai/enabled", true);
globals->get_subsystem_mgr()->bind();
globals->get_subsystem_mgr()->init();
globals->get_subsystem_mgr()->postinit();
}
// Clean up after each test.
void AIFlightPlanTests::tearDown()
{
FGTestApi::tearDown::shutdownTestGlobals();
}
void AIFlightPlanTests::testAIFlightPlan()
{
std::unique_ptr<FGAIFlightPlan> aiFP(new FGAIFlightPlan);
aiFP->setName("Bob");
aiFP->setRunway("24");
CPPUNIT_ASSERT_EQUAL(string{"Bob"}, aiFP->getName());
CPPUNIT_ASSERT_EQUAL(string{"24"}, aiFP->getRunway());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getNextWaypoint());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getLeg());
FGPositioned::TypeFilter ty(FGPositioned::VOR);
auto cache = flightgear::NavDataCache::instance();
auto shannonVOR = cache->findClosestWithIdent("SHA", SGGeod::fromDeg(-8, 52), &ty);
CPPUNIT_ASSERT_EQUAL(string{"SHANNON VOR-DME"}, shannonVOR->name());
auto wp1 = new FGAIWaypoint;
wp1->setPos(shannonVOR->geod());
wp1->setName("testWp_0");
wp1->setOn_ground(true);
wp1->setGear_down(true);
wp1->setSpeed(100);
auto wp2 = new FGAIWaypoint;
const auto g1 = SGGeodesy::direct(shannonVOR->geod(), 10.0, SG_NM_TO_METER * 5.0);
wp2->setPos(g1);
wp2->setName("upInTheAir");
wp2->setOn_ground(false);
wp2->setGear_down(true);
wp2->setSpeed(150);
aiFP->addWaypoint(wp1);
aiFP->addWaypoint(wp2);
CPPUNIT_ASSERT_EQUAL(2, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp1, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(wp2, aiFP->getNextWaypoint());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getLeg());
CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, aiFP->getBearing(wp1, wp2), 0.1);
time_t startTime = 1498;
aiFP->setTime(startTime);
CPPUNIT_ASSERT(!aiFP->isActive(1400));
CPPUNIT_ASSERT(aiFP->isActive(1500));
aiFP->IncrementWaypoint(false);
CPPUNIT_ASSERT_EQUAL(2, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp1, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(wp2, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getNextWaypoint());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getLeg());
auto wp3 = new FGAIWaypoint;
auto diganWpt = cache->findClosestWithIdent("DIGAN", shannonVOR->geod(), nullptr);
wp3->setPos(diganWpt->geod());
wp3->setName("overDIGAN");
wp3->setOn_ground(false);
wp3->setGear_down(false);
wp3->setSpeed(180);
// check that adding a waypoint doesn't mess up the iterators or
// current position
aiFP->addWaypoint(wp3);
CPPUNIT_ASSERT_EQUAL(3, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp1, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(wp2, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(wp3, aiFP->getNextWaypoint());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getLeg());
auto p3 = SGGeodesy::direct(diganWpt->geod(), 45, SG_NM_TO_METER * 4);
p3.setElevationFt(12000);
auto wp4 = new FGAIWaypoint;
wp4->setPos(p3);
wp4->setName("passDIGAN");
wp4->setSpeed(200);
aiFP->addWaypoint(wp4);
auto ingur = cache->findClosestWithIdent("INGUR", shannonVOR->geod(), nullptr);
auto p4 = ingur->geod();
p4.setElevationFt(16000);
auto wp5 = new FGAIWaypoint;
wp5->setPos(p4);
wp5->setName("INGUR");
wp5->setSpeed(250);
aiFP->addWaypoint(wp5);
aiFP->IncrementWaypoint(false);
CPPUNIT_ASSERT_EQUAL(5, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp2, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(wp3, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(wp4, aiFP->getNextWaypoint());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getLeg());
// let's increment to the end
aiFP->IncrementWaypoint(false);
aiFP->IncrementWaypoint(false);
CPPUNIT_ASSERT_EQUAL(5, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp4, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(wp5, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getNextWaypoint());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getLeg());
// one more increment 'off the end'
aiFP->IncrementWaypoint(false);
CPPUNIT_ASSERT_EQUAL(5, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp5, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getNextWaypoint());
// should put us back on the last waypoint
aiFP->DecrementWaypoint();
CPPUNIT_ASSERT_EQUAL(5, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp4, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(wp5, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getNextWaypoint());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getLeg());
aiFP->DecrementWaypoint(); // back to wp4
aiFP->DecrementWaypoint(); // back to wp3
aiFP->DecrementWaypoint(); // back to wp2
CPPUNIT_ASSERT_EQUAL(5, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp1, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(wp2, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(wp3, aiFP->getNextWaypoint());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getLeg());
// restart to the beginning
aiFP->restart();
CPPUNIT_ASSERT_EQUAL(5, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(wp1, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(wp2, aiFP->getNextWaypoint());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getLeg());
// test increment with delete
aiFP->IncrementWaypoint(true);
CPPUNIT_ASSERT_EQUAL(5, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp1, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(wp2, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(wp3, aiFP->getNextWaypoint());
aiFP->IncrementWaypoint(true);
CPPUNIT_ASSERT_EQUAL(4, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp2, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(wp3, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(wp4, aiFP->getNextWaypoint());
aiFP->IncrementWaypoint(true);
CPPUNIT_ASSERT_EQUAL(3, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp3, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(wp4, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(wp5, aiFP->getNextWaypoint());
// let's run up to the end and check nothing explodes
aiFP->IncrementWaypoint(true);
CPPUNIT_ASSERT_EQUAL(2, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp4, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(wp5, aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getNextWaypoint());
aiFP->IncrementWaypoint(true);
CPPUNIT_ASSERT_EQUAL(1, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(wp5, aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getNextWaypoint());
}
void AIFlightPlanTests::testAIFlightPlanLeftCircle()
{
auto aiFP = new FGAIFlightPlan;
aiFP->setName("Bob");
aiFP->setRunway("24");
CPPUNIT_ASSERT_EQUAL(string{"Bob"}, aiFP->getName());
CPPUNIT_ASSERT_EQUAL(string{"24"}, aiFP->getRunway());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getNrOfWayPoints());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getPreviousWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getCurrentWaypoint());
CPPUNIT_ASSERT_EQUAL(static_cast<FGAIWaypoint*>(nullptr), aiFP->getNextWaypoint());
CPPUNIT_ASSERT_EQUAL(0, aiFP->getLeg());
FGPositioned::TypeFilter ty(FGPositioned::VOR);
auto cache = flightgear::NavDataCache::instance();
auto shannonVOR = cache->findClosestWithIdent("SHA", SGGeod::fromDeg(-8, 52), &ty);
CPPUNIT_ASSERT_EQUAL(string{"SHANNON VOR-DME"}, shannonVOR->name());
auto wp1 = new FGAIWaypoint;
wp1->setPos(shannonVOR->geod());
wp1->setName("testWp_0");
wp1->setOn_ground(true);
wp1->setGear_down(true);
wp1->setSpeed(10);
aiFP->addWaypoint(wp1);
auto lastWp = wp1;
int course = 0;
for(int i = 1; i <= 10; i++) {
auto wp = new FGAIWaypoint;
course += 10;
const auto g1 = SGGeodesy::direct(lastWp->getPos(), course, SG_NM_TO_METER * 5.0);
wp->setPos(g1);
wp->setName("testWp_" + std::to_string(i));
wp->setOn_ground(true);
wp->setGear_down(true);
wp->setSpeed(10);
aiFP->addWaypoint(wp);
lastWp = wp;
}
CPPUNIT_ASSERT_EQUAL(aiFP->getNrOfWayPoints(), 11);
}
void AIFlightPlanTests::testAIFlightPlanLoadXML()
{
const auto xml = R"(<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
<flightplan>
<wp>
<name>onGroundWP</name>
<lat>57</lat>
<lon>3</lon>
<ktas>10</ktas>
<on-ground>1</on-ground>
</wp>
<wp>
<name>someWP</name>
<lat>57</lat>
<lon>4</lon>
<ktas>200</ktas>
<alt>8000</alt>
</wp>
<wp>
<name>END</name>
</wp>
</flightplan>
</PropertyList>
)";
std::istringstream is(xml);
std::unique_ptr<FGAIFlightPlan> aiFP(new FGAIFlightPlan);
bool ok = aiFP->readFlightplan(is, sg_location("In-memory test_ai_fp.xml"));
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(false, aiFP->getCurrentWaypoint()->getInAir());
CPPUNIT_ASSERT_EQUAL(true, aiFP->getCurrentWaypoint()->getGear_down());
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, aiFP->getCurrentWaypoint()->getFlaps(), 0.1);
auto wp2 = aiFP->getNextWaypoint();
CPPUNIT_ASSERT_EQUAL(true, wp2->getInAir());
CPPUNIT_ASSERT_EQUAL(false, wp2->getGear_down());
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, wp2->getFlaps(), 0.1);
}
void AIFlightPlanTests::testLeftTurnFlightplanXML()
{
std::unique_ptr<FGAIFlightPlan> aiFP(new FGAIFlightPlan);
const auto fpath = SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "AI"/"Flightplan"/"left_onground.xml";
std::fstream fs(fpath.c_str());
bool ok = aiFP->readFlightplan(fs, sg_location("In-memory test_ai_fp.xml"));
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(false, aiFP->getCurrentWaypoint()->getInAir());
auto wp2 = aiFP->getNextWaypoint();
CPPUNIT_ASSERT_EQUAL(false, wp2->getInAir());
CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, wp2->getSpeed(), 0.1);
}
void AIFlightPlanTests::testRightTurnFlightplanXML()
{
std::unique_ptr<FGAIFlightPlan> aiFP(new FGAIFlightPlan);
const auto fpath = SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "AI"/"Flightplan"/"right_onground.xml";
std::fstream fs(fpath.c_str());
bool ok = aiFP->readFlightplan(fs, sg_location("In-memory test_ai_fp.xml"));
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(false, aiFP->getCurrentWaypoint()->getInAir());
auto wp2 = aiFP->getNextWaypoint();
CPPUNIT_ASSERT_EQUAL(false, wp2->getInAir());
CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, wp2->getSpeed(), 0.1);
}
@@ -0,0 +1,57 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include <simgear/props/props.hxx>
class SGGeod;
// The AI flight plan unit tests.
class AIFlightPlanTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(AIFlightPlanTests);
CPPUNIT_TEST(testAIFlightPlan);
CPPUNIT_TEST(testAIFlightPlanLeftCircle);
CPPUNIT_TEST(testAIFlightPlanLoadXML);
CPPUNIT_TEST(testLeftTurnFlightplanXML);
CPPUNIT_TEST(testRightTurnFlightplanXML);
CPPUNIT_TEST_SUITE_END();
public:
// Set up function for each test.
void setUp();
// Clean up after each test.
void tearDown();
// The tests.
void testAIFlightPlan();
void testAIFlightPlanLeftCircle();
void testAIFlightPlanLoadXML();
void testLeftTurnFlightplanXML();
void testRightTurnFlightplanXML();
};
+131
View File
@@ -0,0 +1,131 @@
/*
* Copyright (C) 2020 James Turner
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "test_AIManager.hxx"
#include <cstring>
#include <memory>
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include "test_suite/FGTestApi/TestDataLogger.hxx"
#include "test_suite/FGTestApi/TestPilot.hxx"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include <AIModel/AIAircraft.hxx>
#include <AIModel/AIFlightPlan.hxx>
#include <AIModel/AIManager.hxx>
#include <Airports/airport.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <Navaids/NavDataCache.hxx>
#include <Navaids/navrecord.hxx>
/////////////////////////////////////////////////////////////////////////////
// Set up function for each test.
void AIManagerTests::setUp()
{
FGTestApi::setUp::initTestGlobals("AI");
FGTestApi::setUp::initNavDataCache();
globals->add_new_subsystem<FGAIManager>(SGSubsystemMgr::GENERAL);
auto props = globals->get_props();
props->setBoolValue("sim/ai/enabled", true);
globals->get_subsystem_mgr()->bind();
globals->get_subsystem_mgr()->init();
globals->get_subsystem_mgr()->postinit();
}
// Clean up after each test.
void AIManagerTests::tearDown()
{
FGTestApi::tearDown::shutdownTestGlobals();
}
void AIManagerTests::testBasic()
{
auto aim = globals->get_subsystem<FGAIManager>();
auto bikf = FGAirport::findByIdent("BIKF");
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot);
FGTestApi::setPosition(bikf->geod());
pilot->resetAtPosition(bikf->geod());
pilot->setSpeedKts(220);
pilot->setCourseTrue(0.0);
pilot->setTargetAltitudeFtMSL(10000);
FGTestApi::runForTime(10.0);
auto aiUserAircraft = aim->getUserAircraft();
CPPUNIT_ASSERT(aiUserAircraft->isValid());
CPPUNIT_ASSERT(!aiUserAircraft->getDie());
const SGGeod g = globals->get_aircraft_position();
CPPUNIT_ASSERT_DOUBLES_EQUAL(g.getLongitudeDeg(), aiUserAircraft->getGeodPos().getLongitudeDeg(), 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL(g.getLatitudeDeg(), aiUserAircraft->getGeodPos().getLatitudeDeg(), 0.01);
// disable, the AI user aircraft doesn't track altitude?!
// CPPUNIT_ASSERT_DOUBLES_EQUAL(g.getElevationFt(), aiUserAircraft->getGeodPos().getElevationFt(), 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("orientation/heading-deg"), aiUserAircraft->getTrueHeadingDeg(), 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("velocities/groundspeed-kt"), aiUserAircraft->getSpeed(), 1);
}
// test for AIFLightPlan leg / legEnd pieces.
void AIManagerTests::testAircraftWaypoints()
{
auto aim = globals->get_subsystem<FGAIManager>();
SGPropertyNode_ptr aircraftDefinition(new SGPropertyNode);
aircraftDefinition->setStringValue("type", "aircraft");
aircraftDefinition->setStringValue("callsign", "G-ARTA");
// set class for performance data
auto eggd = FGAirport::findByIdent("EGGD");
aircraftDefinition->setDoubleValue("heading", 90.0);
aircraftDefinition->setDoubleValue("latitude", eggd->geod().getLatitudeDeg());
aircraftDefinition->setDoubleValue("longitude", eggd->geod().getLongitudeDeg());
aircraftDefinition->setDoubleValue("altitude", 6000.0);
aircraftDefinition->setDoubleValue("speed", 250.0); // IAS or TAS?
FGTestApi::setPositionAndStabilise(eggd->geod());
auto ai = aim->addObject(aircraftDefinition);
CPPUNIT_ASSERT(ai);
CPPUNIT_ASSERT_EQUAL(FGAIBase::object_type::otAircraft, ai->getType());
CPPUNIT_ASSERT_EQUAL(std::string{"aircraft"}, std::string{ai->getTypeString()});
auto aiAircraft = static_cast<FGAIAircraft*>(ai.get());
const auto aiPos = aiAircraft->getGeodPos();
CPPUNIT_ASSERT_DOUBLES_EQUAL(eggd->geod().getLatitudeDeg(), aiPos.getLatitudeDeg(), 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL(eggd->geod().getLongitudeDeg(), aiPos.getLongitudeDeg(), 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL(90.0, aiAircraft->getTrueHeadingDeg(), 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(250.0, aiAircraft->getSpeed(), 1);
std::unique_ptr<FGAIFlightPlan> aiFP(new FGAIFlightPlan);
ai->setFlightPlan(std::move(aiFP));
}
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2020 James Turner
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include <simgear/props/props.hxx>
class SGGeod;
// The flight plan unit tests.
class AIManagerTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(AIManagerTests);
CPPUNIT_TEST(testBasic);
CPPUNIT_TEST(testAircraftWaypoints);
CPPUNIT_TEST_SUITE_END();
public:
// Set up function for each test.
void setUp();
// Clean up after each test.
void tearDown();
// The tests.
void testBasic();
void testAircraftWaypoints();
};
@@ -0,0 +1,152 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "test_TrafficMgr.hxx"
#include <cstring>
#include <memory>
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include "test_suite/FGTestApi/TestDataLogger.hxx"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include <Airports/airport.hxx>
#include <Traffic/TrafficMgr.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
// 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<FGTrafficManager>(SGSubsystemMgr::GENERAL);
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<FGTrafficManager>(SGSubsystemMgr::GENERAL);
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);
}
@@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include <simgear/props/props.hxx>
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();
};
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
*/
#include "test_VectorMath.hxx"
#include <cstring>
#include <memory>
#include <cppunit/TestAssert.h>
#include "config.h"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include <AIModel/VectorMath.hxx>
using namespace flightgear;
// Set up function for each test.
void VectorMathTests::setUp()
{
}
// Clean up after each test.
void VectorMathTests::tearDown()
{
}
void VectorMathTests::testInnerTanget()
{
double r1 = 10;
double r2 = 10;
// when the circles are dist appart the angle will be 45°
double dist = 2 * r1 + 2 * r2;
SGGeod m1 = SGGeod::fromDeg(9,51);
SGGeod m2 = SGGeodesy::direct(m1, 90, dist);
auto angles = VectorMath::innerTangentsAngle(m1, m2, r1, r2);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 60, angles[0], 0.1);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 120, angles[1], 0.1);
}
void VectorMathTests::testInnerTangent2()
{
double r1 = 10;
double r2 = 10;
// when the circles are dist appart the angle will be 45°
double dist = 2 * r1 + 2 * r2;
SGGeod m1 = SGGeod::fromDeg(9,51);
SGGeod m2 = SGGeodesy::direct(m1, 0, dist);
auto angles = VectorMath::innerTangentsAngle(m1, m2, r1, r2);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 330, angles[0], 0.1);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 30, angles[1], 0.1);
}
void VectorMathTests::testOuterTanget()
{
double r1 = 10;
double r2 = 50;
// when the circles are dist appart the angle will be 45°
double dist = 40;
SGGeod m1 = SGGeod::fromDeg(9,51);
SGGeod m2 = SGGeodesy::direct(m1, 90, dist);
auto angles = VectorMath::outerTangentsAngle(m1, m2, r1, r2);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 45, angles[0], 0.1);
CPPUNIT_ASSERT_DOUBLES_EQUAL( 135, angles[1], 0.1);
}
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include <simgear/props/props.hxx>
class SGGeod;
// The AI flight plan unit tests.
class VectorMathTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(VectorMathTests);
CPPUNIT_TEST(testInnerTanget);
CPPUNIT_TEST(testInnerTangent2);
CPPUNIT_TEST(testOuterTanget);
CPPUNIT_TEST_SUITE_END();
public:
// Set up function for each test.
void setUp();
// Clean up after each test.
void tearDown();
// The tests.
void testInnerTanget();
void testInnerTangent2();
void testOuterTanget();
};
+122
View File
@@ -0,0 +1,122 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "test_groundnet.hxx"
#include <cstring>
#include <memory>
#include <iostream>
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include "test_suite/FGTestApi/TestDataLogger.hxx"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include <AIModel/AIAircraft.hxx>
#include <AIModel/AIFlightPlan.hxx>
#include <AIModel/AIManager.hxx>
#include <AIModel/performancedb.hxx>
#include <Airports/airport.hxx>
#include <Airports/airportdynamicsmanager.hxx>
#include <Airports/groundnetwork.hxx>
#include <Airports/parking.hxx>
#include <Traffic/TrafficMgr.hxx>
#include <ATC/atc_mgr.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
/////////////////////////////////////////////////////////////////////////////
// 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");
FGAirportRef ybbn = FGAirport::getByIdent("YBBN");
ybbn->testSuiteInjectGroundnetXML(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "YBBN.groundnet.xml");
globals->add_new_subsystem<PerformanceDB>(SGSubsystemMgr::GENERAL);
globals->add_new_subsystem<FGATCManager>(SGSubsystemMgr::GENERAL);
globals->add_new_subsystem<FGAIManager>(SGSubsystemMgr::GENERAL);
globals->add_new_subsystem<flightgear::AirportDynamicsManager>(SGSubsystemMgr::GENERAL);
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");
FGGroundNetwork* network = egph->groundNetwork();
FGParkingRef startParking = network->findParkingByName("main-apron10");
FGRunwayRef runway = egph->getRunwayByIndex(0);
FGTaxiNodeRef end = network->findNearestNodeOnRunwayEntry(runway->threshold());
FGTaxiRoute route = network->findShortestRoute(startParking, end);
CPPUNIT_ASSERT_EQUAL(true, network->exists());
CPPUNIT_ASSERT_EQUAL(29, route.size());
}
/**
* Tests various find methods.
*/
void GroundnetTests::testFind()
{
FGAirportRef ybbn = FGAirport::getByIdent("YBBN");
FGGroundNetwork* network = ybbn->groundNetwork();
FGParkingRef startParking = network->findParkingByName("GA1");
CPPUNIT_ASSERT_EQUAL(1020, startParking->getIndex());
FGTaxiSegment* segment1 = network->findSegment(startParking, NULL);
CPPUNIT_ASSERT(segment1);
FGTaxiSegment* segment2 = network->findSegment(startParking, segment1->getEnd());
CPPUNIT_ASSERT(segment2);
FGTaxiNodeVector segmentList = network->findSegmentsFrom(startParking);
CPPUNIT_ASSERT_EQUAL(2, (int)segmentList.size());
CPPUNIT_ASSERT_EQUAL(1026, segmentList.front()->getIndex());
CPPUNIT_ASSERT_EQUAL(1027, segmentList.back()->getIndex());
FGTaxiSegment* pushForwardSegment = network->findSegmentByHeading(startParking, startParking->getHeading());
CPPUNIT_ASSERT(pushForwardSegment);
CPPUNIT_ASSERT_EQUAL(1027, pushForwardSegment->getEnd()->getIndex());
}
@@ -0,0 +1,52 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include <simgear/props/props.hxx>
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(testFind);
CPPUNIT_TEST_SUITE_END();
public:
// Set up function for each test.
void setUp();
// Clean up after each test.
void tearDown();
// The tests.
void testShortestRoute();
void testFind();
};
+259
View File
@@ -0,0 +1,259 @@
/*
* Copyright (C) 2021 Colin Geniet
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "test_submodels.hxx"
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include "test_suite/FGTestApi/TestPilot.hxx"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include <AIModel/AIAircraft.hxx>
#include <AIModel/AIManager.hxx>
#include <AIModel/submodel.hxx>
#include <Airports/airport.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <cmath>
using std::string;
/////////////////////////////////////////////////////////////////////////////
// Set up function for each test.
void SubmodelsTests::setUp()
{
FGTestApi::setUp::initTestGlobals("Submodels");
FGTestApi::setUp::initNavDataCache();
globals->append_aircraft_path(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "Aircraft");
auto props = globals->get_props();
props->setBoolValue("sim/ai/enabled", true);
props->setStringValue("sim/submodels/path", "Aircraft/Test/submodels.xml");
globals->add_new_subsystem<FGAIManager>(SGSubsystemMgr::GENERAL);
globals->add_new_subsystem<FGSubmodelMgr>(SGSubsystemMgr::GENERAL);
globals->get_subsystem_mgr()->bind();
globals->get_subsystem_mgr()->init();
globals->get_subsystem_mgr()->postinit();
}
// Clean up after each test.
void SubmodelsTests::tearDown()
{
FGTestApi::tearDown::shutdownTestGlobals();
}
void SubmodelsTests::testLoadXML()
{
auto props = globals->get_props();
auto sm_node = props->getNode("ai/submodels");
CPPUNIT_ASSERT(sm_node->hasChild("submodel", 0));
sm_node = sm_node->getChild("submodel", 0);
CPPUNIT_ASSERT_EQUAL(string{"testLoadXML"}, static_cast<string>(sm_node->getStringValue("name")));
CPPUNIT_ASSERT_EQUAL(0, sm_node->getIntValue("id"));
CPPUNIT_ASSERT_EQUAL(42, sm_node->getIntValue("count"));
CPPUNIT_ASSERT(sm_node->getBoolValue("serviceable"));
}
FGAIBase* SubmodelsTests::findAIModel(std::string &name) {
auto ai_list = globals->get_subsystem<FGAIManager>()->get_ai_list();
auto filter = [name](FGAIBase *model) { return model->_getName() == name; };
return *std::find_if(ai_list.begin(), ai_list.end(), filter);
}
int SubmodelsTests::countAIModels(std::string &name) {
auto ai_list = globals->get_subsystem<FGAIManager>()->get_ai_list();
auto filter = [name](FGAIBase *model) { return model->_getName() == name; };
return static_cast<int>(std::count_if(ai_list.begin(), ai_list.end(), filter));
}
void SubmodelsTests::testRelease()
{
auto props = globals->get_props();
auto sm_node = props->getNode("ai/submodels/submodel[1]");
std::string name = sm_node->getStringValue("name");
// Setup reasonable flight conditions.
auto bikf = FGAirport::findByIdent("BIKF");
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot);
FGTestApi::setPosition(bikf->geod());
pilot->resetAtPosition(bikf->geod());
pilot->setSpeedKts(0);
pilot->setCourseTrue(0.0);
pilot->setTargetAltitudeFtMSL(0);
// Sanity check
CPPUNIT_ASSERT_EQUAL(0, countAIModels(name));
// Don't release anything
FGTestApi::runForTime(10.0);
CPPUNIT_ASSERT_EQUAL(0, countAIModels(name));
// Release submodel
sm_node->setBoolValue("trigger", true);
FGTestApi::runForTime(1);
sm_node->setBoolValue("trigger", false);
FGTestApi::runForTime(1);
CPPUNIT_ASSERT_EQUAL(1, countAIModels(name));
// Check validity
auto sm = findAIModel(name);
CPPUNIT_ASSERT(sm->isValid());
CPPUNIT_ASSERT(!sm->getDie());
// Second time
sm_node->setBoolValue("trigger", true);
FGTestApi::runForTime(5);
sm_node->setBoolValue("trigger", false);
FGTestApi::runForTime(1);
CPPUNIT_ASSERT_EQUAL(2, countAIModels(name));
// Let submodels expire
FGTestApi::runForTime(20);
CPPUNIT_ASSERT_EQUAL(0, countAIModels(name));
// Switch to repeat release
sm_node->setBoolValue("repeat", true);
sm_node->setBoolValue("trigger", true);
FGTestApi::runForTime(4.2); // release interval is 1s
sm_node->setBoolValue("trigger", false);
CPPUNIT_ASSERT_EQUAL(4, countAIModels(name));
// Let submodels expire
FGTestApi::runForTime(20);
CPPUNIT_ASSERT_EQUAL(0, countAIModels(name));
// In repeat mode, release timer persists when trigger is false.
// Currently it is at ~0.2s, so this must not release anything.
sm_node->setBoolValue("trigger", true);
FGTestApi::runForTime(0.5);
sm_node->setBoolValue("trigger", false);
CPPUNIT_ASSERT_EQUAL(0, countAIModels(name));
// Set limited count
sm_node->setIntValue("count", 3);
sm_node->setBoolValue("trigger", true);
FGTestApi::runForTime(1);
CPPUNIT_ASSERT_EQUAL(2, sm_node->getIntValue("count"));
CPPUNIT_ASSERT_EQUAL(1, countAIModels(name));
FGTestApi::runForTime(5);
CPPUNIT_ASSERT_EQUAL(0, sm_node->getIntValue("count"));
CPPUNIT_ASSERT_EQUAL(3, countAIModels(name));
}
void SubmodelsTests::testInitialState()
{
auto props = globals->get_props();
auto sm_node = props->getNode("ai/submodels/submodel[2]");
std::string name = sm_node->getStringValue("name");
// Submodel parameters
double x_offset = 10, y_offset = 6, z_offset = 1, yaw_offset = 30, pitch_offset = 50, speed = 100;
// Setup reasonable flight conditions.
auto bikf = FGAirport::findByIdent("BIKF");
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot);
FGTestApi::setPosition(bikf->geod());
pilot->resetAtPosition(bikf->geod());
pilot->setSpeedKts(0);
pilot->setCourseTrue(90);
pilot->setTargetAltitudeFtMSL(0);
props->setDoubleValue("/orientation/pitch-deg", 0);
props->setDoubleValue("/orientation/roll-deg", 0);
FGTestApi::runForTime(1);
sm_node->setBoolValue("trigger", true);
// Run update loop with dt=0 to capture initial state.
globals->get_subsystem<FGSubmodelMgr>()->update(0);
globals->get_subsystem<FGAIManager>()->update(0);
sm_node->setBoolValue("trigger", false);
CPPUNIT_ASSERT_EQUAL(1, countAIModels(name));
auto sm = findAIModel(name);
auto sm_pos = sm->getCartPos();
auto ac_pos = globals->get_aircraft_position_cart(); //ac->getCartPosAt(SGVec3d(0, 0, 0));
double heading, pitch, roll;
globals->get_aircraft_orientation(heading, pitch, roll);
CPPUNIT_ASSERT_DOUBLES_EQUAL(90, heading, 0.1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, pitch, 0.1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, roll, 0.1);
// Submodel release point
// Submodels offsets are in x-back,y-right,z-up frame.
// Computation is in x-forward,y-irght,z-down frame.
SGVec3d offset(-x_offset, y_offset, -z_offset);
SGQuatd local_frame_rotation = SGQuatd::fromLonLat(globals->get_aircraft_position());
local_frame_rotation *= SGQuatd::fromYawPitchRollDeg(heading, pitch, roll);
offset = local_frame_rotation.backTransform(offset);
auto release_pos = ac_pos + offset;
CPPUNIT_ASSERT_DOUBLES_EQUAL(release_pos.x(), sm_pos.x(), 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL(release_pos.y(), sm_pos.y(), 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL(release_pos.z(), sm_pos.z(), 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL(remainder(heading + yaw_offset, 360), remainder(sm->getTrueHeadingDeg(), 360), 0.1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(pitch + pitch_offset, sm->_getPitch(), 0.1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(speed, sm->_getSpeed() * SG_KT_TO_FPS, 0.1);
// Let submodels expire
FGTestApi::runForTime(20);
CPPUNIT_ASSERT_EQUAL(0, countAIModels(name));
// Second test for velocities
double speed_east = 100, wind_north = 20;
pilot->setSpeedKts(100 * SG_FPS_TO_KT);
props->setDoubleValue("/orientation/pitch-deg", 0);
props->setDoubleValue("/orientation/roll-deg", 0);
props->setDoubleValue("/velocities/speed-north-fps", 0);
props->setDoubleValue("/velocities/speed-east-fps", speed_east);
props->setDoubleValue("/velocities/speed-down-fps", 0);
props->setDoubleValue("/environment/wind-from-north-fps", wind_north);
props->setDoubleValue("/environment/wind-from-east-fps", 0);
FGTestApi::runForTime(1);
sm_node->setBoolValue("trigger", true);
// Run update loop with dt=0 to capture initial state.
globals->get_subsystem<FGSubmodelMgr>()->update(0);
globals->get_subsystem<FGAIManager>()->update(0);
sm_node->setBoolValue("trigger", false);
CPPUNIT_ASSERT_EQUAL(1, countAIModels(name));
sm = findAIModel(name);
// Check initial speeds.
// _get_speed_*_fps gives airspeed for submodels, which initially must be the vector
// parent_ground_velocity + opposed_wind_velocity + submodel_launch_velocity
CPPUNIT_ASSERT_DOUBLES_EQUAL(cos((heading + yaw_offset) * SG_DEGREES_TO_RADIANS)
* cos((pitch + pitch_offset) * SG_DEGREES_TO_RADIANS)
* speed
+ wind_north,
sm->_get_speed_north_fps(), 0.1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(sin((heading + yaw_offset) * SG_DEGREES_TO_RADIANS)
* cos((pitch + pitch_offset) * SG_DEGREES_TO_RADIANS)
* speed
+ speed_east,
sm->_get_speed_east_fps(), 0.1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(sin((pitch + pitch_offset) * SG_DEGREES_TO_RADIANS) * speed,
sm->_getVS_fps(), 0.1);
}
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2021 Colin Geniet
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <AIModel/AIBase.hxx>
#include <simgear/props/props.hxx>
class SGGeod;
// The flight plan unit tests.
class SubmodelsTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(SubmodelsTests);
CPPUNIT_TEST(testLoadXML);
CPPUNIT_TEST(testRelease);
CPPUNIT_TEST(testInitialState);
CPPUNIT_TEST_SUITE_END();
public:
// Set up function for each test.
void setUp();
// Clean up after each test.
void tearDown();
// The tests.
void testLoadXML();
void testRelease();
void testInitialState();
private:
FGAIBase* findAIModel(std::string &name);
int countAIModels(std::string &name);
};
File diff suppressed because it is too large Load Diff
+78
View File
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2020 James Turner
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include <simgear/props/props.hxx>
class SGGeod;
class FGAIAircraft;
// The flight plan unit tests.
class TrafficTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(TrafficTests);
CPPUNIT_TEST(testPushback);
CPPUNIT_TEST(testPushbackCargo);
CPPUNIT_TEST(testPushbackCargoInProgress);
CPPUNIT_TEST(testPushbackCargoInProgressDownWind);
CPPUNIT_TEST(testPushbackCargoInProgressNotBeyond);
CPPUNIT_TEST(testPushbackCargoInProgressBeyond);
CPPUNIT_TEST(testChangeRunway);
CPPUNIT_TEST(testPushforward);
CPPUNIT_TEST(testPushforwardSpeedy);
CPPUNIT_TEST(testPushforwardParkYBBN);
CPPUNIT_TEST(testPushforwardParkYBBNRepeatGa);
CPPUNIT_TEST(testPushforwardParkYBBNRepeatGaDelayed);
CPPUNIT_TEST(testPushforwardParkYBBNRepeatGate);
CPPUNIT_TEST_SUITE_END();
public:
// Set up function for each test.
void setUp();
// Clean up after each test.
void tearDown();
// Pushback Tests
void testPushback();
void testPushbackCargo();
void testPushbackCargoInProgress();
void testPushbackCargoInProgressDownWind();
void testPushbackCargoInProgressNotBeyond();
void testPushbackCargoInProgressBeyond();
void testChangeRunway();
//GA Tests with forward push
void testPushforward();
void testPushforwardSpeedy();
void testPushforwardParkYBBN();
void testPushforwardParkYBBNRepeatGa();
void testPushforwardParkYBBNRepeatGaDelayed();
void testPushforwardParkYBBNRepeatGate();
private:
long currentWorldTime;
std::string getTimeString(int timeOffset);
FGAIAircraft * flyAI(SGSharedPtr<FGAIAircraft> aiAircraft, std::string fName);
};