TestSuite: Addition of a test data store singleton.
This is for currently for storing the path to FGData for use in any tests requiring it.
This commit is contained in:
parent
667cd86656
commit
9583e2d7ad
6 changed files with 187 additions and 43 deletions
|
@ -21,6 +21,7 @@ add_subdirectory(helpers)
|
|||
set(TESTSUITE_SOURCES
|
||||
${TESTSUITE_SOURCES}
|
||||
bootstrap.cxx
|
||||
dataStore.cxx
|
||||
fgCompilerOutputter.cxx
|
||||
fgTestListener.cxx
|
||||
fgTestRunner.cxx
|
||||
|
@ -30,6 +31,7 @@ set(TESTSUITE_SOURCES
|
|||
)
|
||||
set(TESTSUITE_HEADERS
|
||||
${TESTSUITE_HEADERS}
|
||||
dataStore.hxx
|
||||
fgCompilerOutputter.hxx
|
||||
fgTestListener.hxx
|
||||
fgTestRunner.hxx
|
||||
|
|
103
test_suite/dataStore.cxx
Normal file
103
test_suite/dataStore.cxx
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (C) 2018 James Turner
|
||||
* Copyright (C) 2018 Edward d'Auvergne
|
||||
*
|
||||
* This file is part of the program FlightGear.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "dataStore.hxx"
|
||||
|
||||
|
||||
// Sanity check.
|
||||
bool looksLikeFGData(const SGPath& path)
|
||||
{
|
||||
return (path / "defaults.xml").exists();
|
||||
}
|
||||
|
||||
|
||||
// Set up the path to FGData.
|
||||
int DataStore::findFGRoot(const std::string& fgRootCmdLineOpt, bool debug)
|
||||
{
|
||||
SGPath fgRoot;
|
||||
|
||||
// Command line supplied path.
|
||||
if (!fgRootCmdLineOpt.empty()) {
|
||||
fgRoot = SGPath::fromUtf8(fgRootCmdLineOpt);
|
||||
if (looksLikeFGData(fgRoot)) {
|
||||
if (debug)
|
||||
std::cerr << "FGdata from the command line: " << fgRoot << std::endl;
|
||||
_fgRootPath = fgRoot;
|
||||
return 0;
|
||||
|
||||
// Fail if an invalid path is supplied.
|
||||
} else {
|
||||
std::cerr << "The supplied path \"" << fgRootCmdLineOpt << "\" is not a valid FGData path." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// The FG_DATA_DIR CMake option.
|
||||
fgRoot = SGPath::fromUtf8(PKGLIBDIR);
|
||||
if (looksLikeFGData(fgRoot)) {
|
||||
if (debug)
|
||||
std::cerr << "FGdata found via $PKGLIBDIR: " << fgRoot << std::endl;
|
||||
_fgRootPath = fgRoot;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The FG_ROOT environmental variable.
|
||||
if (std::getenv("FG_ROOT")) {
|
||||
fgRoot = SGPath::fromEnv("FG_ROOT");
|
||||
if (looksLikeFGData(fgRoot)) {
|
||||
if (debug)
|
||||
std::cerr << "FGdata found via $FG_ROOT: " << fgRoot << std::endl;
|
||||
_fgRootPath = fgRoot;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Try in ../fgdata.
|
||||
fgRoot = SGPath::fromUtf8(FGSRCDIR) / ".." / "fgdata";
|
||||
if (looksLikeFGData(fgRoot)) {
|
||||
if (debug)
|
||||
std::cerr << "FGdata found at \"$FGSRCDIR/../fgdata\": " << fgRoot << std::endl;
|
||||
_fgRootPath = fgRoot;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Try in ../data.
|
||||
fgRoot = SGPath::fromUtf8(FGSRCDIR) / ".." / "data";
|
||||
if (looksLikeFGData(fgRoot)) {
|
||||
if (debug)
|
||||
std::cerr << "FGdata found at \"$FGSRCDIR/../data\": " << std::endl;
|
||||
_fgRootPath = fgRoot;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// No FGData.
|
||||
std::cerr << "FGData not found." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get the path to FGData.
|
||||
SGPath DataStore::getFGRoot()
|
||||
{
|
||||
return _fgRootPath;
|
||||
}
|
53
test_suite/dataStore.hxx
Normal file
53
test_suite/dataStore.hxx
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (C) 2018 Edward d'Auvergne
|
||||
*
|
||||
* This file is part of the program FlightGear.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _FG_TEST_SUITE_DATA_STORE_HXX
|
||||
#define _FG_TEST_SUITE_DATA_STORE_HXX
|
||||
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
|
||||
|
||||
// The data store singleton.
|
||||
class DataStore
|
||||
{
|
||||
public:
|
||||
// Return the singleton, instantiating it if required.
|
||||
static DataStore& get()
|
||||
{
|
||||
static DataStore instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
// Function deletion to allow the class to be a singleton.
|
||||
DataStore(DataStore const&) = delete;
|
||||
void operator=(DataStore const&) = delete;
|
||||
|
||||
// FGData path functions.
|
||||
int findFGRoot(const std::string& fgRootCmdLineOpt, bool debug = false);
|
||||
SGPath getFGRoot();
|
||||
|
||||
private:
|
||||
DataStore() = default;
|
||||
|
||||
// The path to FGData.
|
||||
SGPath _fgRootPath;
|
||||
};
|
||||
|
||||
|
||||
#endif // _FG_TEST_SUITE_DATA_STORE_HXX
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_suite/dataStore.hxx"
|
||||
|
||||
#include "globals.hxx"
|
||||
|
||||
#if defined(HAVE_QT) && !defined(FG_TESTLIB)
|
||||
|
@ -24,12 +26,6 @@ static SGPath tests_fgdata;
|
|||
namespace fgtest
|
||||
{
|
||||
|
||||
bool looksLikeFGData(const SGPath& path)
|
||||
{
|
||||
return (path / "defaults.xml").exists();
|
||||
}
|
||||
|
||||
|
||||
SGPath fgdataPath()
|
||||
{
|
||||
return tests_fgdata;
|
||||
|
@ -39,36 +35,9 @@ namespace fgtest
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
||||
tests_fgdata = globals->get_fg_root();
|
||||
DataStore &data = DataStore::get();
|
||||
globals->set_fg_root(data.getFGRoot());
|
||||
tests_fgdata = data.getFGRoot();
|
||||
|
||||
// current dir
|
||||
SGPath homePath = SGPath::fromUtf8(FGBUILDDIR) / "test_home";
|
||||
|
@ -85,8 +54,8 @@ namespace fgtest
|
|||
std::cerr << "Navcache rebuild for testing" << std::flush;
|
||||
|
||||
while (cache->rebuild() != flightgear::NavDataCache::REBUILD_DONE) {
|
||||
SGTimeStamp::sleepForMSec(1000);
|
||||
std::cerr << "." << std::flush;
|
||||
SGTimeStamp::sleepForMSec(1000);
|
||||
std::cerr << "." << std::flush;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#include "dataStore.hxx"
|
||||
#include "fgTestRunner.hxx"
|
||||
#include "formatting.hxx"
|
||||
#include "logging.hxx"
|
||||
|
@ -80,11 +81,12 @@ void summary(CppUnit::OStream &stream, int system_result, int unit_result, int g
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
// Declarations.
|
||||
int status_gui=-1, status_simgear=-1, status_system=-1, status_unit=-1;
|
||||
bool run_system=false, run_unit=false, run_gui=false, run_simgear=false;
|
||||
bool verbose=false, ctest_output=false, debug=false, help=false;
|
||||
char *subset_system=NULL, *subset_unit=NULL, *subset_gui=NULL, *subset_simgear=NULL;
|
||||
char firstchar;
|
||||
int status_gui=-1, status_simgear=-1, status_system=-1, status_unit=-1;
|
||||
bool run_system=false, run_unit=false, run_gui=false, run_simgear=false;
|
||||
bool verbose=false, ctest_output=false, debug=false, help=false;
|
||||
char *subset_system=NULL, *subset_unit=NULL, *subset_gui=NULL, *subset_simgear=NULL;
|
||||
char firstchar;
|
||||
std::string fgRoot;
|
||||
|
||||
// Argument parsing.
|
||||
for (int i = 1; i < argc; i++) {
|
||||
|
@ -131,6 +133,11 @@ int main(int argc, char **argv)
|
|||
// Help.
|
||||
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
|
||||
help = true;
|
||||
|
||||
// FGData path.
|
||||
} else if (strcmp(argv[i], "--fg-root") == 0) {
|
||||
if (firstchar != '-')
|
||||
fgRoot = argv[i+1];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,6 +166,9 @@ int main(int argc, char **argv)
|
|||
std::cout << " tests." << std::endl;
|
||||
std::cout << " -c, --ctest simplified output suitable for running via CTest." << std::endl;
|
||||
std::cout << " -d, --debug disable IO capture for debugging (super verbose output)." << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << " FG options:" << std::endl;
|
||||
std::cout << " --fg-root the path to FGData" << std::endl;
|
||||
std::cout.flush();
|
||||
return 0;
|
||||
}
|
||||
|
@ -171,6 +181,12 @@ int main(int argc, char **argv)
|
|||
run_simgear = true;
|
||||
}
|
||||
|
||||
// Set up the data store singleton and FGData path.
|
||||
DataStore& data = DataStore::get();
|
||||
if (data.findFGRoot(fgRoot, debug) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Set up logging.
|
||||
sglog().setDeveloperMode(true);
|
||||
if (debug)
|
||||
|
|
|
@ -89,6 +89,7 @@ get_property(fgtestlib_sources DIRECTORY PROPERTY fgtestlib_sources)
|
|||
|
||||
add_library(fgtestlib SHARED ${fgtestlib_sources}
|
||||
"${CMAKE_SOURCE_DIR}/test_suite/helpers/globals.cxx"
|
||||
"${CMAKE_SOURCE_DIR}/test_suite/dataStore.cxx"
|
||||
testStubs.cxx
|
||||
fake_sgSky.cxx
|
||||
fake_sgPrecipitation.cxx
|
||||
|
|
Loading…
Reference in a new issue