2017-03-21 20:43:42 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2018-03-28 15:30:59 +00:00
|
|
|
#include "test_suite/dataStore.hxx"
|
|
|
|
|
2018-03-13 19:56:31 +00:00
|
|
|
#include "globals.hxx"
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-06-11 09:35:09 +00:00
|
|
|
#if defined(HAVE_QT)
|
2018-03-28 22:39:38 +00:00
|
|
|
#include <GUI/QtLauncher.hxx>
|
|
|
|
#endif
|
|
|
|
|
2017-03-21 20:43:42 +00:00
|
|
|
#include <Main/globals.hxx>
|
2017-03-27 14:37:54 +00:00
|
|
|
#include <Main/options.hxx>
|
|
|
|
|
2017-03-21 20:43:42 +00:00
|
|
|
#include <Time/TimeManager.hxx>
|
|
|
|
|
2018-06-12 12:28:23 +00:00
|
|
|
#include <simgear/structure/event_mgr.hxx>
|
2017-03-21 20:43:42 +00:00
|
|
|
#include <simgear/timing/timestamp.hxx>
|
2018-10-10 08:26:06 +00:00
|
|
|
#include <simgear/math/sg_geodesy.hxx>
|
2017-03-27 14:37:54 +00:00
|
|
|
|
2019-04-23 17:10:39 +00:00
|
|
|
#include <Airports/airport.hxx>
|
|
|
|
#include <Navaids/FlightPlan.hxx>
|
|
|
|
#include <Navaids/waypoint.hxx>
|
|
|
|
|
|
|
|
using namespace flightgear;
|
|
|
|
|
2018-07-16 13:59:21 +00:00
|
|
|
namespace FGTestApi {
|
|
|
|
|
|
|
|
namespace setUp {
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-06-10 13:43:20 +00:00
|
|
|
void initTestGlobals(const std::string& testName)
|
|
|
|
{
|
2017-03-21 20:43:42 +00:00
|
|
|
globals = new FGGlobals;
|
|
|
|
|
2018-03-28 15:30:59 +00:00
|
|
|
DataStore &data = DataStore::get();
|
2018-06-05 12:31:06 +00:00
|
|
|
if (!data.getFGRoot().exists()) {
|
|
|
|
data.findFGRoot("");
|
|
|
|
}
|
2018-03-28 15:30:59 +00:00
|
|
|
globals->set_fg_root(data.getFGRoot());
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-06-10 13:43:20 +00:00
|
|
|
// current dir
|
|
|
|
SGPath homePath = SGPath::fromUtf8(FGBUILDDIR) / "test_home";
|
|
|
|
if (!homePath.exists()) {
|
|
|
|
(homePath / "dummyFile").create_dir(0755);
|
|
|
|
}
|
2017-03-27 14:37:54 +00:00
|
|
|
|
2018-06-10 13:43:20 +00:00
|
|
|
globals->set_fg_home(homePath);
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-06-11 06:50:36 +00:00
|
|
|
// Activate headless mode.
|
|
|
|
globals->set_headless(true);
|
|
|
|
|
2018-06-10 13:43:20 +00:00
|
|
|
fgSetDefaults();
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-06-10 13:43:20 +00:00
|
|
|
std::unique_ptr<TimeManager> t;
|
|
|
|
t.reset(new TimeManager);
|
|
|
|
t->init(); // establish mag-var data
|
2018-06-12 12:28:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Both the event manager and subsystem manager are initialised by the
|
|
|
|
* FGGlobals ctor, but only the subsystem manager is destroyed by the dtor.
|
|
|
|
* Here the event manager is added to the subsystem manager so it can be
|
|
|
|
* destroyed via the subsystem manager.
|
|
|
|
*/
|
|
|
|
globals->add_subsystem("events", globals->get_event_mgr(), SGSubsystemMgr::DISPLAY);
|
2018-06-10 13:43:20 +00:00
|
|
|
}
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2019-04-23 17:10:39 +00:00
|
|
|
void populateFP(flightgear::FlightPlanRef f,
|
|
|
|
const std::string& depICAO, const std::string& depRunway,
|
|
|
|
const std::string& destICAO, const std::string& destRunway,
|
|
|
|
const std::string& waypoints)
|
|
|
|
{
|
|
|
|
FGAirportRef depApt = FGAirport::getByIdent(depICAO);
|
|
|
|
f->setDeparture(depApt->getRunwayByIdent(depRunway));
|
|
|
|
|
|
|
|
|
|
|
|
FGAirportRef destApt = FGAirport::getByIdent(destICAO);
|
|
|
|
f->setDestination(destApt->getRunwayByIdent(destRunway));
|
|
|
|
|
|
|
|
// since we don't have the Nasal route-manager delegate, insert the
|
|
|
|
// runway waypoints manually
|
|
|
|
|
|
|
|
f->insertWayptAtIndex(new RunwayWaypt(f->departureRunway(), f), -1);
|
|
|
|
|
|
|
|
for (auto ws : simgear::strutils::split(waypoints)) {
|
|
|
|
WayptRef wpt = f->waypointFromString(ws);
|
|
|
|
f->insertWayptAtIndex(wpt, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto destRwy = f->destinationRunway();
|
|
|
|
f->insertWayptAtIndex(new BasicWaypt(destRwy->pointOnCenterline(-8 * SG_NM_TO_METER),
|
|
|
|
destRwy->ident() + "-8", f), -1);
|
|
|
|
f->insertWayptAtIndex(new RunwayWaypt(destRwy, f), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-16 13:59:21 +00:00
|
|
|
} // End of namespace setUp.
|
|
|
|
|
2018-10-10 08:26:06 +00:00
|
|
|
void setPosition(const SGGeod& g)
|
|
|
|
{
|
|
|
|
globals->get_props()->setDoubleValue("position/latitude-deg", g.getLatitudeDeg());
|
|
|
|
globals->get_props()->setDoubleValue("position/longitude-deg", g.getLongitudeDeg());
|
|
|
|
globals->get_props()->setDoubleValue("position/altitude-ft", g.getElevationFt());
|
|
|
|
}
|
2018-07-16 13:59:21 +00:00
|
|
|
|
2019-04-22 10:57:55 +00:00
|
|
|
void runForTime(double t)
|
|
|
|
{
|
|
|
|
int ticks = t * 120.0;
|
|
|
|
assert(ticks > 0);
|
|
|
|
|
|
|
|
for (int t = 0; t < ticks; ++t) {
|
|
|
|
globals->get_subsystem_mgr()->update(1 / 120.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 13:59:21 +00:00
|
|
|
namespace tearDown {
|
|
|
|
|
2018-06-10 13:43:20 +00:00
|
|
|
void shutdownTestGlobals()
|
|
|
|
{
|
2018-03-28 22:39:38 +00:00
|
|
|
// The QApplication instance must be destroyed before exit() begins, see
|
|
|
|
// <https://bugreports.qt.io/browse/QTBUG-48709> (otherwise, segfault).
|
2018-06-11 09:35:09 +00:00
|
|
|
#if defined(HAVE_QT)
|
2018-03-28 22:39:38 +00:00
|
|
|
flightgear::shutdownQtApp();
|
|
|
|
#endif
|
|
|
|
|
2017-03-21 20:43:42 +00:00
|
|
|
delete globals;
|
2018-06-10 13:43:20 +00:00
|
|
|
}
|
2018-07-16 13:59:21 +00:00
|
|
|
|
|
|
|
} // End of namespace tearDown.
|
|
|
|
|
|
|
|
} // End of namespace FGTestApi.
|