diff --git a/src/Main/test_posinit.cxx b/src/Main/test_posinit.cxx new file mode 100644 index 000000000..f746ab570 --- /dev/null +++ b/src/Main/test_posinit.cxx @@ -0,0 +1,119 @@ +#include "config.h" + +#include "unitTestHelpers.hxx" + +#include +#include + +#include "Main/positioninit.hxx" +#include "Main/options.hxx" +#include "Main/globals.hxx" +#include "Main/fg_props.hxx" + +#include "Airports/airport.hxx" + +using namespace flightgear; + +void testDefaultStartup() +{ + fgtest::initTestGlobals("posinit"); + Options::reset(); + + fgLoadProps("defaults.xml", globals->get_props()); + + { + Options* opts = Options::sharedInstance(); + opts->setShouldLoadDefaultConfig(false); + + const char* args[] = {"dummypath"}; + opts->init(1, (char**) args, SGPath()); + opts->processOptions(); + } + + initPosition(); + + // verify we got the location specified in location-preset.xml + // this unfortunately means manually parsing that file, oh well + + { + SGPath presets = fgtest::fgdataPath() / "location-presets.xml"; + SG_VERIFY(presets.exists()); + SGPropertyNode_ptr props(new SGPropertyNode); + readProperties(presets, props); + + std::string icao = props->getStringValue("/sim/presets/airport-id"); + SG_CHECK_EQUAL(globals->get_props()->getStringValue("/sim/airport/closest-airport-id"), icao); + + SGGeod pos = globals->get_aircraft_position(); + + FGAirportRef defaultAirport = FGAirport::getByIdent(icao); + + double dist = SGGeodesy::distanceM(pos, defaultAirport->geod()); + SG_CHECK_LT(dist, 10000); + } + fgtest::shutdownTestGlobals(); + +} + +void testAirportOnlyStartup() +{ + fgtest::initTestGlobals("posinit"); + Options::reset(); + fgLoadProps("defaults.xml", globals->get_props()); + + { + Options* opts = Options::sharedInstance(); + opts->setShouldLoadDefaultConfig(false); + + const char* args[] = {"dummypath", "--airport=EDDF"}; + opts->init(2, (char**) args, SGPath()); + opts->processOptions(); + } + + SG_VERIFY(fgGetBool("/sim/presets/airport-requested")); + initPosition(); + + SG_CHECK_EQUAL(globals->get_props()->getStringValue("/sim/airport/closest-airport-id"), std::string("EDDF")); + double dist = SGGeodesy::distanceM(globals->get_aircraft_position(), + FGAirport::getByIdent("EDDF")->geod()); + SG_CHECK_LT(dist, 10000); + fgtest::shutdownTestGlobals(); + +} + +void testAirportAndMetarStartup() +{ + fgtest::initTestGlobals("posinit"); + + Options::reset(); + fgLoadProps("defaults.xml", globals->get_props()); + + { + Options* opts = Options::sharedInstance(); + opts->setShouldLoadDefaultConfig(false); + const char* args[] = {"dummypath", "--airport=LOWI", "--metar=XXXX 271320Z 08007KT 030V130 CAVOK 17/02 Q1020 NOSIG"}; + opts->init(3, (char**) args, SGPath()); + opts->processOptions(); + } + + initPosition(); + + SG_CHECK_EQUAL(globals->get_props()->getStringValue("/sim/airport/closest-airport-id"), std::string("LOWI")); + double dist = SGGeodesy::distanceM(globals->get_aircraft_position(), + FGAirport::getByIdent("LOWI")->geod()); + SG_CHECK_LT(dist, 10000); + ///sim/atc/runway + SG_CHECK_EQUAL(globals->get_props()->getStringValue("sim/atc/runway"), std::string("26")); + + fgtest::shutdownTestGlobals(); +} + +int main(int argc, char* argv[]) +{ + + testDefaultStartup(); + testAirportOnlyStartup(); + testAirportAndMetarStartup(); + + return EXIT_SUCCESS; +}