diff --git a/test_suite/unit_tests/Instrumentation/test_gps.cxx b/test_suite/unit_tests/Instrumentation/test_gps.cxx index 68a70ec26..104ec2091 100644 --- a/test_suite/unit_tests/Instrumentation/test_gps.cxx +++ b/test_suite/unit_tests/Instrumentation/test_gps.cxx @@ -1529,3 +1529,53 @@ void GPSTests::testDMEIntercept() CPPUNIT_ASSERT(ok); } + +void GPSTests::testFinalLegCourse() +{ + // FGTestApi::setUp::logPositionToKML("gps_dme_intercept"); + auto rm = globals->get_subsystem(); + auto fp = new FlightPlan; + rm->setFlightPlan(fp); + + // we can't use the standard function as it puts a waypoint on + // the extended centerline + FGAirportRef depApt = FGAirport::getByIdent("EGAA"); + fp->setDeparture(depApt->getRunwayByIdent("07")); + + + FGAirportRef destApt = FGAirport::getByIdent("EGPF"); + fp->setDestination(destApt->getRunwayByIdent("23")); + + // since we don't have the Nasal route-manager delegate, insert the + // runway waypoints manually + auto depRwy = new RunwayWaypt(fp->departureRunway(), fp); + depRwy->setFlag(WPT_DEPARTURE); + fp->insertWayptAtIndex(depRwy, -1); + + fp->insertWayptAtIndex(fp->waypointFromString("LISBO"), -1); + + auto destRwy = fp->destinationRunway(); + fp->insertWayptAtIndex(new RunwayWaypt(destRwy, fp), -1); + + // takes the place of the Nasal delegates + auto testDelegate = new TestFPDelegate; + testDelegate->thePlan = fp; + CPPUNIT_ASSERT(rm->activate()); + fp->addDelegate(testDelegate); + auto gps = setupStandardGPS(); + + fp->setCurrentIndex(2); + + // position halfway between EGAA and EGPF + SGGeod initPos = fp->pointAlongRoute(1, -30.5); + FGTestApi::setPositionAndStabilise(initPos); + + auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); + gpsNode->setBoolValue("config/delegate-sequencing", true); + gpsNode->setStringValue("command", "leg"); + + + FGTestApi::writeFlightPlanToKML(fp); + // check that the final leg course doesn't fall back to 233 deg + CPPUNIT_ASSERT_DOUBLES_EQUAL(37, gpsNode->getDoubleValue("desired-course-deg"), 2.0); +} diff --git a/test_suite/unit_tests/Instrumentation/test_gps.hxx b/test_suite/unit_tests/Instrumentation/test_gps.hxx index 782b695d2..5773f4f65 100644 --- a/test_suite/unit_tests/Instrumentation/test_gps.hxx +++ b/test_suite/unit_tests/Instrumentation/test_gps.hxx @@ -54,6 +54,7 @@ class GPSTests : public CppUnit::TestFixture CPPUNIT_TEST(testBuiltinRevertToOBSAtEnd); CPPUNIT_TEST(testRadialIntercept); CPPUNIT_TEST(testDMEIntercept); + CPPUNIT_TEST(testFinalLegCourse); CPPUNIT_TEST_SUITE_END(); @@ -88,6 +89,7 @@ public: void testBuiltinRevertToOBSAtEnd(); void testRadialIntercept(); void testDMEIntercept(); + void testFinalLegCourse(); }; #endif // _FG_GPS_UNIT_TESTS_HXX