From 24c21bf876300e00933243ac384b266cb83025ae Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Sun, 10 May 2020 14:32:04 +0100 Subject: [PATCH] Double posinit test Testcase for running posinit twice. posinit sets various properties which it then reads, so there's a possibility that it could write a value which causes unexpected behaviour when run later. Unclear if this should be a unit test or a system test, but it's simple enough to be a unit test. --- test_suite/unit_tests/Main/test_posinit.cxx | 41 ++++++++++++++++++++- test_suite/unit_tests/Main/test_posinit.hxx | 7 +++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/test_suite/unit_tests/Main/test_posinit.cxx b/test_suite/unit_tests/Main/test_posinit.cxx index bea0fdc6e..6725c83d0 100644 --- a/test_suite/unit_tests/Main/test_posinit.cxx +++ b/test_suite/unit_tests/Main/test_posinit.cxx @@ -67,7 +67,6 @@ void PosInitTests::checkPosition(SGGeod expectedPos, float delta) { double dist = SGGeodesy::distanceM(globals->get_aircraft_position(), expectedPos); - std::cerr << "Position distance " << dist << "\n"; CPPUNIT_ASSERT_MESSAGE("Unexpected Position", dist < delta); } @@ -184,6 +183,7 @@ void PosInitTests::testAirportAndRunwayStartup() checkClosestAirport(std::string("EDDF")); checkPosition(FGAirport::getByIdent("EDDF")->geod(), 10000.0); + checkHeading(250.0); } void PosInitTests::testAirportAndParkingStartup() @@ -534,3 +534,42 @@ void PosInitTests::testCarrierStartup() checkPosition(SGGeod::fromDeg(-122.6, 37.8), 100.0); checkOnGround(); } + +void PosInitTests::testAirportRepositionAirport() +{ + { + Options* opts = Options::sharedInstance(); + opts->setShouldLoadDefaultConfig(false); + + const char* args[] = {"dummypath", "--airport=EDDF", "--runway=25C"}; + opts->init(3, (char**) args, SGPath()); + opts->processOptions(); + } + + std::cout << "Preset heading " << fgGetDouble("/sim/presets/heading-deg") << "\n"; + + CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested")); + CPPUNIT_ASSERT(fgGetBool("/sim/presets/runway-requested")); + checkRunway(std::string("25C")); + initPosition(); + + checkClosestAirport(std::string("EDDF")); + checkPosition(FGAirport::getByIdent("EDDF")->geod(), 10000.0); + checkHeading(250.0); + + std::cout << "Preset heading " << fgGetDouble("/sim/presets/heading-deg") << "\n"; + + // Now re-position to KSFO runway + // Reset the Lat/Lon as these will be used in preference to the airport ID + fgSetDouble("/sim/presets/longitude-deg", -9990.00); + fgSetDouble("/sim/presets/latitude-deg", -9990.00); + fgSetString("/sim/presets/airport-id", "KHAF"); + fgSetDouble("/sim/presets/heading-deg", 9990.00); + fgSetString("/sim/presets/runway", "12"); + initPosition(); + + checkClosestAirport(std::string("KHAF")); + checkPosition(FGAirport::getByIdent("KHAF")->geod(), 5000.0); + checkHeading(137.0); // Lots of magnetic variation in SF Bay area! + checkOnGround(); +} diff --git a/test_suite/unit_tests/Main/test_posinit.hxx b/test_suite/unit_tests/Main/test_posinit.hxx index f742b0385..1c4ad8688 100644 --- a/test_suite/unit_tests/Main/test_posinit.hxx +++ b/test_suite/unit_tests/Main/test_posinit.hxx @@ -55,13 +55,15 @@ class PosInitTests : public CppUnit::TestFixture CPPUNIT_TEST(testLatLonStartup); //CPPUNIT_TEST(testLatLonOffsetStartup); This is not yet supported. - // Carrier tests // We are not able to test the carrier code thoroughly as it depends // heavily on finalizePosition(), which requires that the carrier model // itself be loaded into the scenegraph. CPPUNIT_TEST(testCarrierStartup); + // Reposition tests + CPPUNIT_TEST(testAirportRepositionAirport); + CPPUNIT_TEST_SUITE_END(); public: @@ -97,6 +99,9 @@ public: //Carrier tests void testCarrierStartup(); + //Reposition tests + void testAirportRepositionAirport(); + private: // Helper functions for tests. Return void as they use CPPUNIT_ASSERT void checkAlt(float value);