1
0
Fork 0

Unit-test for initPosition.

Only basic, but can be expanded incrementally now
This commit is contained in:
James Turner 2017-03-27 15:37:54 +01:00
parent feb5d599d0
commit 58a7f2c5c2
8 changed files with 113 additions and 70 deletions

View file

@ -34,6 +34,7 @@
#define PKGLIBDIR "@FG_DATA_DIR@" #define PKGLIBDIR "@FG_DATA_DIR@"
#define FGSRCDIR "@PROJECT_SOURCE_DIR@" #define FGSRCDIR "@PROJECT_SOURCE_DIR@"
#define FGBUILDDIR "@PROJECT_BINARY_DIR@"
#define WEB_BROWSER "@WEB_BROWSER@" #define WEB_BROWSER "@WEB_BROWSER@"
// Ensure FG_HAVE_xxx always have a value // Ensure FG_HAVE_xxx always have a value

View file

@ -184,3 +184,7 @@ if(ENABLE_METAR)
install(TARGETS metar RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS metar RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif() endif()
if (ENABLE_TESTS)
flightgear_test(posinit test_posinit.cxx)
endif()

View file

@ -95,7 +95,7 @@ using namespace flightgear;
#define NEW_DEFAULT_MODEL_HZ 120 #define NEW_DEFAULT_MODEL_HZ 120
static flightgear::Options* shared_instance = NULL; static flightgear::Options* shared_instance = nullptr;
static double static double
atof( const string& str ) atof( const string& str )
@ -1979,6 +1979,14 @@ Options* Options::sharedInstance()
return shared_instance; return shared_instance;
} }
void Options::reset()
{
if (shared_instance != nullptr) {
delete shared_instance;
shared_instance = nullptr;
}
}
Options::Options() : Options::Options() :
p(new OptionsPrivate()) p(new OptionsPrivate())
{ {
@ -2034,7 +2042,9 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
} }
if (!p->shouldLoadDefaultConfig) { if (!p->shouldLoadDefaultConfig) {
#if !defined(FG_TESTLIB)
setupRoot(argc, argv); setupRoot(argc, argv);
#endif
return; return;
} }

View file

@ -67,6 +67,13 @@ private:
public: public:
static Options* sharedInstance(); static Options* sharedInstance();
/**
* Delete the entire options object. Use with a degree of care, no code
* should ever be caching the Options pointer but this has not actually been
* checked across the whole code :)
*/
static void reset();
~Options(); ~Options();
/** /**

View file

@ -453,6 +453,8 @@ static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) {
SGGeod geodPos; SGGeod geodPos;
double heading; double heading;
SGVec3d uvw; SGVec3d uvw;
#ifndef FG_TESTLIB
if (FGAIManager::getStartPosition(carrier, posid, geodPos, heading, uvw)) { if (FGAIManager::getStartPosition(carrier, posid, geodPos, heading, uvw)) {
double lon = geodPos.getLongitudeDeg(); double lon = geodPos.getLongitudeDeg();
double lat = geodPos.getLatitudeDeg(); double lat = geodPos.getLatitudeDeg();
@ -482,7 +484,9 @@ static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) {
fgSetBool("/sim/presets/onground", true); fgSetBool("/sim/presets/onground", true);
return true; return true;
} else { } else
#endif
{
SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate aircraft carrier = " SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate aircraft carrier = "
<< carrier ); << carrier );
return false; return false;

View file

@ -6,6 +6,7 @@ set(sources
Main/globals.cxx Main/globals.cxx
Main/locale.cxx Main/locale.cxx
Main/util.cxx Main/util.cxx
Main/positioninit.cxx
Aircraft/controls.cxx Aircraft/controls.cxx
Aircraft/FlightHistory.cxx Aircraft/FlightHistory.cxx
Aircraft/flightrecorder.cxx Aircraft/flightrecorder.cxx
@ -91,7 +92,7 @@ set_target_properties (fgtestlib
) )
if(FG_HAVE_GPERFTOOLS) if(FG_HAVE_GPERFTOOLS)
include_directories(${GooglePerfTools_INCLUDE_DIR}) target_include_directories(fgtestlib PRIVATE ${GooglePerfTools_INCLUDE_DIR})
target_link_libraries(fgtestlib ${GooglePerfTools_LIBRARIES}) target_link_libraries(fgtestlib ${GooglePerfTools_LIBRARIES})
endif() endif()
target_link_libraries(fgtestlib SimGearCore ${PLATFORM_LIBS} ${SQLITE3_LIBRARY}) target_link_libraries(fgtestlib SimGearCore ${PLATFORM_LIBS} ${SQLITE3_LIBRARY})
@ -101,6 +102,7 @@ target_link_libraries(fgtest fgtestlib)
macro(flightgear_test name sources) macro(flightgear_test name sources)
add_executable(${name} ${sources}) add_executable(${name} ${sources})
target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR}/tests)
target_link_libraries(${name} fgtestlib) target_link_libraries(${name} fgtestlib)
add_test(${name} ${EXECUTABLE_OUTPUT_PATH}/${name}) add_test(${name} ${EXECUTABLE_OUTPUT_PATH}/${name})
endmacro() endmacro()

View file

@ -4,6 +4,8 @@
#include "unitTestHelpers.hxx" #include "unitTestHelpers.hxx"
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Main/options.hxx>
#include <Navaids/NavDataCache.hxx> #include <Navaids/NavDataCache.hxx>
#include <Time/TimeManager.hxx> #include <Time/TimeManager.hxx>
@ -13,6 +15,8 @@
#include <iostream> #include <iostream>
static SGPath tests_fgdata;
namespace fgtest namespace fgtest
{ {
@ -21,6 +25,12 @@ namespace fgtest
return (path / "defaults.xml").exists(); return (path / "defaults.xml").exists();
} }
SGPath fgdataPath()
{
return tests_fgdata;
}
void initTestGlobals(const std::string& testName) void initTestGlobals(const std::string& testName)
{ {
sglog().setLogLevels( SG_ALL, SG_WARN ); sglog().setLogLevels( SG_ALL, SG_WARN );
@ -58,15 +68,18 @@ namespace fgtest
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
tests_fgdata = globals->get_fg_root();
// current dir // current dir
SGPath homePath = simgear::Dir::current().path() / "test_home"; SGPath homePath = SGPath::fromUtf8(FGBUILDDIR) / "test_home";
if (!homePath.exists()) { if (!homePath.exists()) {
(homePath / "dummyFile").create_dir(0755); (homePath / "dummyFile").create_dir(0755);
} }
globals->set_fg_home(homePath); globals->set_fg_home(homePath);
fgSetDefaults();
flightgear::NavDataCache* cache = flightgear::NavDataCache::createInstance(); flightgear::NavDataCache* cache = flightgear::NavDataCache::createInstance();
if (cache->isRebuildRequired()) { if (cache->isRebuildRequired()) {
std::cerr << "Navcache rebuild for testing" << std::flush; std::cerr << "Navcache rebuild for testing" << std::flush;

View file

@ -10,6 +10,8 @@ namespace fgtest
void initTestGlobals(const std::string& testName); void initTestGlobals(const std::string& testName);
void shutdownTestGlobals(); void shutdownTestGlobals();
SGPath fgdataPath();
} }
#endif // of FG_TEST_HELPERS_HXX #endif // of FG_TEST_HELPERS_HXX