1
0
Fork 0

TestSuite: Spun out the NavDataCache initialisation code.

Not all tests will require the NavDataCache, so it is no longer set up with the
dummy globals data structure.
This commit is contained in:
Edward d'Auvergne 2018-06-10 15:43:20 +02:00
parent b0c5a5481d
commit 99a50508a7
9 changed files with 81 additions and 65 deletions

View file

@ -1,6 +1,7 @@
set(TESTSUITE_SOURCES
${TESTSUITE_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/globals.cxx
${CMAKE_CURRENT_SOURCE_DIR}/NavDataCache.cxx
${CMAKE_CURRENT_SOURCE_DIR}/PrivateAccessorFDM.cxx
${CMAKE_CURRENT_SOURCE_DIR}/scene_graph.cxx
PARENT_SCOPE
@ -10,6 +11,7 @@ set(TESTSUITE_SOURCES
set(TESTSUITE_HEADERS
${TESTSUITE_HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/globals.hxx
${CMAKE_CURRENT_SOURCE_DIR}/NavDataCache.hxx
${CMAKE_CURRENT_SOURCE_DIR}/PrivateAccessorFDM.hxx
${CMAKE_CURRENT_SOURCE_DIR}/scene_graph.hxx
PARENT_SCOPE

View file

@ -0,0 +1,25 @@
#include "NavDataCache.hxx"
#include <Navaids/NavDataCache.hxx>
namespace FGTestApi {
namespace setUp {
void initNavDataCache()
{
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;
}
}
}
} // End of namespace setUp.
} // End of namespace FGTestApi.

View file

@ -0,0 +1,15 @@
#ifndef FG_NAV_DATA_CACHE_TEST_HELPERS_HXX
#define FG_NAV_DATA_CACHE_TEST_HELPERS_HXX
namespace FGTestApi {
namespace setUp {
void initNavDataCache();
} // End of namespace setUp.
} // End of namespace FGTestApi.
#endif // of FG_NAV_DATA_CACHE_TEST_HELPERS_HXX

View file

@ -1,4 +1,3 @@
#include "config.h"
#include "test_suite/dataStore.hxx"
@ -12,28 +11,17 @@
#include <Main/globals.hxx>
#include <Main/options.hxx>
#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>
static SGPath tests_fgdata;
namespace FGTestApi {
namespace setUp {
SGPath fgdataPath()
{
return tests_fgdata;
}
void initTestGlobals(const std::string& testName)
{
void initTestGlobals(const std::string& testName)
{
globals = new FGGlobals;
DataStore &data = DataStore::get();
@ -41,40 +29,29 @@ namespace setUp {
data.findFGRoot("");
}
globals->set_fg_root(data.getFGRoot());
tests_fgdata = data.getFGRoot();
// current dir
SGPath homePath = SGPath::fromUtf8(FGBUILDDIR) / "test_home";
if (!homePath.exists()) {
(homePath / "dummyFile").create_dir(0755);
}
// current dir
SGPath homePath = SGPath::fromUtf8(FGBUILDDIR) / "test_home";
if (!homePath.exists()) {
(homePath / "dummyFile").create_dir(0755);
}
globals->set_fg_home(homePath);
globals->set_fg_home(homePath);
fgSetDefaults();
fgSetDefaults();
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;
}
}
std::unique_ptr<TimeManager> t;
t.reset(new TimeManager);
t->init(); // establish mag-var data
}
std::unique_ptr<TimeManager> t;
t.reset(new TimeManager);
t->init(); // establish mag-var data
}
} // End of namespace setUp.
namespace tearDown {
void shutdownTestGlobals()
{
void shutdownTestGlobals()
{
// The QApplication instance must be destroyed before exit() begins, see
// <https://bugreports.qt.io/browse/QTBUG-48709> (otherwise, segfault).
#if defined(HAVE_QT) && !defined(FG_TESTLIB)
@ -82,7 +59,7 @@ namespace tearDown {
#endif
delete globals;
}
}
} // End of namespace tearDown.

View file

@ -1,8 +1,7 @@
#ifndef FG_TEST_HELPERS_HXX
#define FG_TEST_HELPERS_HXX
#ifndef FG_TEST_GLOBALS_HELPERS_HXX
#define FG_TEST_GLOBALS_HELPERS_HXX
#include <string>
#include <simgear/misc/sg_path.hxx>
namespace FGTestApi {
@ -10,8 +9,6 @@ namespace setUp {
void initTestGlobals(const std::string& testName);
SGPath fgdataPath();
} // End of namespace setUp.
@ -23,4 +20,4 @@ void shutdownTestGlobals();
} // End of namespace FGTestApi.
#endif // of FG_TEST_HELPERS_HXX
#endif // of FG_TEST_GLOBALS_HELPERS_HXX

View file

@ -19,6 +19,7 @@
#include "test_posinit.hxx"
#include "test_suite/FGTestApi/globals.hxx"
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include <simgear/props/props_io.hxx>
@ -31,13 +32,23 @@
using namespace flightgear;
void PosInitTests::testDefaultStartup()
void PosInitTests::setUp()
{
FGTestApi::setUp::initTestGlobals("posinit");
FGTestApi::setUp::initNavDataCache();
Options::reset();
fgLoadProps("defaults.xml", globals->get_props());
}
void PosInitTests::tearDown()
{
FGTestApi::tearDown::shutdownTestGlobals();
}
void PosInitTests::testDefaultStartup()
{
{
Options* opts = Options::sharedInstance();
opts->setShouldLoadDefaultConfig(false);
@ -53,7 +64,7 @@ void PosInitTests::testDefaultStartup()
// this unfortunately means manually parsing that file, oh well
{
SGPath presets = FGTestApi::setUp::fgdataPath() / "location-presets.xml";
SGPath presets = globals->get_fg_root() / "location-presets.xml";
CPPUNIT_ASSERT(presets.exists());
SGPropertyNode_ptr props(new SGPropertyNode);
readProperties(presets, props);
@ -68,16 +79,10 @@ void PosInitTests::testDefaultStartup()
double dist = SGGeodesy::distanceM(pos, defaultAirport->geod());
CPPUNIT_ASSERT(dist < 10000);
}
FGTestApi::tearDown::shutdownTestGlobals();
}
void PosInitTests::testAirportOnlyStartup()
{
FGTestApi::setUp::initTestGlobals("posinit");
Options::reset();
fgLoadProps("defaults.xml", globals->get_props());
{
Options* opts = Options::sharedInstance();
opts->setShouldLoadDefaultConfig(false);
@ -94,17 +99,10 @@ void PosInitTests::testAirportOnlyStartup()
double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
FGAirport::getByIdent("EDDF")->geod());
CPPUNIT_ASSERT(dist < 10000);
FGTestApi::tearDown::shutdownTestGlobals();
}
void PosInitTests::testAirportAndMetarStartup()
{
FGTestApi::setUp::initTestGlobals("posinit");
Options::reset();
fgLoadProps("defaults.xml", globals->get_props());
{
Options* opts = Options::sharedInstance();
opts->setShouldLoadDefaultConfig(false);
@ -121,6 +119,4 @@ void PosInitTests::testAirportAndMetarStartup()
CPPUNIT_ASSERT(dist < 10000);
///sim/atc/runway
CPPUNIT_ASSERT(globals->get_props()->getStringValue("sim/atc/runway") == std::string("26"));
FGTestApi::tearDown::shutdownTestGlobals();
}

View file

@ -38,10 +38,10 @@ class PosInitTests : public CppUnit::TestFixture
public:
// Set up function for each test.
void setUp() {}
void setUp();
// Clean up after each test.
void tearDown() {}
void tearDown();
// The tests.
void testAirportAndMetarStartup();

View file

@ -1,6 +1,7 @@
#include "test_flightplan.hxx"
#include "test_suite/FGTestApi/globals.hxx"
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include <simgear/misc/strutils.hxx>
@ -20,6 +21,7 @@ using namespace flightgear;
void FlightplanTests::setUp()
{
FGTestApi::setUp::initTestGlobals("flightplan");
FGTestApi::setUp::initNavDataCache();
}

View file

@ -1,6 +1,7 @@
#include "test_navaids2.hxx"
#include "test_suite/FGTestApi/globals.hxx"
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include <Navaids/NavDataCache.hxx>
#include <Navaids/navrecord.hxx>
@ -11,6 +12,7 @@
void NavaidsTests::setUp()
{
FGTestApi::setUp::initTestGlobals("navaids2");
FGTestApi::setUp::initNavDataCache();
}