2017-03-21 20:43:42 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-03-13 19:56:31 +00:00
|
|
|
#include "globals.hxx"
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-03-29 15:19:13 +00:00
|
|
|
#if defined(HAVE_QT) && !defined(FG_TESTLIB)
|
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 <Navaids/NavDataCache.hxx>
|
|
|
|
#include <Time/TimeManager.hxx>
|
|
|
|
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
|
|
|
#include <simgear/misc/sg_dir.hxx>
|
|
|
|
#include <simgear/timing/timestamp.hxx>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2017-03-27 14:37:54 +00:00
|
|
|
static SGPath tests_fgdata;
|
|
|
|
|
2017-03-21 20:43:42 +00:00
|
|
|
namespace fgtest
|
|
|
|
{
|
|
|
|
|
|
|
|
bool looksLikeFGData(const SGPath& path)
|
|
|
|
{
|
|
|
|
return (path / "defaults.xml").exists();
|
|
|
|
}
|
|
|
|
|
2017-03-27 14:37:54 +00:00
|
|
|
|
|
|
|
SGPath fgdataPath()
|
|
|
|
{
|
|
|
|
return tests_fgdata;
|
|
|
|
}
|
|
|
|
|
2017-03-21 20:43:42 +00:00
|
|
|
void initTestGlobals(const std::string& testName)
|
|
|
|
{
|
|
|
|
globals = new FGGlobals;
|
|
|
|
|
|
|
|
bool foundRoot = false;
|
|
|
|
if (std::getenv("FG_ROOT")) {
|
|
|
|
SGPath fg_root = SGPath::fromEnv("FG_ROOT");
|
|
|
|
if (looksLikeFGData(fg_root)) {
|
|
|
|
globals->set_fg_root(fg_root);
|
|
|
|
foundRoot = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundRoot) {
|
|
|
|
SGPath pkgLibDir = SGPath::fromUtf8(PKGLIBDIR);
|
|
|
|
if (looksLikeFGData(pkgLibDir)) {
|
|
|
|
globals->set_fg_root(pkgLibDir);
|
|
|
|
foundRoot = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundRoot) {
|
|
|
|
SGPath dataDir = SGPath::fromUtf8(FGSRCDIR) / ".." / "fgdata";
|
|
|
|
if (looksLikeFGData(dataDir)) {
|
|
|
|
globals->set_fg_root(dataDir);
|
|
|
|
foundRoot = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundRoot) {
|
|
|
|
std::cerr << "FGData not found" << std::endl;
|
|
|
|
}
|
|
|
|
|
2017-03-27 14:37:54 +00:00
|
|
|
tests_fgdata = globals->get_fg_root();
|
2017-03-21 20:43:42 +00:00
|
|
|
|
|
|
|
// current dir
|
2017-03-27 14:37:54 +00:00
|
|
|
SGPath homePath = SGPath::fromUtf8(FGBUILDDIR) / "test_home";
|
2017-03-21 20:43:42 +00:00
|
|
|
if (!homePath.exists()) {
|
|
|
|
(homePath / "dummyFile").create_dir(0755);
|
|
|
|
}
|
|
|
|
|
|
|
|
globals->set_fg_home(homePath);
|
|
|
|
|
2017-03-27 14:37:54 +00:00
|
|
|
fgSetDefaults();
|
|
|
|
|
2017-03-21 20:43:42 +00:00
|
|
|
flightgear::NavDataCache* cache = flightgear::NavDataCache::createInstance();
|
|
|
|
if (cache->isRebuildRequired()) {
|
|
|
|
std::cerr << "Navcache rebuild for testing" << std::flush;
|
|
|
|
|
|
|
|
while (cache->rebuild() != flightgear::NavDataCache::REBUILD_DONE) {
|
|
|
|
SGTimeStamp::sleepForMSec(1000);
|
|
|
|
std::cerr << "." << std::flush;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-15 13:04:33 +00:00
|
|
|
std::unique_ptr<TimeManager> t;
|
|
|
|
t.reset(new TimeManager);
|
2017-03-21 20:43:42 +00:00
|
|
|
t->init(); // establish mag-var data
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03-29 15:19:13 +00:00
|
|
|
#if defined(HAVE_QT) && !defined(FG_TESTLIB)
|
2018-03-28 22:39:38 +00:00
|
|
|
flightgear::shutdownQtApp();
|
|
|
|
#endif
|
|
|
|
|
2017-03-21 20:43:42 +00:00
|
|
|
delete globals;
|
|
|
|
}
|
|
|
|
} // of namespace fgtest
|