1
0
Fork 0

TestSuite: Implementation of FGTestApi.

The test_suite/helpers directory has been renamed to test_suite/FGTestApi/ and
all the fgtest namespaces renamed to FGTestApi.  The helper functions are now
also placed into either a setUp or tearDown namespace depending on their
function.  And a new FGTestApi::PrivateAccessor::FDM namespace has been created
for holding friend classes used to access private or protected variables or
functions from solely within the test suite.
This commit is contained in:
Edward d'Auvergne 2018-07-16 15:59:21 +02:00
parent 68141f3675
commit 88179ec9c1
14 changed files with 93 additions and 50 deletions

View file

@ -14,8 +14,8 @@ foreach(test_category
add_subdirectory(${test_category})
endforeach(test_category)
# Add the helpers.
add_subdirectory(helpers)
# Add the testing API.
add_subdirectory(FGTestApi)
# Add all test suite sources and headers.
set(TESTSUITE_SOURCES

View file

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

View file

@ -0,0 +1,2 @@
#include "PrivateAccessorFDM.hxx"

View file

@ -0,0 +1,17 @@
#ifndef _FG_PRIVATE_ACCESSOR_FDM_HXX
#define _FG_PRIVATE_ACCESSOR_FDM_HXX
namespace FGTestApi {
namespace PrivateAccessor {
namespace FDM {
class Accessor
{
public:
};
} // End of namespace FDM.
} // End of namespace PrivateAccessor.
} // End of namespace FGTestApi.
#endif // _FG_PRIVATE_ACCESSOR_FDM_HXX

View file

@ -23,8 +23,9 @@
static SGPath tests_fgdata;
namespace fgtest
{
namespace FGTestApi {
namespace setUp {
SGPath fgdataPath()
{
@ -67,6 +68,11 @@ namespace fgtest
t->init(); // establish mag-var data
}
} // End of namespace setUp.
namespace tearDown {
void shutdownTestGlobals()
{
// The QApplication instance must be destroyed before exit() begins, see
@ -77,4 +83,7 @@ namespace fgtest
delete globals;
}
} // of namespace fgtest
} // End of namespace tearDown.
} // End of namespace FGTestApi.

View file

@ -0,0 +1,26 @@
#ifndef FG_TEST_HELPERS_HXX
#define FG_TEST_HELPERS_HXX
#include <string>
#include <simgear/misc/sg_path.hxx>
namespace FGTestApi {
namespace setUp {
void initTestGlobals(const std::string& testName);
SGPath fgdataPath();
} // End of namespace setUp.
namespace tearDown {
void shutdownTestGlobals();
} // End of namespace tearDown.
} // End of namespace FGTestApi.
#endif // of FG_TEST_HELPERS_HXX

View file

@ -26,8 +26,8 @@
#include <Viewer/FGEventHandler.hxx>
namespace fgtest
{
namespace FGTestApi {
namespace setUp {
void initScenery()
{
@ -49,4 +49,5 @@ void initScenery()
globals->get_scenery()->bind();
}
} // of namespace fgtest
} // End of namespace setUp.
} // End of namespace FGTestApi.

View file

@ -20,9 +20,12 @@
#ifndef FG_TEST_SCENE_GRAPH_HXX
#define FG_TEST_SCENE_GRAPH_HXX
namespace fgtest
{
namespace FGTestApi {
namespace setUp {
void initScenery();
}
} // End of namespace setUp.
} // End of namespace FGTestApi.
#endif // FG_TEST_SCENE_GRAPH_HXX

View file

@ -1,17 +0,0 @@
#ifndef FG_TEST_HELPERS_HXX
#define FG_TEST_HELPERS_HXX
#include <string>
#include <simgear/misc/sg_path.hxx>
namespace fgtest
{
void initTestGlobals(const std::string& testName);
void shutdownTestGlobals();
SGPath fgdataPath();
}
#endif // of FG_TEST_HELPERS_HXX

View file

@ -21,7 +21,7 @@
#include "test_AddonManagement.hxx"
#include "config.h"
#include "test_suite/helpers/globals.hxx"
#include "test_suite/FGTestApi/globals.hxx"
#include <sstream>
#include <string>
@ -49,7 +49,7 @@ void AddonManagementTests::testAddonVersionSuffix()
{
using AddonRelType = flightgear::addons::AddonVersionSuffixPrereleaseType;
fgtest::initTestGlobals("AddonVersionSuffix");
FGTestApi::setUp::initTestGlobals("AddonVersionSuffix");
AddonVersionSuffix v1(AddonRelType::beta, 2, true, 5);
AddonVersionSuffix v1Copy(v1);
@ -139,14 +139,14 @@ void AddonManagementTests::testAddonVersionSuffix()
CPPUNIT_ASSERT(AddonVersionSuffix(AddonRelType::none) >=
AddonVersionSuffix(AddonRelType::candidate, 21, false));
fgtest::shutdownTestGlobals();
FGTestApi::tearDown::shutdownTestGlobals();
}
void AddonManagementTests::testAddonVersion()
{
using AddonRelType = flightgear::addons::AddonVersionSuffixPrereleaseType;
fgtest::initTestGlobals("AddonVersion");
FGTestApi::setUp::initTestGlobals("AddonVersion");
AddonVersionSuffix suffix(AddonRelType::beta, 2, true, 5);
AddonVersion v1(2017, 4, 7, suffix);
@ -204,12 +204,12 @@ void AddonManagementTests::testAddonVersion()
"3.12.9", "3.13.0", "4.0.0.dev1", "4.0.0.dev10", "4.0.0a1", "4.0.0",
"2017.4.0", "2017.4.1", "2017.4.10", "2017.5.0", "2018.0.0"});
fgtest::shutdownTestGlobals();
FGTestApi::tearDown::shutdownTestGlobals();
}
void AddonManagementTests::testAddon()
{
fgtest::initTestGlobals("Addon");
FGTestApi::setUp::initTestGlobals("Addon");
std::string addonId = "org.FlightGear.addons.MyGreatAddon";
Addon addon{addonId};
@ -243,5 +243,5 @@ void AddonManagementTests::testAddon()
CPPUNIT_ASSERT(addon.getMaxFGVersionRequired() == "2018.2.5");
CPPUNIT_ASSERT_EQUAL(addon.str(), refText2);
fgtest::shutdownTestGlobals();
FGTestApi::tearDown::shutdownTestGlobals();
}

