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

View File

@@ -0,0 +1,19 @@
set(TESTSUITE_SOURCES
${TESTSUITE_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_flightplan.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_fpNasal.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_navaids2.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_aircraftPerformance.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_routeManager.cxx
PARENT_SCOPE
)
set(TESTSUITE_HEADERS
${TESTSUITE_HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/test_flightplan.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_fpNasal.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_aircraftPerformance.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_routeManager.hxx
PARENT_SCOPE
)

View File

@@ -0,0 +1,31 @@
/*
* Copyright (C) 2018 Edward d'Auvergne
*
* 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_flightplan.hxx"
#include "test_navaids2.hxx"
#include "test_aircraftPerformance.hxx"
#include "test_routeManager.hxx"
#include "test_fpNasal.hxx"
// Set up the unit tests.
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(FlightplanTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(FPNasalTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(NavaidsTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AircraftPerformanceTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(RouteManagerTests, "Unit tests");

View File

@@ -0,0 +1,73 @@
#include "test_aircraftPerformance.hxx"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include <simgear/misc/strutils.hxx>
#include <Main/fg_props.hxx>
#include <Aircraft/AircraftPerformance.hxx>
using namespace flightgear;
// Set up function for each test.
void AircraftPerformanceTests::setUp()
{
FGTestApi::setUp::initTestGlobals("aircraft-perf");
FGTestApi::setUp::initNavDataCache();
}
// Clean up after each test.
void AircraftPerformanceTests::tearDown()
{
FGTestApi::tearDown::shutdownTestGlobals();
}
void AircraftPerformanceTests::testBasic()
{
fgSetString("/aircraft/performance/icao-category", "C");
AircraftPerformance ap;
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(1000), 152, 1e-3);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(8000), 224, 1e-3);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(20000), 491, 1e-3);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(35000), 461, 1e-3);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(38000), 458, 1e-3);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.groundSpeedForAltitudeKnots(40000), 458, 1e-3);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.timeBetween(3000, 6000), 100, 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.distanceNmBetween(3000, 6000), 5.430, 1e-3);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.timeBetween(36000, 34000), 100, 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.distanceNmBetween(36000, 34000), 12.805, 1e-1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.timeBetween(15000, 20000), 300, 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.distanceNmBetween(15000, 18000), 14.270, 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.timeBetween(2000, 25000), 1191.6, 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.distanceNmBetween(2000, 25000), 123.06, 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.timeBetween(36000, 3000), 1666.6, 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(ap.distanceNmBetween(36000, 3000), 162.02, 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(251.5, ap.timeToCruise(32.0, 350000), 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(503.0, ap.timeToCruise(64.0, 380000), 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1553.7, ap.turnRadiusMForAltitude(4000), 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(3322.4, ap.turnRadiusMForAltitude(16000), 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(4602.6, ap.turnRadiusMForAltitude(30000), 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(4475.5, ap.turnRadiusMForAltitude(38000), 1);
}
void AircraftPerformanceTests::testAltitudeGradient()
{
fgSetString("/aircraft/performance/icao-category", "E");
AircraftPerformance ap;
CPPUNIT_ASSERT_DOUBLES_EQUAL(8332, ap.computePreviousAltitude(10000, 6000), 1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(3260, ap.computeNextAltitude(4000, 2000), 1);
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) 2018 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/>.
*/
#ifndef _FG_AIRCRAFT_PERFORMANCE_UNIT_TESTS_HXX
#define _FG_AIRCRAFT_PERFORMANCE_UNIT_TESTS_HXX
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
class AircraftPerformanceTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(AircraftPerformanceTests);
CPPUNIT_TEST(testBasic);
CPPUNIT_TEST(testAltitudeGradient);
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 testAltitudeGradient();
};
#endif // AircraftPerformanceTests

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,105 @@
/*
* Copyright (C) 2018 Edward d'Auvergne
*
* 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/>.
*/
#ifndef FG_FLIGHTPLAN_UNIT_TESTS_HXX
#define FG_FLIGHTPLAN_UNIT_TESTS_HXX
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
// The flight plan unit tests.
class FlightplanTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(FlightplanTests);
CPPUNIT_TEST(testBasic);
CPPUNIT_TEST(testRoutePathBasic);
CPPUNIT_TEST(testRoutePathSkipped);
CPPUNIT_TEST(testRoutePathTrivialFlightPlan);
CPPUNIT_TEST(testBasicAirways);
CPPUNIT_TEST(testAirwayNetworkRoute);
CPPUNIT_TEST(testBug1814);
CPPUNIT_TEST(testRoutPathWpt0Midflight);
CPPUNIT_TEST(testRoutePathVec);
CPPUNIT_TEST(testRoutePathFinalLegVQPR15);
CPPUNIT_TEST(testLoadSaveMachRestriction);
CPPUNIT_TEST(testOnlyDiscontinuityRoute);
CPPUNIT_TEST(testBasicDiscontinuity);
CPPUNIT_TEST(testLeadingWPDynamic);
CPPUNIT_TEST(testRadialIntercept);
CPPUNIT_TEST(loadFGFPWithoutDepartureArrival);
CPPUNIT_TEST(loadFGFPWithEmbeddedProcedures);
CPPUNIT_TEST(loadFGFPWithOldProcedures);
CPPUNIT_TEST(loadFGFPWithProcedureIdents);
CPPUNIT_TEST(testCloningBasic);
CPPUNIT_TEST(testCloningFGFP);
CPPUNIT_TEST(testCloningProcedures);
CPPUNIT_TEST(testBug2616);
CPPUNIT_TEST(testRoute);
CPPUNIT_TEST(testViaInsertIntoFP);
CPPUNIT_TEST(testViaInsertIntoRoute);
CPPUNIT_TEST(loadFGFPAsRoute);
// CPPUNIT_TEST(testParseICAORoute);
// CPPUNIT_TEST(testParseICANLowLevelRoute);
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 testRoutePathBasic();
void testRoutePathSkipped();
void testRoutePathTrivialFlightPlan();
void testBasicAirways();
void testAirwayNetworkRoute();
void testParseICAORoute();
void testParseICANLowLevelRoute();
void testBug1814();
void testRoutPathWpt0Midflight();
void testRoutePathVec();
void testRoutePathFinalLegVQPR15();
void testLoadSaveMachRestriction();
void testBasicDiscontinuity();
void testOnlyDiscontinuityRoute();
void testLeadingWPDynamic();
void testRadialIntercept();
void loadFGFPWithoutDepartureArrival();
void loadFGFPWithEmbeddedProcedures();
void loadFGFPWithOldProcedures();
void loadFGFPWithProcedureIdents();
void testCloningBasic();
void testCloningFGFP();
void testCloningProcedures();
void testBug2616();
void testRoute();
void testViaInsertIntoFP();
void testViaInsertIntoRoute();
void loadFGFPAsRoute();
};
#endif // FG_FLIGHTPLAN_UNIT_TESTS_HXX

View File

