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-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;
|
|
|
|
|
2018-07-16 13:59:21 +00:00
|
|
|
namespace FGTestApi {
|
|
|
|
|
|
|
|
namespace setUp {
|
2017-03-21 20:43:42 +00:00
|
|
|
|
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;
|
|
|
|
|
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());
|
|
|
|
tests_fgdata = data.getFGRoot();
|
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) {
|
2018-03-28 15:30:59 +00:00
|
|
|
SGTimeStamp::sleepForMSec(1000);
|
|
|
|
std::cerr << "." << std::flush;
|
2017-03-21 20:43:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-07-16 13:59:21 +00:00
|
|
|
} // End of namespace setUp.
|
|
|
|
|
|
|
|
|
|
|
|
namespace tearDown {
|
|
|
|
|
2017-03-21 20:43:42 +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-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;
|
|
|
|
}
|
2018-07-16 13:59:21 +00:00
|
|
|
|
|
|
|
} // End of namespace tearDown.
|
|
|
|
|
|
|
|
} // End of namespace FGTestApi.
|