2018-03-01 12:13:03 +00:00
|
|
|
#include "test_flightplan.hxx"
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-07-16 13:59:21 +00:00
|
|
|
#include "test_suite/FGTestApi/globals.hxx"
|
2018-06-10 13:43:20 +00:00
|
|
|
#include "test_suite/FGTestApi/NavDataCache.hxx"
|
2017-03-21 20:43:42 +00:00
|
|
|
|
|
|
|
#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 <Airports/airport.hxx>
|
|
|
|
|
|
|
|
using namespace flightgear;
|
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
|
|
|
|
// Set up function for each test.
|
|
|
|
void FlightplanTests::setUp()
|
|
|
|
{
|
2018-07-16 13:59:21 +00:00
|
|
|
FGTestApi::setUp::initTestGlobals("flightplan");
|
2018-06-10 13:43:20 +00:00
|
|
|
FGTestApi::setUp::initNavDataCache();
|
2018-03-01 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Clean up after each test.
|
|
|
|
void FlightplanTests::tearDown()
|
|
|
|
{
|
2018-07-16 13:59:21 +00:00
|
|
|
FGTestApi::tearDown::shutdownTestGlobals();
|
2018-03-01 12:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-21 20:43:42 +00:00
|
|
|
FlightPlanRef makeTestFP(const std::string& depICAO, const std::string& depRunway,
|
|
|
|
const std::string& destICAO, const std::string& destRunway,
|
|
|
|
const std::string& waypoints)
|
|
|
|
{
|
|
|
|
FlightPlanRef f = new FlightPlan;
|
|
|
|
|
|
|
|
FGAirportRef depApt = FGAirport::getByIdent(depICAO);
|
|
|
|
f->setDeparture(depApt->getRunwayByIdent(depRunway));
|
|
|
|
|
|
|
|
|
|
|
|
FGAirportRef destApt = FGAirport::getByIdent(destICAO);
|
|
|
|
f->setDestination(destApt->getRunwayByIdent(destRunway));
|
|
|
|
|
|
|
|
for (auto ws : simgear::strutils::split(waypoints)) {
|
|
|
|
WayptRef wpt = f->waypointFromString(ws);
|
|
|
|
f->insertWayptAtIndex(wpt, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
void FlightplanTests::testBasic()
|
2017-03-21 20:43:42 +00:00
|
|
|
{
|
|
|
|
FlightPlanRef fp1 = makeTestFP("EGCC", "23L", "EHAM", "24",
|
|
|
|
"TNT CLN");
|
|
|
|
fp1->setIdent("testplan");
|
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
CPPUNIT_ASSERT(fp1->ident() == "testplan");
|
|
|
|
CPPUNIT_ASSERT(fp1->departureAirport()->ident() == "EGCC");
|
|
|
|
CPPUNIT_ASSERT(fp1->departureRunway()->ident() == "23L");
|
|
|
|
CPPUNIT_ASSERT(fp1->destinationAirport()->ident() == "EHAM");
|
|
|
|
CPPUNIT_ASSERT(fp1->destinationRunway()->ident() == "24");
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(fp1->numLegs(), 2);
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
CPPUNIT_ASSERT(fp1->legAtIndex(0)->waypoint()->source()->ident() == "TNT");
|
|
|
|
CPPUNIT_ASSERT(fp1->legAtIndex(0)->waypoint()->source()->name() == "TRENT VOR-DME");
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
CPPUNIT_ASSERT(fp1->legAtIndex(1)->waypoint()->source()->ident() == "CLN");
|
|
|
|
CPPUNIT_ASSERT(fp1->legAtIndex(1)->waypoint()->source()->name() == "CLACTON VOR-DME");
|
2017-03-21 20:43:42 +00:00
|
|
|
}
|
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
void FlightplanTests::testRoutePathBasic()
|
2017-03-21 20:43:42 +00:00
|
|
|
{
|
|
|
|
FlightPlanRef fp1 = makeTestFP("EGHI", "20", "EDDM", "08L",
|
|
|
|
"SFD LYD BNE CIV ELLX LUX SAA KRH WLD");
|
|
|
|
|
|
|
|
|
|
|
|
RoutePath rtepath(fp1);
|
2017-04-04 21:15:18 +00:00
|
|
|
const int legCount = fp1->numLegs();
|
2017-03-21 20:43:42 +00:00
|
|
|
for (int leg = 0; leg < legCount; ++leg) {
|
|
|
|
rtepath.trackForIndex(leg);
|
|
|
|
rtepath.pathForIndex(leg);
|
|
|
|
rtepath.distanceForIndex(leg);
|
|
|
|
}
|
|
|
|
|
|
|
|
rtepath.distanceBetweenIndices(2, 5);
|
|
|
|
|
|
|
|
// check some leg parameters
|
|
|
|
|
|
|
|
// BOLOUGNE SUR MER, near LFAY (AMIENS)
|
|
|
|
FGNavRecordRef bne = FGNavList::findByFreq(113.8, FGAirport::getByIdent("LFAY")->geod());
|
|
|
|
|
|
|
|
// CHIEVRES
|
|
|
|
FGNavRecordRef civ = FGNavList::findByFreq(113.2, FGAirport::getByIdent("EBCI")->geod());
|
|
|
|
|
|
|
|
double distM = SGGeodesy::distanceM(bne->geod(), civ->geod());
|
|
|
|
double trackDeg = SGGeodesy::courseDeg(bne->geod(), civ->geod());
|
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
CPPUNIT_ASSERT_DOUBLES_EQUAL(trackDeg, rtepath.trackForIndex(3), 0.5);
|
|
|
|
CPPUNIT_ASSERT_DOUBLES_EQUAL(distM, rtepath.distanceForIndex(3), 2000); // 2km precision, allow for turns
|
2017-03-21 20:43:42 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://sourceforge.net/p/flightgear/codetickets/1703/
|
|
|
|
// https://sourceforge.net/p/flightgear/codetickets/1939/
|
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
void FlightplanTests::testRoutePathSkipped()
|
2017-03-21 20:43:42 +00:00
|
|
|
{
|
|
|
|
FlightPlanRef fp1 = makeTestFP("EHAM", "24", "EDDM", "08L",
|
|
|
|
"EHEH KBO TAU FFM FFM/100/0.01 FFM/120/0.02 WUR WLD");
|
|
|
|
|
|
|
|
|
|
|
|
RoutePath rtepath(fp1);
|
|
|
|
|
|
|
|
// skipped point uses inbound track
|
2018-03-01 12:13:03 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(rtepath.trackForIndex(3), rtepath.trackForIndex(4));
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, rtepath.distanceForIndex(4), 1e-9);
|
|
|
|
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, rtepath.distanceForIndex(5), 1e-9);
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
CPPUNIT_ASSERT_DOUBLES_EQUAL(101000, rtepath.distanceForIndex(6), 1000);
|
2017-03-21 20:43:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
// this tests skipping two preceeding points works as it should
|
|
|
|
SGGeodVec vec = rtepath.pathForIndex(6);
|
2018-03-01 12:13:03 +00:00
|
|
|
CPPUNIT_ASSERT(vec.size() == 9);
|
2017-03-21 20:43:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
void FlightplanTests::testRoutePathTrivialFlightPlan()
|
2017-03-21 20:43:42 +00:00
|
|
|
{
|
|
|
|
FlightPlanRef fp1 = makeTestFP("EGPH", "24", "EGPH", "06",
|
|
|
|
"");
|
|
|
|
|
|
|
|
|
|
|
|
RoutePath rtepath(fp1);
|
2017-04-04 21:15:18 +00:00
|
|
|
const int legCount = fp1->numLegs();
|
2017-03-21 20:43:42 +00:00
|
|
|
for (int leg = 0; leg < legCount; ++leg) {
|
|
|
|
rtepath.trackForIndex(leg);
|
|
|
|
rtepath.pathForIndex(leg);
|
|
|
|
rtepath.distanceForIndex(leg);
|
|
|
|
}
|
|
|
|
|
2018-03-01 12:13:03 +00:00
|
|
|
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, fp1->totalDistanceNm(), 1e-9);
|
2017-03-21 20:43:42 +00:00
|
|
|
}
|