Moved AI FlightPlan Tests to seperate test class
This commit is contained in:
parent
d96602fc90
commit
9dd5c0e055
6 changed files with 336 additions and 221 deletions
|
@ -2,6 +2,7 @@
|
||||||
set(TESTSUITE_SOURCES
|
set(TESTSUITE_SOURCES
|
||||||
${TESTSUITE_SOURCES}
|
${TESTSUITE_SOURCES}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx
|
${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_AIManager.cxx
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test_traffic.cxx
|
${CMAKE_CURRENT_SOURCE_DIR}/test_traffic.cxx
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test_groundnet.cxx
|
${CMAKE_CURRENT_SOURCE_DIR}/test_groundnet.cxx
|
||||||
|
@ -11,6 +12,7 @@ set(TESTSUITE_SOURCES
|
||||||
|
|
||||||
set(TESTSUITE_HEADERS
|
set(TESTSUITE_HEADERS
|
||||||
${TESTSUITE_HEADERS}
|
${TESTSUITE_HEADERS}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/test_AIFlightPlan.hxx
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test_AIManager.hxx
|
${CMAKE_CURRENT_SOURCE_DIR}/test_AIManager.hxx
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test_traffic.hxx
|
${CMAKE_CURRENT_SOURCE_DIR}/test_traffic.hxx
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test_groundnet.hxx
|
${CMAKE_CURRENT_SOURCE_DIR}/test_groundnet.hxx
|
||||||
|
|
|
@ -17,11 +17,13 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "test_AIFlightPlan.hxx"
|
||||||
#include "test_AIManager.hxx"
|
#include "test_AIManager.hxx"
|
||||||
#include "test_groundnet.hxx"
|
#include "test_groundnet.hxx"
|
||||||
#include "test_traffic.hxx"
|
#include "test_traffic.hxx"
|
||||||
#include "test_submodels.hxx"
|
#include "test_submodels.hxx"
|
||||||
|
|
||||||
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AIFlightPlanTests, "Unit tests");
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AIManagerTests, "Unit tests");
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AIManagerTests, "Unit tests");
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(GroundnetTests, "Unit tests");
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(GroundnetTests, "Unit tests");
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TrafficTests, "Unit tests");
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TrafficTests, "Unit tests");
|
||||||
|
|
281
test_suite/unit_tests/AI/test_AIFlightPlan.cxx
Normal file
281
test_suite/unit_tests/AI/test_AIFlightPlan.cxx
Normal file
|
@ -0,0 +1,281 @@
|
||||||
|
/*
|
||||||
|
* 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 "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 AIFlightPlanTests::setUp()
|
||||||
|
{
|
||||||
|
FGTestApi::setUp::initTestGlobals("AI");
|
||||||
|
FGTestApi::setUp::initNavDataCache();
|
||||||
|
|
||||||
|
globals->add_new_subsystem<FGAIManager>();
|
||||||
|
|
||||||
|
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::testAIFlightPlanLoadXML()
|
||||||
|
{
|
||||||
|
const auto xml = R"(<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<PropertyList>
|
||||||
|
<flightplan>
|
||||||
|
<wp>
|
||||||
|
<name>onGroundWP</name>
|
||||||
|
<lat></lat>
|
||||||
|
<lon></lon>
|
||||||
|
<ktas>10</ktas>
|
||||||
|
<on-ground>1</on-ground>
|
||||||
|
</wp>
|
||||||
|
<wp>
|
||||||
|
<name>someWP</name>
|
||||||
|
<lat></lat>
|
||||||
|
<lon></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);
|
||||||
|
}
|
||||||
|
|
51
test_suite/unit_tests/AI/test_AIFlightPlan.hxx
Normal file
51
test_suite/unit_tests/AI/test_AIFlightPlan.hxx
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* 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(testAIFlightPlanLoadXML);
|
||||||
|
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 testAIFlightPlanLoadXML();
|
||||||
|
};
|
|
@ -92,223 +92,6 @@ void AIManagerTests::testBasic()
|
||||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("velocities/groundspeed-kt"), aiUserAircraft->getSpeed(), 1);
|
CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("velocities/groundspeed-kt"), aiUserAircraft->getSpeed(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIManagerTests::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 AIManagerTests::testAIFlightPlanLoadXML()
|
|
||||||
{
|
|
||||||
const auto xml = R"(<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<PropertyList>
|
|
||||||
<flightplan>
|
|
||||||
<wp>
|
|
||||||
<name>onGroundWP</name>
|
|
||||||
<lat></lat>
|
|
||||||
<lon></lon>
|
|
||||||
<ktas>10</ktas>
|
|
||||||
<on-ground>1</on-ground>
|
|
||||||
</wp>
|
|
||||||
<wp>
|
|
||||||
<name>someWP</name>
|
|
||||||
<lat></lat>
|
|
||||||
<lon></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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// test for AIFLightPlan leg / legEnd pieces.
|
// test for AIFLightPlan leg / legEnd pieces.
|
||||||
|
|
||||||
void AIManagerTests::testAircraftWaypoints()
|
void AIManagerTests::testAircraftWaypoints()
|
||||||
|
|
|
@ -34,9 +34,7 @@ class AIManagerTests : public CppUnit::TestFixture
|
||||||
// Set up the test suite.
|
// Set up the test suite.
|
||||||
CPPUNIT_TEST_SUITE(AIManagerTests);
|
CPPUNIT_TEST_SUITE(AIManagerTests);
|
||||||
CPPUNIT_TEST(testBasic);
|
CPPUNIT_TEST(testBasic);
|
||||||
CPPUNIT_TEST(testAIFlightPlan);
|
|
||||||
CPPUNIT_TEST(testAircraftWaypoints);
|
CPPUNIT_TEST(testAircraftWaypoints);
|
||||||
CPPUNIT_TEST(testAIFlightPlanLoadXML);
|
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
|
@ -50,7 +48,5 @@ public:
|
||||||
|
|
||||||
// The tests.
|
// The tests.
|
||||||
void testBasic();
|
void testBasic();
|
||||||
void testAIFlightPlan();
|
|
||||||
void testAircraftWaypoints();
|
void testAircraftWaypoints();
|
||||||
void testAIFlightPlanLoadXML();
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue