From 88179ec9c1457b96604eb27b2ecb56ac75a08a0c Mon Sep 17 00:00:00 2001 From: Edward d'Auvergne Date: Mon, 16 Jul 2018 15:59:21 +0200 Subject: [PATCH] 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. --- test_suite/CMakeLists.txt | 4 +-- .../{helpers => FGTestApi}/CMakeLists.txt | 2 ++ test_suite/FGTestApi/PrivateAccessorFDM.cxx | 2 ++ test_suite/FGTestApi/PrivateAccessorFDM.hxx | 17 ++++++++++++ test_suite/{helpers => FGTestApi}/globals.cxx | 15 ++++++++--- test_suite/FGTestApi/globals.hxx | 26 +++++++++++++++++++ .../{helpers => FGTestApi}/scene_graph.cxx | 7 ++--- .../{helpers => FGTestApi}/scene_graph.hxx | 9 ++++--- test_suite/helpers/globals.hxx | 17 ------------ .../Add-ons/test_AddonManagement.cxx | 14 +++++----- test_suite/unit_tests/Main/test_posinit.cxx | 16 ++++++------ .../unit_tests/Navaids/test_flightplan.cxx | 6 ++--- .../unit_tests/Navaids/test_navaids2.cxx | 6 ++--- tests/CMakeLists.txt | 2 +- 14 files changed, 93 insertions(+), 50 deletions(-) rename test_suite/{helpers => FGTestApi}/CMakeLists.txt (74%) create mode 100644 test_suite/FGTestApi/PrivateAccessorFDM.cxx create mode 100644 test_suite/FGTestApi/PrivateAccessorFDM.hxx rename test_suite/{helpers => FGTestApi}/globals.cxx (91%) create mode 100644 test_suite/FGTestApi/globals.hxx rename test_suite/{helpers => FGTestApi}/scene_graph.cxx (94%) rename test_suite/{helpers => FGTestApi}/scene_graph.hxx (89%) delete mode 100644 test_suite/helpers/globals.hxx diff --git a/test_suite/CMakeLists.txt b/test_suite/CMakeLists.txt index 7bfd0fd37..0b0fbd9a3 100644 --- a/test_suite/CMakeLists.txt +++ b/test_suite/CMakeLists.txt @@ -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 diff --git a/test_suite/helpers/CMakeLists.txt b/test_suite/FGTestApi/CMakeLists.txt similarity index 74% rename from test_suite/helpers/CMakeLists.txt rename to test_suite/FGTestApi/CMakeLists.txt index 20d434eae..a68aeb00c 100644 --- a/test_suite/helpers/CMakeLists.txt +++ b/test_suite/FGTestApi/CMakeLists.txt @@ -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 ) diff --git a/test_suite/FGTestApi/PrivateAccessorFDM.cxx b/test_suite/FGTestApi/PrivateAccessorFDM.cxx new file mode 100644 index 000000000..67d92f9ec --- /dev/null +++ b/test_suite/FGTestApi/PrivateAccessorFDM.cxx @@ -0,0 +1,2 @@ +#include "PrivateAccessorFDM.hxx" + diff --git a/test_suite/FGTestApi/PrivateAccessorFDM.hxx b/test_suite/FGTestApi/PrivateAccessorFDM.hxx new file mode 100644 index 000000000..7db30b6b3 --- /dev/null +++ b/test_suite/FGTestApi/PrivateAccessorFDM.hxx @@ -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 diff --git a/test_suite/helpers/globals.cxx b/test_suite/FGTestApi/globals.cxx similarity index 91% rename from test_suite/helpers/globals.cxx rename to test_suite/FGTestApi/globals.cxx index 6e7859f69..d857ed706 100644 --- a/test_suite/helpers/globals.cxx +++ b/test_suite/FGTestApi/globals.cxx @@ -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. diff --git a/test_suite/FGTestApi/globals.hxx b/test_suite/FGTestApi/globals.hxx new file mode 100644 index 000000000..92dfc0603 --- /dev/null +++ b/test_suite/FGTestApi/globals.hxx @@ -0,0 +1,26 @@ +#ifndef FG_TEST_HELPERS_HXX +#define FG_TEST_HELPERS_HXX + +#include +#include + +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 diff --git a/test_suite/helpers/scene_graph.cxx b/test_suite/FGTestApi/scene_graph.cxx similarity index 94% rename from test_suite/helpers/scene_graph.cxx rename to test_suite/FGTestApi/scene_graph.cxx index b7afdf8f9..877f836a1 100644 --- a/test_suite/helpers/scene_graph.cxx +++ b/test_suite/FGTestApi/scene_graph.cxx @@ -26,8 +26,8 @@ #include -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. diff --git a/test_suite/helpers/scene_graph.hxx b/test_suite/FGTestApi/scene_graph.hxx similarity index 89% rename from test_suite/helpers/scene_graph.hxx rename to test_suite/FGTestApi/scene_graph.hxx index d96b31767..7bb363bfa 100644 --- a/test_suite/helpers/scene_graph.hxx +++ b/test_suite/FGTestApi/scene_graph.hxx @@ -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 diff --git a/test_suite/helpers/globals.hxx b/test_suite/helpers/globals.hxx deleted file mode 100644 index 04132218e..000000000 --- a/test_suite/helpers/globals.hxx +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef FG_TEST_HELPERS_HXX -#define FG_TEST_HELPERS_HXX - -#include -#include - -namespace fgtest -{ - - void initTestGlobals(const std::string& testName); - - void shutdownTestGlobals(); - - SGPath fgdataPath(); -} - -#endif // of FG_TEST_HELPERS_HXX diff --git a/test_suite/unit_tests/Add-ons/test_AddonManagement.cxx b/test_suite/unit_tests/Add-ons/test_AddonManagement.cxx index dce921e99..d2b4eaca6 100644 --- a/test_suite/unit_tests/Add-ons/test_AddonManagement.cxx +++ b/test_suite/unit_tests/Add-ons/test_AddonManagement.cxx @@ -21,7 +21,7 @@ #include "test_AddonManagement.hxx" #include "config.h" -#include "test_suite/helpers/globals.hxx" +#include "test_suite/FGTestApi/globals.hxx" #include #include @@ -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(); } diff --git a/test_suite/unit_tests/Main/test_posinit.cxx b/test_suite/unit_tests/Main/test_posinit.cxx index 4561f1118..d653df469 100644 --- a/test_suite/unit_tests/Main/test_posinit.cxx +++ b/test_suite/unit_tests/Main/test_posinit.cxx @@ -18,7 +18,7 @@ #include "test_posinit.hxx" -#include "test_suite/helpers/globals.hxx" +#include "test_suite/FGTestApi/globals.hxx" #include @@ -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(); } diff --git a/test_suite/unit_tests/Navaids/test_flightplan.cxx b/test_suite/unit_tests/Navaids/test_flightplan.cxx index dcb2d2e49..a8f58e8cc 100644 --- a/test_suite/unit_tests/Navaids/test_flightplan.cxx +++ b/test_suite/unit_tests/Navaids/test_flightplan.cxx @@ -1,6 +1,6 @@ #include "test_flightplan.hxx" -#include "test_suite/helpers/globals.hxx" +#include "test_suite/FGTestApi/globals.hxx" #include @@ -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(); } diff --git a/test_suite/unit_tests/Navaids/test_navaids2.cxx b/test_suite/unit_tests/Navaids/test_navaids2.cxx index d1fb46377..20d44b68f 100644 --- a/test_suite/unit_tests/Navaids/test_navaids2.cxx +++ b/test_suite/unit_tests/Navaids/test_navaids2.cxx @@ -1,6 +1,6 @@ #include "test_navaids2.hxx" -#include "test_suite/helpers/globals.hxx" +#include "test_suite/FGTestApi/globals.hxx" #include #include @@ -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(); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4fa36f6f9..9f8ef1395 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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