From cd5a0ffe0bc46f83764658686a74c3345c0ad6f6 Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Sat, 27 Jun 2020 12:57:55 +0100 Subject: [PATCH] Expose totalDistanceNm to Nasal flightplan ghost Requested by Tobias Dammers, includes associated test. May be cherry-picked to 2020.2. --- src/Scripting/NasalFlightPlan.cxx | 2 ++ .../unit_tests/Navaids/test_fpNasal.cxx | 19 ++++++++++++++++++- .../unit_tests/Navaids/test_fpNasal.hxx | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Scripting/NasalFlightPlan.cxx b/src/Scripting/NasalFlightPlan.cxx index a38eb1998..22c6d2994 100644 --- a/src/Scripting/NasalFlightPlan.cxx +++ b/src/Scripting/NasalFlightPlan.cxx @@ -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; diff --git a/test_suite/unit_tests/Navaids/test_fpNasal.cxx b/test_suite/unit_tests/Navaids/test_fpNasal.cxx index 94d2ec975..1b21bbe77 100644 --- a/test_suite/unit_tests/Navaids/test_fpNasal.cxx +++ b/test_suite/unit_tests/Navaids/test_fpNasal.cxx @@ -314,4 +314,21 @@ void FPNasalTests::testAirwaysAPI() )"); CPPUNIT_ASSERT(ok); -} \ No newline at end of file +} + +void FPNasalTests::testTotalDistanceAPI() +{ + auto rm = globals->get_subsystem(); + + 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); +} diff --git a/test_suite/unit_tests/Navaids/test_fpNasal.hxx b/test_suite/unit_tests/Navaids/test_fpNasal.hxx index bc49c1063..9250a0502 100644 --- a/test_suite/unit_tests/Navaids/test_fpNasal.hxx +++ b/test_suite/unit_tests/Navaids/test_fpNasal.hxx @@ -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(); };