@@ -0,0 +1,476 @@
#include "test_fpNasal.hxx"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include <simgear/misc/strutils.hxx>
#include <Navaids/FlightPlan.hxx>
#include <Navaids/routePath.hxx>
#include <Navaids/NavDataCache.hxx>
#include <Navaids/waypoint.hxx>
#include <Navaids/navlist.hxx>
#include <Navaids/navrecord.hxx>
#include <Navaids/airways.hxx>
#include <Navaids/fix.hxx>
#include <Airports/airport.hxx>
#include <Autopilot/route_mgr.hxx>
using namespace flightgear;
static bool static_haveProcedures = false;
// Set up function for each test.
void FPNasalTests::setUp()
{
FGTestApi::setUp::initTestGlobals("flightplan");
FGTestApi::setUp::initNavDataCache();
SGPath proceduresPath = SGPath::fromEnv("FG_PROCEDURES_PATH");
if (proceduresPath.exists()) {
static_haveProcedures = true;
globals->append_fg_scenery(proceduresPath);
}
// flightplan() acces needs the route manager
globals->add_new_subsystem<FGRouteMgr>(SGSubsystemMgr::GENERAL);
globals->get_subsystem_mgr()->bind();
globals->get_subsystem_mgr()->init();
FGTestApi::setUp::initStandardNasal();
globals->get_subsystem_mgr()->postinit();
}
// Clean up after each test.
void FPNasalTests::tearDown()
{
FGTestApi::tearDown::shutdownTestGlobals();
}
static FlightPlanRef makeTestFP(const std::string& depICAO, const std::string& depRunway,
const std::string& destICAO, const std::string& destRunway,
const std::string& waypoints)
{
FlightPlanRef f = FlightPlan::create();
FGTestApi::setUp::populateFPWithNasal(f, depICAO, depRunway, destICAO, destRunway, waypoints);
return f;
}
void FPNasalTests::testBasic()
{
FlightPlanRef fp1 = makeTestFP("EGCC", "23L", "EHAM", "24",
"TNT CLN");
fp1->setIdent("testplan");
// setup the FP on the route-manager, so flightplan() call works
auto rm = globals->get_subsystem<FGRouteMgr>();
rm->setFlightPlan(fp1);
rm->activate();
// modify leg data dfrom Nasal
bool ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
var leg = fp.getWP(3);
leg.setAltitude(6000, 'AT');
)");
CPPUNIT_ASSERT(ok);
// check the value updated in the leg
CPPUNIT_ASSERT_EQUAL(RESTRICT_AT, fp1->legAtIndex(3)->altitudeRestriction());
CPPUNIT_ASSERT_EQUAL(6000, fp1->legAtIndex(3)->altitudeFt());
// insert some waypoints from Nasal
ok = FGTestApi::executeNasal(R"(
var fp = flightplan();
var leg = fp.getWP(2);
var newWP = createWPFrom(navinfo(leg.lat, leg.lon, 'COA')[0]);
fp.insertWPAfter(newWP, 2);
)");
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(string{"COSTA VOR-DME"}, fp1->legAtIndex(3)->waypoint()->source()->name());
ok = FGTestApi::executeNasal(R"(
var fp = flightplan();
fp.clearAll();
unitTest.assert_equal(fp.getPlanSize(), 0);
unitTest.assert_equal(fp.current, -1);
unitTest.assert_equal(fp.departure, nil);
unitTest.assert_equal(fp.sid, nil);
unitTest.assert_equal(fp.cruiseSpeedKt, 0);
)");
CPPUNIT_ASSERT(ok);
}
void FPNasalTests::testRestrictions()
{
FlightPlanRef fp1 = makeTestFP("EGCC", "23L", "EHAM", "24",
"TNT CLN");
fp1->setIdent("testplan");
// setup the FP on the route-manager, so flightplan() call works
auto rm = globals->get_subsystem<FGRouteMgr>();
rm->setFlightPlan(fp1);
rm->activate();
// modify leg data dfrom Nasal
bool ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
var leg = fp.getWP(3);
leg.setAltitude(6000, 'AT');
)");
CPPUNIT_ASSERT(ok);
// check the value updated in the leg
CPPUNIT_ASSERT_EQUAL(RESTRICT_AT, fp1->legAtIndex(3)->altitudeRestriction());
CPPUNIT_ASSERT_EQUAL(6000, fp1->legAtIndex(3)->altitudeFt());
ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
var leg = fp.getWP(3);
leg.setAltitude(6000, 'above');
)");
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(RESTRICT_ABOVE, fp1->legAtIndex(3)->altitudeRestriction());
CPPUNIT_ASSERT_EQUAL(6000, fp1->legAtIndex(3)->altitudeFt());
ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
var leg = fp.getWP(3);
leg.setAltitude(6000, 'below');
)");
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(RESTRICT_BELOW, fp1->legAtIndex(3)->altitudeRestriction());
CPPUNIT_ASSERT_EQUAL(6000, fp1->legAtIndex(3)->altitudeFt());
ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
var leg = fp.getWP(3);
leg.setAltitude(6000, 'delete');
)");
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(RESTRICT_DELETE, fp1->legAtIndex(3)->altitudeRestriction());
ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
var leg = fp.getWP(3);
leg.setSpeed(250, 'at');
)");
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(RESTRICT_AT, fp1->legAtIndex(3)->speedRestriction());
CPPUNIT_ASSERT_EQUAL(250, fp1->legAtIndex(3)->speedKts());
ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
var leg = fp.getWP(3);
leg.setSpeed(250, 'above');
)");
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(RESTRICT_ABOVE, fp1->legAtIndex(3)->speedRestriction());
CPPUNIT_ASSERT_EQUAL(250, fp1->legAtIndex(3)->speedKts());
ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
var leg = fp.getWP(3);
leg.setSpeed(250, 'below');
)");
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(RESTRICT_BELOW, fp1->legAtIndex(3)->speedRestriction());
CPPUNIT_ASSERT_EQUAL(250, fp1->legAtIndex(3)->speedKts());
ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
var leg = fp.getWP(3);
leg.setSpeed(250, 'delete');
)");
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(RESTRICT_DELETE, fp1->legAtIndex(3)->speedRestriction());
}
void FPNasalTests::testSegfaultWaypointGhost()
{
// checking for a segfault here, no segfault indicates success. A runtime error in the log is acceptable here.
bool ok = FGTestApi::executeNasal(R"(
var fp = createFlightplan();
fp.departure = airportinfo("BIKF");
fp.destination = airportinfo("EGLL");
var wp = fp.getWP(1);
fp.deleteWP(1);
print(wp.wp_name);
)");
CPPUNIT_ASSERT(ok);
}
void FPNasalTests::testSIDTransitionAPI()
{
if (!static_haveProcedures) {
return;
}
auto rm = globals->get_subsystem<FGRouteMgr>();
bool ok = FGTestApi::executeNasal(R"(
var fp = flightplan();
fp.departure = airportinfo("KJFK");
fp.destination = airportinfo("EGLL");
var sid = fp.departure.getSid("DEEZZ5.13L");
unitTest.assert(sid != nil, "SID not found");
unitTest.assert_equal(sid.id, "DEEZZ5.13L", "Incorrect SID loaded");
var trans = sid.transition('CANDR');
unitTest.assert_equal(trans.id, "CANDR", "Couldn't find transition");
unitTest.assert_equal(trans.tp_type, "transition", "Procedure type incorrect");
fp.sid = trans;
fp.departure_runway = fp.departure.runway('13L')
)");
CPPUNIT_ASSERT(ok);
auto fp = rm->flightPlan();
CPPUNIT_ASSERT(fp->departureRunway());
CPPUNIT_ASSERT(fp->sid());
CPPUNIT_ASSERT(fp->sidTransition());
CPPUNIT_ASSERT_EQUAL(fp->departureRunway()->ident(), string{"13L"});
CPPUNIT_ASSERT_EQUAL(fp->sid()->ident(), string{"DEEZZ5.13L"});
CPPUNIT_ASSERT_EQUAL(fp->sidTransition()->ident(), string{"CANDR"});
// test specify SID via transition in Nasal
rm->setFlightPlan(FlightPlan::create());
ok = FGTestApi::executeNasal(R"(
var fp = flightplan();
fp.departure = airportinfo("KJFK");
fp.destination = airportinfo("EGLL");
fp.departure_runway = airportinfo("KJFK").runways["13L"];
fp.sid = airportinfo("KJFK").getSid("DEEZZ5.13L");
fp.sid_trans = "CANDR";
)");
CPPUNIT_ASSERT(ok);
fp = rm->flightPlan();
CPPUNIT_ASSERT(fp->departureRunway());
CPPUNIT_ASSERT(fp->sid());
CPPUNIT_ASSERT(fp->sidTransition());
CPPUNIT_ASSERT_EQUAL(fp->departureRunway()->ident(), string{"13L"});
CPPUNIT_ASSERT_EQUAL(fp->sid()->ident(), string{"DEEZZ5.13L"});
CPPUNIT_ASSERT_EQUAL(fp->sidTransition()->ident(), string{"CANDR"});
}
void FPNasalTests::testSTARTransitionAPI()
{
if (!static_haveProcedures) {
return;
}
auto rm = globals->get_subsystem<FGRouteMgr>();
bool ok = FGTestApi::executeNasal(R"(
var fp = flightplan();
fp.departure = airportinfo("EGLL");
fp.destination = airportinfo("EDDM");
var star = fp.destination.getStar("RIXE3A.26L");
unitTest.assert(star != nil, "STAR not found");
unitTest.assert_equal(star.id, "RIXE3A.26L", "Incorrect STAR loaded");
fp.star = star;
fp.destination_runway = fp.destination.runway('26L')
)");
CPPUNIT_ASSERT(ok);
auto fp = rm->flightPlan();
CPPUNIT_ASSERT(fp->star());
CPPUNIT_ASSERT(fp->starTransition() == nullptr);
CPPUNIT_ASSERT_EQUAL(fp->star()->ident(), string{"RIXE3A.26L"});
}
void FPNasalTests::testApproachTransitionAPI()
{
if (!static_haveProcedures) {
return;
}
auto rm = globals->get_subsystem<FGRouteMgr>();
bool ok = FGTestApi::executeNasal(R"(
var fp = flightplan();
fp.departure = airportinfo("EGLL");
fp.destination = airportinfo("EDDM");
var star = fp.destination.getStar("RIXE3A.08L");
unitTest.assert(star != nil, "STAR not found");
unitTest.assert_equal(star.id, "RIXE3A.08L", "Incorrect STAR loaded");
fp.star = star;
fp.destination_runway = fp.destination.runway('08L');
var approach = fp.destination.getApproach("ILS08L");
unitTest.assert(approach != nil, "No approach loaded");
var trans = approach.transition('LUL1C');
unitTest.assert(trans != nil, "approach transition not found");
unitTest.assert_equal(trans.id, "LUL1C", "Incorrect approach transition loaded");
unitTest.assert_equal(trans.tp_type, "transition", "Procedure type incorrect");
fp.approach = trans;
unitTest.assert_equal(fp.approach.id, "ILS08L", "Incorrect approach returned");
unitTest.assert_equal(fp.approach_trans.id, "LUL1C", "Incorrect transition returned");
unitTest.assert_equal(fp.approach_trans.tp_type, "transition", "Procedure type incorrect");
)");
CPPUNIT_ASSERT(ok);
auto fp = rm->flightPlan();
CPPUNIT_ASSERT(fp->approach());
CPPUNIT_ASSERT_EQUAL(string{"LUL1C"}, fp->approachTransition()->ident());
CPPUNIT_ASSERT_EQUAL(string{"ILS08L"}, fp->approach()->ident());
}
void FPNasalTests::testApproachTransitionAPIWithCloning()
{
if (!static_haveProcedures) {
return;
}
auto rm = globals->get_subsystem<FGRouteMgr>();
bool ok = FGTestApi::executeNasal(R"(
var fp = flightplan();
fp.departure = airportinfo("EGLL");
fp.destination = airportinfo("EHAM");
fp.star = fp.destination.getStar("REDF1A");
fp.destination_runway = fp.destination.runway('06');
var approach = fp.destination.getApproach("ILS06");
unitTest.assert(approach != nil, "No approach loaded");
var trans = approach.transition('SUG2A');
unitTest.assert(trans != nil, "approach transition not found");
fp.approach = trans;
unitTest.assert_equal(fp.approach.id, "ILS06", "Incorrect approach returned");
unitTest.assert_equal(fp.approach_trans.id, "SUG2A", "Incorrect transition returned");
unitTest.assert_equal(fp.approach_trans.tp_type, "transition", "Procedure type incorrect");
)");
CPPUNIT_ASSERT(ok);
auto fp = rm->flightPlan();
CPPUNIT_ASSERT(fp->approach());
CPPUNIT_ASSERT_EQUAL(string{"SUG2A"}, fp->approachTransition()->ident());
CPPUNIT_ASSERT_EQUAL(string{"ILS06"}, fp->approach()->ident());
auto fp2 = fp->clone("testplan2");
CPPUNIT_ASSERT_EQUAL(string{"ILS06"}, fp2->approach()->ident());
CPPUNIT_ASSERT_EQUAL(string{"SUG2A"}, fp2->approachTransition()->ident());
}
void FPNasalTests::testAirwaysAPI()
{
bool ok = FGTestApi::executeNasal(R"(
var airwayIdent = "L620";
var airwayStore = airway(airwayIdent, "low");
unitTest.assert(airwayStore != nil, "Airway " ~ airwayIdent ~ " not found");
unitTest.assert(airwayStore.id == airwayIdent, "Incorrect airway found");
unitTest.assert_equal(airwayStore.level, 'low', "Incorrect airway found");
unitTest.assert_equal(airwayStore.level_code, Airway.LOW, "Incorrect airway found");
airwayIdent = "UL620";
var cln = findNavaidsByID("CLN", "VOR")[0];
airwayStore = airway(airwayIdent, cln);
unitTest.assert(airwayStore != nil, "Airway " ~ airwayIdent ~ " not found");
unitTest.assert(airwayStore.id == airwayIdent, "Incorrect airway found");
unitTest.assert_equal(airwayStore.level_code, Airway.HIGH, "Incorrect airway found");
airwayIdent = "J547";
airwayStore = airway(airwayIdent);
unitTest.assert(airwayStore != nil, "Airway " ~ airwayIdent ~ " not found");
unitTest.assert(airwayStore.id == airwayIdent, "Incorrect airway found");
)");
CPPUNIT_ASSERT(ok);
ok = FGTestApi::executeNasal(R"(
var airwayIdent = "L620";
var airwayStore = airway(airwayIdent, Airway.LOW);
var cln = findNavaidsByID("CLN", "VOR")[0];
var v1 = createViaTo(airwayIdent, "CLN");
unitTest.assert_equal(v1.wp_type, "via");
unitTest.assert_equal(v1.airway.id, 'L620');
unitTest.assert_equal(v1.airway.level_code, Airway.LOW);
var v2 = createViaTo(airwayStore, "TULIP");
unitTest.assert_equal(v2.wp_type, "via");
unitTest.assert_equal(v2.airway.id, airwayIdent);
var v3 = createViaFromTo(cln, "L620", 'low', "TULIP");
unitTest.assert_equal(v3.airway.id, 'L620');
var v4 = createViaFromTo(cln, "L620", "REDFA");
unitTest.assert_equal(v4.airway.level_code, Airway.LOW);
# test direct API (no Vias)
var wps = airwayStore.viaWaypoints(cln, "TULIP");
unitTest.assert_equal(size(wps), 3);
unitTest.assert_equal(wps[1].wp_ident, 'REDFA');
unitTest.assert_equal(wps[1].airway.ident, 'L620');
)");
CPPUNIT_ASSERT(ok);
}
void FPNasalTests::testTotalDistanceAPI()
{
auto rm = globals->get_subsystem<FGRouteMgr>();
bool ok = FGTestApi::executeNasal(R"(
var fp = flightplan();
fp.departure = airportinfo("BIKF");
fp.destination = airportinfo("EGLL");
unitTest.assert_doubles_equal(1025.9, fp.totalDistanceNm, 0.1, "Distance assertion failed");
)");
CPPUNIT_ASSERT(ok);
auto fp = rm->flightPlan();
CPPUNIT_ASSERT_DOUBLES_EQUAL(fp->totalDistanceNm(), 1025.9, 0.1);
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (C) 2018 Edward d'Auvergne
*
* 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/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
// The flight plan unit tests.
class FPNasalTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(FPNasalTests);
CPPUNIT_TEST(testBasic);
CPPUNIT_TEST(testRestrictions);
CPPUNIT_TEST(testSegfaultWaypointGhost);
CPPUNIT_TEST(testSIDTransitionAPI);
CPPUNIT_TEST(testSTARTransitionAPI);
CPPUNIT_TEST(testApproachTransitionAPI);
CPPUNIT_TEST(testApproachTransitionAPIWithCloning);
CPPUNIT_TEST(testAirwaysAPI);
CPPUNIT_TEST(testTotalDistanceAPI);
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 testRestrictions();
void testSegfaultWaypointGhost();
void testSIDTransitionAPI();
void testSTARTransitionAPI();
void testApproachTransitionAPI();
void testApproachTransitionAPIWithCloning();
void testAirwaysAPI();
void testTotalDistanceAPI();
};