View file

@ -18,7 +18,7 @@
#include "test_posinit.hxx"
#include "test_suite/helpers/globals.hxx"
#include "test_suite/FGTestApi/globals.hxx"
#include <simgear/props/props_io.hxx>
@ -33,7 +33,7 @@ using namespace flightgear;
void PosInitTests::testDefaultStartup()
{
fgtest::initTestGlobals("posinit");
FGTestApi::setUp::initTestGlobals("posinit");
Options::reset();
fgLoadProps("defaults.xml", globals->get_props());
@ -53,7 +53,7 @@ void PosInitTests::testDefaultStartup()
// this unfortunately means manually parsing that file, oh well
{
SGPath presets = fgtest::fgdataPath() / "location-presets.xml";
SGPath presets = FGTestApi::setUp::fgdataPath() / "location-presets.xml";
CPPUNIT_ASSERT(presets.exists());
SGPropertyNode_ptr props(new SGPropertyNode);
readProperties(presets, props);
@ -68,13 +68,13 @@ void PosInitTests::testDefaultStartup()
double dist = SGGeodesy::distanceM(pos, defaultAirport->geod());
CPPUNIT_ASSERT(dist < 10000);
}
fgtest::shutdownTestGlobals();
FGTestApi::tearDown::shutdownTestGlobals();
}
void PosInitTests::testAirportOnlyStartup()
{
fgtest::initTestGlobals("posinit");
FGTestApi::setUp::initTestGlobals("posinit");
Options::reset();
fgLoadProps("defaults.xml", globals->get_props());
@ -94,13 +94,13 @@ void PosInitTests::testAirportOnlyStartup()
double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
FGAirport::getByIdent("EDDF")->geod());
CPPUNIT_ASSERT(dist < 10000);
fgtest::shutdownTestGlobals();
FGTestApi::tearDown::shutdownTestGlobals();
}
void PosInitTests::testAirportAndMetarStartup()
{
fgtest::initTestGlobals("posinit");
FGTestApi::setUp::initTestGlobals("posinit");
Options::reset();
fgLoadProps("defaults.xml", globals->get_props());
@ -122,5 +122,5 @@ void PosInitTests::testAirportAndMetarStartup()
///sim/atc/runway
CPPUNIT_ASSERT(globals->get_props()->getStringValue("sim/atc/runway") == std::string("26"));
fgtest::shutdownTestGlobals();
FGTestApi::tearDown::shutdownTestGlobals();
}

View file

@ -1,6 +1,6 @@
#include "test_flightplan.hxx"
#include "test_suite/helpers/globals.hxx"
#include "test_suite/FGTestApi/globals.hxx"
#include <simgear/misc/strutils.hxx>
@ -19,14 +19,14 @@ using namespace flightgear;
// Set up function for each test.
void FlightplanTests::setUp()
{
fgtest::initTestGlobals("flightplan");
FGTestApi::setUp::initTestGlobals("flightplan");
}
// Clean up after each test.
void FlightplanTests::tearDown()
{
fgtest::shutdownTestGlobals();
FGTestApi::tearDown::shutdownTestGlobals();
}

View file

@ -1,6 +1,6 @@
#include "test_navaids2.hxx"
#include "test_suite/helpers/globals.hxx"
#include "test_suite/FGTestApi/globals.hxx"
#include <Navaids/NavDataCache.hxx>
#include <Navaids/navrecord.hxx>
@ -10,14 +10,14 @@
// Set up function for each test.
void NavaidsTests::setUp()
{
fgtest::initTestGlobals("navaids2");
FGTestApi::setUp::initTestGlobals("navaids2");
}
// Clean up after each test.
void NavaidsTests::tearDown()
{
fgtest::shutdownTestGlobals();
FGTestApi::tearDown::shutdownTestGlobals();
}

View file

@ -88,7 +88,7 @@ set_property(DIRECTORY APPEND PROPERTY fgtestlib_sources "${CMAKE_SOURCE_DIR}/3r
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/FGTestApi/globals.cxx"
"${CMAKE_SOURCE_DIR}/test_suite/dataStore.cxx"
testStubs.cxx
fake_sgSky.cxx