1
0
Fork 0

Expose totalDistanceNm to Nasal flightplan ghost

Requested by Tobias Dammers, includes associated test. 
May be cherry-picked to 2020.2.
This commit is contained in:
legoboyvdlp R 2020-06-27 12:57:55 +01:00 committed by James Turner
parent 034c9f4c86
commit cd5a0ffe0b
3 changed files with 22 additions and 1 deletions

View file

@ -632,6 +632,8 @@ static const char* flightplanGhostGetMember(naContext c, void* g, naRef field, n
*out = naNum(fp->indexOfFirstApproachWaypoint());
else if (!strcmp(fieldName, "destination_runway_leg"))
*out = naNum(fp->indexOfDestinationRunwayWaypoint());
else if (!strcmp(fieldName, "totalDistanceNm"))
*out = naNum(fp->totalDistanceNm());
else {
return nullptr;

View file

@ -314,4 +314,21 @@ void FPNasalTests::testAirwaysAPI()
)");
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

@ -36,6 +36,7 @@ class FPNasalTests : public CppUnit::TestFixture
CPPUNIT_TEST(testApproachTransitionAPI);
CPPUNIT_TEST(testApproachTransitionAPIWithCloning);
CPPUNIT_TEST(testAirwaysAPI);
CPPUNIT_TEST(testTotalDistanceAPI);
CPPUNIT_TEST_SUITE_END();
@ -54,4 +55,5 @@ public:
void testApproachTransitionAPI();
void testApproachTransitionAPIWithCloning();
void testAirwaysAPI();
void testTotalDistanceAPI();
};