View File

@@ -0,0 +1,36 @@
#include "test_navaids2.hxx"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include <Navaids/NavDataCache.hxx>
#include <Navaids/navrecord.hxx>
#include <Navaids/navlist.hxx>
// Set up function for each test.
void NavaidsTests::setUp()
{
FGTestApi::setUp::initTestGlobals("navaids2");
FGTestApi::setUp::initNavDataCache();
}
// Clean up after each test.
void NavaidsTests::tearDown()
{
FGTestApi::tearDown::shutdownTestGlobals();
}
void NavaidsTests::testBasic()
{
SGGeod egccPos = SGGeod::fromDeg(-2.27, 53.35);
FGNavRecordRef tla = FGNavList::findByFreq(115.7, egccPos);
CPPUNIT_ASSERT_EQUAL(strcmp(tla->get_ident(), "TNT"), 0);
CPPUNIT_ASSERT(tla->ident() == "TNT");
CPPUNIT_ASSERT(tla->name() == "TRENT VOR-DME");
CPPUNIT_ASSERT_EQUAL(tla->get_freq(), 11570);
CPPUNIT_ASSERT_EQUAL(tla->get_range(), 130);
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2018 Edward d'Auvergne
*
* 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/>.
*/
#ifndef _FG_NAVAIDS_UNIT_TESTS_HXX
#define _FG_NAVAIDS_UNIT_TESTS_HXX
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
// The flight plan unit tests.
class NavaidsTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(NavaidsTests);
CPPUNIT_TEST(testBasic);
CPPUNIT_TEST_SUITE_END();
public:
// Set up function for each test.
void setUp();
// Clean up after each test.
void tearDown();
// The tests.
void testBasic();
};
#endif // _FG_NAVAIDS_UNIT_TESTS_HXX

View File

@@ -0,0 +1,989 @@
#include "config.h"
#include "test_routeManager.hxx"
#include <memory>
#include <cstring>
#include <simgear/io/iostreams/sgstream.hxx>
#include <simgear/misc/sg_dir.hxx>
#include <simgear/structure/commands.hxx>
#include "test_suite/FGTestApi/testGlobals.hxx"
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include "test_suite/FGTestApi/TestPilot.hxx"
#include <Navaids/FlightPlan.hxx>
#include <Navaids/NavDataCache.hxx>
#include <Navaids/navrecord.hxx>
#include <Navaids/navlist.hxx>
#include <Navaids/routePath.hxx>
// we need a default GPS instrument, hard to test seperately for now
#include <Instrumentation/gps.hxx>
#include <Autopilot/route_mgr.hxx>
using namespace flightgear;
static bool static_haveProcedures = false;
static FlightPlanRef makeTestFP(const std::string& depICAO, const std::string& depRunway,
const std::string& destICAO, const std::string& destRunway,
const std::string& waypoints)
{
FlightPlanRef f = FlightPlan::create();
FGTestApi::setUp::populateFPWithNasal(f, depICAO, depRunway, destICAO, destRunway, waypoints);
return f;
}
// Set up function for each test.
void RouteManagerTests::setUp()
{
FGTestApi::setUp::initTestGlobals("routemanager");
FGTestApi::setUp::initNavDataCache();
SGPath proceduresPath = SGPath::fromEnv("FG_PROCEDURES_PATH");
if (proceduresPath.exists()) {
static_haveProcedures = true;
globals->append_fg_scenery(proceduresPath);
}
globals->add_new_subsystem<FGRouteMgr>(SGSubsystemMgr::FDM);
// setup the default GPS, which is needed for waypoint
// sequencing to work
SGPropertyNode_ptr configNode(new SGPropertyNode);
configNode->setStringValue("name", "gps");
configNode->setIntValue("number", 0);
GPS* gps(new GPS(configNode, true /* default mode */));
m_gps = gps;
SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation", true)->getChild("gps", 0, true);
// node->setBoolValue("serviceable", true);
// globals->get_props()->setDoubleValue("systems/electrical/outputs/gps", 6.0);
globals->add_subsystem("gps", gps, SGSubsystemMgr::POST_FDM);
globals->get_subsystem_mgr()->bind();
globals->get_subsystem_mgr()->init();
FGTestApi::setUp::initStandardNasal();
globals->get_subsystem_mgr()->postinit();
}
// Clean up after each test.
void RouteManagerTests::tearDown()
{
m_gps = nullptr;
FGTestApi::tearDown::shutdownTestGlobals();
}
void RouteManagerTests::setPositionAndStabilise(const SGGeod& g)
{
FGTestApi::setPosition(g);
for (int i=0; i<60; ++i) {
globals->get_subsystem_mgr()->update(0.02);
}
}
void RouteManagerTests::testBasic()
{
//FGTestApi::setUp::logPositionToKML("rm_basic");
FlightPlanRef fp1 = makeTestFP("EGLC", "27", "EHAM", "06",
"CLN IDESI RINIS VALKO RIVER RTM EKROS");
fp1->setIdent("testplan");
fp1->setCruiseFlightLevel(360);
CPPUNIT_ASSERT_EQUAL("RIVER"s, fp1->legAtIndex(5)->waypoint()->ident());
auto rm = globals->get_subsystem<FGRouteMgr>();
rm->setFlightPlan(fp1);
auto gpsNode = globals->get_props()->getNode("instrumentation/gps", true);
CPPUNIT_ASSERT(gpsNode->getStringValue("mode") == "obs");
rm->activate();
CPPUNIT_ASSERT(fp1->isActive());
// Nasal deleagte should have placed GPS into leg mode
auto rmNode = globals->get_props()->getNode("autopilot/route-manager", true);
CPPUNIT_ASSERT(gpsNode->getStringValue("mode") == "leg");
CPPUNIT_ASSERT(rmNode->getStringValue("departure/airport") == "EGLC");
CPPUNIT_ASSERT(rmNode->getStringValue("departure/runway") == "27");
CPPUNIT_ASSERT(rmNode->getStringValue("departure/sid") == "");
CPPUNIT_ASSERT(rmNode->getStringValue("departure/name") == "London City");
CPPUNIT_ASSERT(rmNode->getStringValue("destination/airport") == "EHAM");
CPPUNIT_ASSERT(rmNode->getStringValue("destination/runway") == "06");
CPPUNIT_ASSERT_EQUAL(360, rmNode->getIntValue("cruise/flight-level"));
CPPUNIT_ASSERT_EQUAL(false, rmNode->getBoolValue("airborne"));
CPPUNIT_ASSERT_EQUAL(0, rmNode->getIntValue("current-wp"));
auto wp0Node = rmNode->getNode("wp");
CPPUNIT_ASSERT(wp0Node->getStringValue("id") == "EGLC-27");
auto wp1Node = rmNode->getNode("wp[1]");
CPPUNIT_ASSERT(wp1Node->getStringValue("id") == "CLN");
FGPositioned::TypeFilter f{FGPositioned::VOR};
auto clactonVOR = fgpositioned_cast<FGNavRecord>(FGPositioned::findClosestWithIdent("CLN", SGGeod::fromDeg(0.0, 51.0), &f));
// verify hold entry course
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot);
FGTestApi::setPosition(fp1->departureRunway()->geod());
pilot->resetAtPosition(fp1->departureRunway()->geod());
pilot->setSpeedKts(220);
pilot->setCourseTrue(fp1->departureRunway()->headingDeg());
pilot->setTargetAltitudeFtMSL(10000);
bool ok = FGTestApi::runForTimeWithCheck(30.0, [rmNode] () {
if (rmNode->getIntValue("current-wp") == 1) return true;
return false;
});
CPPUNIT_ASSERT(ok);
// continue outbound for some time
pilot->setSpeedKts(250);
FGTestApi::runForTime(30.0);
// turn towards Clacton VOR
pilot->flyDirectTo(clactonVOR->geod());
pilot->setTargetAltitudeFtMSL(30000);
pilot->setSpeedKts(280);
ok = FGTestApi::runForTimeWithCheck(6000.0, [rmNode] () {
if (rmNode->getIntValue("current-wp") == 2) return true;
return false;
});
CPPUNIT_ASSERT(ok);
// short straight leg for testing
pilot->flyHeading(90.0);
pilot->setSpeedKts(330);
FGTestApi::runForTime(30.0);
// let's engage LNAV mode :)
pilot->flyGPSCourse(m_gps);
ok = FGTestApi::runForTimeWithCheck(6000.0, [rmNode] () {
if (rmNode->getIntValue("current-wp") == 5) return true;
return false;
});
CPPUNIT_ASSERT(ok);
// check where we are - should be heading to RIVER from VALKO
CPPUNIT_ASSERT_EQUAL(5, rmNode->getIntValue("current-wp"));
CPPUNIT_ASSERT(wp0Node->getStringValue("id") == "RIVER");
CPPUNIT_ASSERT(wp1Node->getStringValue("id") == "RTM");
// slightly rapid descent
pilot->setTargetAltitudeFtMSL(3000);
ok = FGTestApi::runForTimeWithCheck(6000.0, [rmNode] () {
if (rmNode->getIntValue("current-wp") == 7) return true;
return false;
});
CPPUNIT_ASSERT(ok);
// run until the GPS reverts to OBS mode at the end of the flight plan
ok = FGTestApi::runForTimeWithCheck(6000.0, [gpsNode] () {
if (gpsNode->getStringValue("mode") == "obs") return true;
return false;
});
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(-1, fp1->currentIndex());
CPPUNIT_ASSERT(!fp1->isActive());
CPPUNIT_ASSERT_EQUAL(-1, rmNode->getIntValue("current-wp"));
CPPUNIT_ASSERT_EQUAL(false, rmNode->getBoolValue("active"));
}
void RouteManagerTests::testDefaultSID()
{
FlightPlanRef fp1 = makeTestFP("EGLC", "27", "EHAM", "24",
"CLN IDRID VALKO");
fp1->setIdent("testplan");
auto rm = globals->get_subsystem<FGRouteMgr>();
rm->setFlightPlan(fp1);
auto rmNode = globals->get_props()->getNode("autopilot/route-manager", true);
rmNode->setStringValue("departure/sid", "DEFAULT");
// let's see what we got :)
rm->activate();
CPPUNIT_ASSERT(fp1->isActive());
}
void RouteManagerTests::testDirectToLegOnFlightplanAndResume()
{
// FGTestApi::setUp::logPositionToKML("rm_dto_resume_leg");
// this is very similar to the identiucally name dtest in GPSTests, but relies on the Nasal
// route manager delegate to perform the same task
FlightPlanRef fp1 = makeTestFP("EBBR", "07L", "EGGD", "27",
"NIK COA DVR TAWNY WOD");
auto rm = globals->get_subsystem<FGRouteMgr>();
rm->setFlightPlan(fp1);
// FGTestApi::writeFlightPlanToKML(fp1);
auto gpsNode = globals->get_props()->getNode("instrumentation/gps", true);
auto rmNode = globals->get_props()->getNode("autopilot/route-manager", true);
CPPUNIT_ASSERT(gpsNode->getStringValue("mode") == "obs");
rm->activate();
CPPUNIT_ASSERT(fp1->isActive());
FGTestApi::setPosition(fp1->departureRunway()->pointOnCenterline(0.0));
FGTestApi::runForTime(10.0); // let the GPS stabilize
CPPUNIT_ASSERT_EQUAL(std::string{"leg"}, gpsNode->getStringValue("mode"));
CPPUNIT_ASSERT_EQUAL(std::string{"EBBR-07L"}, gpsNode->getStringValue("wp/wp[1]/ID"));
CPPUNIT_ASSERT_EQUAL(0, rmNode->getIntValue("current-wp"));
auto wp0Node = rmNode->getNode("wp");
CPPUNIT_ASSERT(wp0Node->getStringValue("id") == "EBBR-07L");
auto wp1Node = rmNode->getNode("wp[1]");
CPPUNIT_ASSERT(wp1Node->getStringValue("id") == "NIK");
// initiate a direct to
SGGeod p2 = fp1->departureRunway()->pointOnCenterline(5.0* SG_NM_TO_METER);
FGTestApi::setPosition(p2);
auto doverVOR = fp1->legAtIndex(3)->waypoint()->source();
double distanceToDover = SGGeodesy::distanceNm(p2, doverVOR->geod());
double bearingToDover = SGGeodesy::courseDeg(p2, doverVOR->geod());
CPPUNIT_ASSERT_EQUAL(std::string{"DVR"}, doverVOR->ident());
gpsNode->setStringValue("scratch/ident", "DVR");
gpsNode->setDoubleValue("scratch/longitude-deg", doverVOR->geod().getLongitudeDeg());
gpsNode->setDoubleValue("scratch/latitude-deg", doverVOR->geod().getLatitudeDeg());
gpsNode->setStringValue("command", "direct");
CPPUNIT_ASSERT_EQUAL(std::string{"dto"}, gpsNode->getStringValue("mode"));
// check that upon reaching DOVER, we sequence to TAWNY and resume leg mode
// this is handled by the default delegate in Nasal
SGGeod posNearDover = SGGeodesy::direct(p2, bearingToDover, (distanceToDover - 8.0) * SG_NM_TO_METER);
FGTestApi::setPosition(posNearDover);
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot);
pilot->resetAtPosition(posNearDover);
pilot->setSpeedKts(250);
pilot->flyGPSCourse(m_gps);
bool ok = FGTestApi::runForTimeWithCheck(180.0, [fp1] () {
if (fp1->currentIndex() == 4) {
return true;
}
return false;
});
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(std::string{"leg"}, gpsNode->getStringValue("mode"));
}
void RouteManagerTests::testSequenceDiscontinuityAndResume()
{
// FGTestApi::setUp::logPositionToKML("rm_seq_discon_resume_leg");
FlightPlanRef fp1 = makeTestFP("LIRF", "16R", "LEBL", "07L",
"GITRI BALEN MUREN TOSNU");
fp1->insertWayptAtIndex(new Discontinuity(fp1), 3);
auto rm = globals->get_subsystem<FGRouteMgr>();
rm->setFlightPlan(fp1);
auto gpsNode = globals->get_props()->getNode("instrumentation/gps", true);
// auto rmNode = globals->get_props()->getNode("autopilot/route-manager", true);
auto balenLeg = fp1->legAtIndex(2);
auto pos = fp1->pointAlongRoute(2, -8.0); // 8nm before BALEN
FGTestApi::setPosition(pos);
FGTestApi::runForTime(10.0); // let the GPS stabilize
CPPUNIT_ASSERT(gpsNode->getStringValue("mode") == "obs");
rm->activate();
CPPUNIT_ASSERT(fp1->isActive());
CPPUNIT_ASSERT(gpsNode->getStringValue("mode") == "leg");
fp1->setCurrentIndex(2);
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot);
pilot->resetAtPosition(pos);
pilot->setCourseTrue(270);
pilot->setSpeedKts(250);
pilot->flyGPSCourse(m_gps);
bool ok = FGTestApi::runForTimeWithCheck(180.0, [gpsNode] () {
return (gpsNode->getStringValue("mode") == "obs");
});
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(2, fp1->currentIndex()); // shouldn't sequence
FGTestApi::runForTime(30.0);
// 2nm before MUREN : this should be on the GC course from BALEN
auto pos2 = fp1->pointAlongRoute(4, -6.0);
FGTestApi::setPosition(pos2);
FGTestApi::runForTime(2.0); // let the GPS stabilize
// initiate a direct-to the next real WP
const auto murenPos = fp1->legAtIndex(4)->waypoint()->position();
gpsNode->setStringValue("scratch/ident", "MUREN");
gpsNode->setDoubleValue("scratch/longitude-deg", murenPos.getLongitudeDeg());
gpsNode->setDoubleValue("scratch/latitude-deg", murenPos.getLatitudeDeg());
gpsNode->setStringValue("command", "direct");
CPPUNIT_ASSERT_EQUAL(std::string{"dto"}, gpsNode->getStringValue("mode"));
pilot->resetAtPosition(pos2);
pilot->flyGPSCourse(m_gps);
ok = FGTestApi::runForTimeWithCheck(600.0, [fp1] () {
if (fp1->currentIndex() == 5) {
return true;
}
return false;
});
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(std::string{"leg"}, gpsNode->getStringValue("mode"));
CPPUNIT_ASSERT_EQUAL(5, fp1->currentIndex());
FGTestApi::runForTime(30.0);
}
void RouteManagerTests::testDefaultApproach()
{
}
void RouteManagerTests::testHiddenWaypoints()
{
FlightPlanRef fp1 = makeTestFP("NZCH", "02", "NZAA", "05L",
"ALADA NS WB WN MAMOD KAPTI OH");
fp1->setIdent("testplan");
fp1->setCruiseFlightLevel(360);
auto rm = globals->get_subsystem<FGRouteMgr>();
rm->setFlightPlan(fp1);
auto gpsNode = globals->get_props()->getNode("instrumentation/gps", true);
CPPUNIT_ASSERT(gpsNode->getStringValue("mode") == "obs");
// FIXME: use real Nasal test macros soon
auto testNode = globals->get_props()->getNode("test-data", true);
fp1->legAtIndex(3)->waypoint()->setFlag(WPT_HIDDEN);
// ensure no visual path is generated for hidden waypoints
RoutePath path(fp1);
// no path should be generated between 2 and 3
CPPUNIT_ASSERT(path.pathForIndex(3).empty());
// no path should be generated between 3 and 4
CPPUNIT_ASSERT(path.pathForIndex(4).empty());
CPPUNIT_ASSERT(!path.pathForIndex(5).empty());
bool ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
setprop("/test-data/a", fp.numRemainingWaypoints());
)");
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(fp1->numLegs(), testNode->getIntValue("a"));
rm->activate();
fp1->setCurrentIndex(2);
ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
setprop("/test-data/a", fp.numRemainingWaypoints());
setprop("/test-data/b", fp.currentWP(2).id);
)");
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(7, testNode->getIntValue("a"));
CPPUNIT_ASSERT_EQUAL(std::string{"WN"}, testNode->getStringValue("b"));
ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
setprop("/test-data/c", fp.currentWP(-1).id);
# ensure invalid offset returns nil
setprop("/test-data/d", fp.currentWP(-100) == nil);
)");
CPPUNIT_ASSERT(ok);
CPPUNIT_ASSERT_EQUAL(std::string{"ALADA"}, testNode->getStringValue("c"));
CPPUNIT_ASSERT_EQUAL(true, testNode->getBoolValue("d"));
}
void RouteManagerTests::testHoldFromNasal()
{
// FGTestApi::setUp::logPositionToKML("rm_hold_from_nasal");
// test that Nasal can set a hold-count (implicitly converting a leg
// to a Hold waypt), configure the hold radial, and exit the hold
FlightPlanRef fp1 = makeTestFP("NZCH", "02", "NZAA", "05L",
"ALADA NS WB WN MAMOD KAPTI OH");
fp1->setIdent("testplan");
fp1->setCruiseFlightLevel(360);
auto rm = globals->get_subsystem<FGRouteMgr>();
rm->setFlightPlan(fp1);
// FGTestApi::writeFlightPlanToKML(fp1);
auto gpsNode = globals->get_props()->getNode("instrumentation/gps", true);
CPPUNIT_ASSERT(gpsNode->getStringValue("mode") == "obs");
rm->activate();
CPPUNIT_ASSERT(fp1->isActive());
CPPUNIT_ASSERT(gpsNode->getStringValue("mode") == "leg");
SGGeod posEnrouteToWB = fp1->pointAlongRoute(3, -10.0);
FGTestApi::setPositionAndStabilise(posEnrouteToWB);
// sequence everything to the correct wp
fp1->setCurrentIndex(3);
// setup some hold data from Nasal. To make it more challenging,
// do it once the wp is already active
bool ok = FGTestApi::executeNasal(R"(
var fp = flightplan(); # retrieve the global flightplan
var leg = fp.getWP(3);
leg.hold_count = 4;
leg.hold_heading_radial_deg = 310;
)");
CPPUNIT_ASSERT(ok);
// check the value updated in the leg
CPPUNIT_ASSERT_EQUAL(4, fp1->legAtIndex(3)->holdCount());
// check we converted to a hold
auto wp = fp1->legAtIndex(3)->waypoint();
auto holdWpt = static_cast<flightgear::Hold*>(wp);
CPPUNIT_ASSERT_EQUAL(wp->type(), std::string{"hold"});
CPPUNIT_ASSERT_DOUBLES_EQUAL(310.0, holdWpt->headingRadialDeg(), 0.5);
// establish the test pilot at this position too
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot);
pilot->resetAtPosition(posEnrouteToWB);
pilot->setSpeedKts(250);
pilot->flyGPSCourse(m_gps);
pilot->setCourseTrue(gpsNode->getDoubleValue("wp/leg-true-course-deg"));
// run for a bit to stabilize everything
FGTestApi::runForTime(5.0);
// check we upgraded to a hold controller internally, and are flying to it :)
auto statusNode = gpsNode->getNode("rnav-controller-status");
CPPUNIT_ASSERT_EQUAL(std::string{"leg-to-hold"}, statusNode->getStringValue());
// check we're on the leg
CPPUNIT_ASSERT_EQUAL(std::string{"NELSON VOR-DME"}, fp1->legAtIndex(2)->waypoint()->source()->name());
auto wbPos = fp1->legAtIndex(3)->waypoint()->position();
auto nsPos = fp1->legAtIndex(2)->waypoint()->position();
const double crsToWB = SGGeodesy::courseDeg(globals->get_aircraft_position(), wbPos);
const double crsNSWB = SGGeodesy::courseDeg(nsPos,wbPos);
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToWB, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5);
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsNSWB, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5);
// fly into the hold, should be teardrop entry
ok = FGTestApi::runForTimeWithCheck(600.0, [statusNode] () {
if (statusNode->getStringValue() == "entry-teardrop") return true;
return false;
});
CPPUNIT_ASSERT(ok);
ok = FGTestApi::runForTimeWithCheck(600.0, [statusNode] () {
if (statusNode->getStringValue() == "hold-inbound") return true;
return false;
});
ok = FGTestApi::runForTimeWithCheck(600.0, [statusNode] () {
if (statusNode->getStringValue() == "hold-outbound") return true;
return false;
});
CPPUNIT_ASSERT(ok);
// half way through the outbound turn
FGTestApi::runForTime(30.0);
ok = FGTestApi::executeNasal(R"(
setprop("/instrumentation/gps/command", "exit-hold");
)");
CPPUNIT_ASSERT(ok);
// no change yet
CPPUNIT_ASSERT_EQUAL(std::string{"hold-outbound"}, statusNode->getStringValue());
// then we fly inbound
ok = FGTestApi::runForTimeWithCheck(600.0, [statusNode] () {
if (statusNode->getStringValue() == "hold-inbound") return true;
return false;
});
CPPUNIT_ASSERT(ok);
// and then we exit
ok = FGTestApi::runForTimeWithCheck(600.0, [fp1] () {
if (fp1->currentIndex() == 4) return true;
return false;
});
CPPUNIT_ASSERT(ok);
// get back on course
FGTestApi::runForTime(60.0);
}
// check that when loading a GPX, airport waypoints are created
// by the default delegate
// https://sourceforge.net/p/flightgear/codetickets/2227/
void RouteManagerTests::loadGPX()
{
auto rm = globals->get_subsystem<FGRouteMgr>();
FlightPlanRef f = FlightPlan::create();
rm->setFlightPlan(f);
SGPath gpxPath = simgear::Dir::current().path() / "test_gpx.gpx";
{
sg_ofstream s(gpxPath);
s << R"(<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creator="SkyVector" version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<rte>
<name>KJFK-KBOS</name>
<rtept lat="40.639928" lon="-73.778692">
<name>KJFK</name>
<overfly>false</overfly>
</rtept>
<rtept lat="41.641106" lon="-72.547419">
<name>HFD</name>
<overfly>false</overfly>
</rtept>
<rtept lat="42.362944" lon="-71.006389">
<name>KBOS</name>
<overfly>false</overfly>
</rtept>
</rte>
</gpx>
)";
}
CPPUNIT_ASSERT(f->load(gpxPath));
auto kbos = FGAirport::getByIdent("KBOS");
auto kjfk = FGAirport::getByIdent("KJFK");
CPPUNIT_ASSERT_EQUAL(kjfk, f->departureAirport());
CPPUNIT_ASSERT_EQUAL(static_cast<FGRunway*>(nullptr), f->departureRunway());
CPPUNIT_ASSERT_EQUAL(3, f->numLegs());
CPPUNIT_ASSERT_EQUAL(kbos, f->destinationAirport());
auto wp1 = f->legAtIndex(1);
CPPUNIT_ASSERT_EQUAL(std::string{"HFD"}, wp1->waypoint()->ident());
auto wp2 = f->legAtIndex(2);
CPPUNIT_ASSERT_EQUAL(std::string{"KBOS"}, wp2->waypoint()->ident());
}
const std::string flightPlanXMLData =
R"(<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
<version type="int">2</version>
<departure>
<airport type="string">EDDM</airport>
<runway type="string">08R</runway>
</departure>
<destination>
<airport type="string">EDDF</airport>
</destination>
<route>
<wp>
<type type="string">runway</type>
<departure type="bool">true</departure>
<ident type="string">08R</ident>
<icao type="string">EDDM</icao>
</wp>
<wp n="1">
<type type="string">navaid</type>
<ident type="string">GIVMI</ident>
<lon type="double">11.364700</lon>
<lat type="double">48.701100</lat>
</wp>
<wp n="2">
<type type="string">navaid</type>
<ident type="string">ERNAS</ident>
<lon type="double">11.219400</lon>
<lat type="double">48.844700</lat>
</wp>
<wp n="3">
<type type="string">navaid</type>
<ident type="string">TALAL</ident>
<lon type="double">11.085300</lon>
<lat type="double">49.108300</lat>
</wp>
<wp n="4">
<type type="string">navaid</type>
<ident type="string">ERMEL</ident>
<lon type="double">11.044700</lon>
<lat type="double">49.187800</lat>
</wp>
<wp n="5">
<type type="string">navaid</type>
<ident type="string">PSA</ident>
<lon type="double">9.348300</lon>
<lat type="double">49.862200</lat>
</wp>
</route>
</PropertyList>
)";
// The same test as above, but for a file exported from the route manager or online
void RouteManagerTests::loadFGFP()
{
auto rm = globals->get_subsystem<FGRouteMgr>();
FlightPlanRef f = FlightPlan::create();
rm->setFlightPlan(f);
SGPath fgfpPath = simgear::Dir::current().path() / "test_fgfp.fgfp";
{
sg_ofstream s(fgfpPath);
s << flightPlanXMLData;
}
CPPUNIT_ASSERT(f->load(fgfpPath));
auto eddm = FGAirport::getByIdent("EDDM");
auto eddf = FGAirport::getByIdent("EDDF");
CPPUNIT_ASSERT_EQUAL(eddm, f->departureAirport());
CPPUNIT_ASSERT_EQUAL(eddm->getRunwayByIdent("08R")->ident(), f->departureRunway()->ident());
CPPUNIT_ASSERT_EQUAL(7, f->numLegs());
CPPUNIT_ASSERT_EQUAL(eddf, f->destinationAirport());
auto wp1 = f->legAtIndex(1);
CPPUNIT_ASSERT_EQUAL(std::string{"GIVMI"}, wp1->waypoint()->ident());
auto wp2 = f->legAtIndex(6);
CPPUNIT_ASSERT_EQUAL(std::string{"EDDF"}, wp2->waypoint()->ident());
}
void RouteManagerTests::testRouteWithProcedures()
{
if (!static_haveProcedures)
return;
auto rm = globals->get_subsystem<FGRouteMgr>();
FlightPlanRef f = FlightPlan::create();
rm->setFlightPlan(f);
auto kjfk = FGAirport::findByIdent("KJFK");
auto eham = FGAirport::findByIdent("EHAM");
f->setDeparture(kjfk->getRunwayByIdent("13L"));
f->setSID(kjfk->findSIDWithIdent("DEEZZ5.13L"), "CANDR");
f->setDestination(eham->getRunwayByIdent("18R"));
f->setSTAR(eham->findSTARWithIdent("EEL1A"), "BEDUM");
f->setApproach(eham->findApproachWithIdent("VDM18R"));
auto w = f->waypointFromString("TOMYE");
f->insertWayptAtIndex(w, f->indexOfFirstNonDepartureWaypoint());
auto w2 = f->waypointFromString("DEVOL");
f->insertWayptAtIndex(w2, f->indexOfFirstArrivalWaypoint());
// let's check what we got
auto endOfSID = f->legAtIndex(f->indexOfFirstNonDepartureWaypoint() - 1);
CPPUNIT_ASSERT_EQUAL(endOfSID->waypoint()->ident(), string{"CANDR"});
auto startOfSTAR = f->legAtIndex(f->indexOfFirstArrivalWaypoint());
CPPUNIT_ASSERT_EQUAL(startOfSTAR->waypoint()->ident(), string{"BEDUM"});
auto endOfSTAR = f->legAtIndex(f->indexOfFirstApproachWaypoint() - 1);
CPPUNIT_ASSERT_EQUAL(endOfSTAR->waypoint()->ident(), string{"ARTIP"});
auto startOfApproach = f->legAtIndex(f->indexOfFirstApproachWaypoint());
CPPUNIT_ASSERT_EQUAL(startOfApproach->waypoint()->ident(), string{"D070O"});
auto landingRunway = f->legAtIndex(f->indexOfDestinationRunwayWaypoint());
CPPUNIT_ASSERT(landingRunway->waypoint()->source() == f->destinationRunway());
auto firstMiss = f->legAtIndex(f->indexOfDestinationRunwayWaypoint() + 1);
CPPUNIT_ASSERT_EQUAL(firstMiss->waypoint()->ident(), string{"(461)"});
// check it in Nasal too
bool ok = FGTestApi::executeNasal(
R"(
var f = flightplan();
var depEnd = f.getWP(f.firstNonDepartureLeg - 1);
var firstArrival = f.getWP(f.firstArrivalLeg);
var firstApproach = f.getWP(f.firstApproachLeg);
var destRunway = f.getWP(f.destination_runway_leg);
unitTest.assert_equal(depEnd.id, 'CANDR');
var firstEnroute = f.getWP(f.firstNonDepartureLeg );
unitTest.assert_equal(firstEnroute.id, 'TOMYE');
unitTest.assert_equal(firstArrival.id, 'BEDUM');
unitTest.assert_equal(firstApproach.id, 'D070O');
unitTest.assert_equal(destRunway.id, '18R');
)");
CPPUNIT_ASSERT(ok);
}
void RouteManagerTests::testRouteWithApproachProcedures()
{
if (!static_haveProcedures)
return;
auto rm = globals->get_subsystem<FGRouteMgr>();
FlightPlanRef f = FlightPlan::create();
rm->setFlightPlan(f);
auto kjfk = FGAirport::findByIdent("KJFK");
auto eddm = FGAirport::findByIdent("EDDM");
f->setDeparture(kjfk->getRunwayByIdent("13L"));
f->setDestination(eddm->getRunwayByIdent("08R"));
f->setSTAR(eddm->findSTARWithIdent("ABGA3A.08R"));
f->setApproach(eddm->findApproachWithIdent("ILS08R"), "NAP08");
auto w = f->waypointFromString("TOMYE");
f->insertWayptAtIndex(w, f->indexOfFirstNonDepartureWaypoint());
auto w2 = f->waypointFromString("DEVOL");
f->insertWayptAtIndex(w2, f->indexOfFirstArrivalWaypoint());
// let's check what we got
auto startOfSTAR = f->legAtIndex(f->indexOfFirstArrivalWaypoint());
CPPUNIT_ASSERT_EQUAL(startOfSTAR->waypoint()->ident(), string{"ABGAS"});
auto endOfSTAR = f->legAtIndex(f->indexOfFirstApproachWaypoint() - 1);
CPPUNIT_ASSERT_EQUAL(endOfSTAR->waypoint()->ident(), string{"MIQ"});
auto startOfApproach = f->legAtIndex(f->indexOfFirstApproachWaypoint());
CPPUNIT_ASSERT_EQUAL(startOfApproach->waypoint()->ident(), string{"NAPSA"});
auto startOfCoreApproach = f->legAtIndex(f->indexOfFirstApproachWaypoint() + 6);
CPPUNIT_ASSERT_EQUAL(startOfCoreApproach->waypoint()->ident(), string{"BEGEN"});
auto landingRunway = f->legAtIndex(f->indexOfDestinationRunwayWaypoint());
CPPUNIT_ASSERT(landingRunway->waypoint()->source() == f->destinationRunway());
// // check it in Nasal too
// bool ok = FGTestApi::executeNasal(
// R"(
// var f = flightplan();
// var depEnd = f.getWP(f.firstNonDepartureLeg - 1);
// var firstArrival = f.getWP(f.firstArrivalLeg);
// var firstApproach = f.getWP(f.firstApproachLeg);
// var destRunway = f.getWP(f.destination_runway_leg);
//
// unitTest.assert_equal(depEnd.id, 'CANDR');
//
// var firstEnroute = f.getWP(f.firstNonDepartureLeg );
// unitTest.assert_equal(firstEnroute.id, 'TOMYE');
//
// unitTest.assert_equal(firstArrival.id, 'BEDUM');
// unitTest.assert_equal(firstApproach.id, 'D070O');
// unitTest.assert_equal(destRunway.id, '18R');
// )");
//
// CPPUNIT_ASSERT(ok);
}
void RouteManagerTests::testsSelectNavaid()
{
// this captures the issue at:
// https://sourceforge.net/p/flightgear/codetickets/2372/
auto rm = globals->get_subsystem<FGRouteMgr>();
FlightPlanRef f = FlightPlan::create();
rm->setFlightPlan(f);
auto usss = FGAirport::findByIdent("USSS");
auto eddh = FGAirport::findByIdent("EDDH");
f->setDeparture(usss); // Yekaterinberg
f->setDestination(eddh);
auto rmNode = globals->get_props()->getNode("autopilot/route-manager", true);
rmNode->setStringValue("input", "@INSERT1:UUDD");
rmNode->setStringValue("input", "@INSERT2:UKKM");
rmNode->setStringValue("input", "@INSERT2:IP");
rmNode->setStringValue("input", "@INSERT3:OD");
auto leg = f->legAtIndex(2);
auto wp1 = leg->waypoint();
CPPUNIT_ASSERT_EQUAL(wp1->ident(), string{"IP"});
CPPUNIT_ASSERT_EQUAL(wp1->source()->name(), string{"ZAKHAROVKA NDB"});
CPPUNIT_ASSERT_DOUBLES_EQUAL(227, leg->courseDeg(), 0.5);
CPPUNIT_ASSERT_DOUBLES_EQUAL(59, leg->distanceNm(), 0.5);
leg = f->legAtIndex(3);
auto wp2 = leg->waypoint();
CPPUNIT_ASSERT_EQUAL(wp2->ident(), string{"OD"});
CPPUNIT_ASSERT_EQUAL(wp2->source()->name(), string{"BRYANSK NDB"});
}
void RouteManagerTests::testsSelectWaypoint()
{
// another part of the issue at
// https://sourceforge.net/p/flightgear/codetickets/2372/
auto rm = globals->get_subsystem<FGRouteMgr>();
FlightPlanRef f = FlightPlan::create();
rm->setFlightPlan(f);
auto rmNode = globals->get_props()->getNode("autopilot/route-manager", true);
rmNode->setStringValue("input", "70N,015E");
rmNode->setStringValue("input", "55N,015E");
rmNode->setStringValue("input", "@INSERT1:OSS");
rmNode->setStringValue("input", "@INSERT2:BOR");
auto leg = f->legAtIndex(1);
auto wp1 = leg->waypoint();
CPPUNIT_ASSERT_EQUAL(wp1->ident(), string{"OSS"});
CPPUNIT_ASSERT_EQUAL(wp1->source()->name(), string{"OSTERSUND VOR-DME"});
// CPPUNIT_ASSERT_DOUBLES_EQUAL(227, leg->courseDeg(), 0.5);
// CPPUNIT_ASSERT_DOUBLES_EQUAL(59, leg->distanceNm(), 0.5);
leg = f->legAtIndex(2);
auto wp2 = leg->waypoint();
CPPUNIT_ASSERT_EQUAL(wp2->ident(), string{"BOR"});
CPPUNIT_ASSERT_EQUAL(wp2->source()->name(), string{"BORLANGE VOR-DME"});
}
void RouteManagerTests::testCommandAPI()
{
auto rm = globals->get_subsystem<FGRouteMgr>();
SGPath fgfpPath = simgear::Dir::current().path() / "test_fgfp_2.fgfp";
{
sg_ofstream s(fgfpPath);
s << flightPlanXMLData;
}
{
SGPropertyNode_ptr args(new SGPropertyNode);
args->setStringValue("path", fgfpPath.utf8Str());
CPPUNIT_ASSERT(globals->get_commands()->execute("load-flightplan", args));
}
auto f = rm->flightPlan();
CPPUNIT_ASSERT_EQUAL(7, f->numLegs());
CPPUNIT_ASSERT(!f->isActive());
{
SGPropertyNode_ptr args(new SGPropertyNode);
CPPUNIT_ASSERT(globals->get_commands()->execute("activate-flightplan", args));
}
CPPUNIT_ASSERT(f->isActive());
{
SGPropertyNode_ptr args(new SGPropertyNode);
args->setIntValue("index", 3);
CPPUNIT_ASSERT(globals->get_commands()->execute("set-active-waypt", args));
}
CPPUNIT_ASSERT_EQUAL(3, f->currentIndex());
{
SGPropertyNode_ptr args(new SGPropertyNode);
args->setIntValue("index", 4);
args->setStringValue("navaid", "WLD");
// let's build an offset waypoint for fun
args->setDoubleValue("offset-nm", 10.0);
args->setDoubleValue("radial", 30);
CPPUNIT_ASSERT(globals->get_commands()->execute("insert-waypt", args));
}
auto waldaWpt = f->legAtIndex(4)->waypoint();
auto waldaVOR = waldaWpt->source();
CPPUNIT_ASSERT_EQUAL(string{"WALDA VOR-DME"}, waldaVOR->name());
auto d = SGGeodesy::distanceNm(waldaVOR->geod(), waldaWpt->position());
CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, d, 0.1);
}
void RouteManagerTests::testRMBug2616()
{
auto edty = FGAirport::findByIdent("EDTY"s);
edty->testSuiteInjectProceduresXML(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "EDTY.procedures.xml");
auto ils28Approach = edty->findApproachWithIdent("ILS28"s);
CPPUNIT_ASSERT(ils28Approach);
auto rm = globals->get_subsystem<FGRouteMgr>();
auto f = rm->flightPlan();
f->clearLegs();
auto edds = FGAirport::findByIdent("EDDS");
f->setDeparture(edds->getRunwayByIdent("25"));
f->setDestination(edty->getRunwayByIdent("28"));
f->setApproach(ils28Approach);
CPPUNIT_ASSERT(f->destinationRunway()->ident() == "28"s);
CPPUNIT_ASSERT(f->approach()->ident() == "ILS28"s);
rm->activate();
CPPUNIT_ASSERT(f->isActive());
}
void RouteManagerTests::testsSelectWaypoint2()
{
auto rm = globals->get_subsystem<FGRouteMgr>();
FlightPlanRef f = FlightPlan::create();
rm->setFlightPlan(f);
auto rmNode = globals->get_props()->getNode("autopilot/route-manager", true);
rmNode->setStringValue("input", "UAAA");
rmNode->setStringValue("input", "EDDH");
rmNode->setStringValue("input", "@INSERT1:ALM");
auto leg = f->legAtIndex(1);
auto wp1 = leg->waypoint();
CPPUNIT_ASSERT_EQUAL(wp1->ident(), string{"ALM"});
// CPPUNIT_ASSERT_EQUAL(wp1->source()->name(), string{"ALMATY VOR-DME"});
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright (C) 2019 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/>.
*/
#ifndef _FG_ROUTE_MANAGER_UNIT_TESTS_HXX
#define _FG_ROUTE_MANAGER_UNIT_TESTS_HXX
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
class SGGeod;
class GPS;
// The flight plan unit tests.
class RouteManagerTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(RouteManagerTests);
CPPUNIT_TEST(testBasic);
CPPUNIT_TEST(testDefaultSID);
CPPUNIT_TEST(testDefaultApproach);
CPPUNIT_TEST(testDirectToLegOnFlightplanAndResume);
CPPUNIT_TEST(testHoldFromNasal);
CPPUNIT_TEST(testSequenceDiscontinuityAndResume);
CPPUNIT_TEST(testHiddenWaypoints);
CPPUNIT_TEST(loadGPX);
CPPUNIT_TEST(loadFGFP);
CPPUNIT_TEST(testRouteWithProcedures);
CPPUNIT_TEST(testRouteWithApproachProcedures);
CPPUNIT_TEST(testsSelectNavaid);
CPPUNIT_TEST(testCommandAPI);
CPPUNIT_TEST(testRMBug2616);
CPPUNIT_TEST(testsSelectWaypoint);
CPPUNIT_TEST(testsSelectWaypoint2);
CPPUNIT_TEST_SUITE_END();
// void setPositionAndStabilise(FGNavRadio* r, const SGGeod& g);
public:
// Set up function for each test.
void setUp();
// Clean up after each test.
void tearDown();
void setPositionAndStabilise(const SGGeod& g);
// The tests.
void testBasic();
void testDefaultSID();
void testDefaultApproach();
void testDirectToLegOnFlightplanAndResume();
void testHoldFromNasal();
void testSequenceDiscontinuityAndResume();
void testHiddenWaypoints();
void loadGPX();
void loadFGFP();
void testRouteWithProcedures();
void testRouteWithApproachProcedures();
void testsSelectNavaid();
void testCommandAPI();
void testsSelectWaypoint();
void testRMBug2616();
void testsSelectWaypoint2();
private:
GPS* m_gps = nullptr;
};
#endif // _FG_ROUTE_MANAGER_UNIT_TESTS_HXX