From c92c41a50fbdf222492988995aea9d282d02e145 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 8 Mar 2021 16:44:42 +0000 Subject: [PATCH] Switch test_suite build to use an OBJECT library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove use of BUILDING_TESTSUITE from headers. Where possible, move test APIs to their own file in the test_suite dir (testApis.cxx). For some others, add them to a special list of ‘sources which depend on the build mode’. This will hopefully go away with some further refactoring. --- CMakeModules/FlightGearComponent.cmake | 7 +++++++ src/Airports/airport.cxx | 11 ----------- src/Airports/airport.hxx | 6 ++---- src/Main/CMakeLists.txt | 14 ++++++-------- src/Main/positioninit.hxx | 3 --- src/Scripting/CMakeLists.txt | 6 ++++-- src/Scripting/NasalSys.hxx | 4 ---- src/Time/TimeManager.hxx | 3 +-- test_suite/CMakeLists.txt | 13 +++++++------ test_suite/FGTestApi/CMakeLists.txt | 1 + test_suite/FGTestApi/testApis.cxx | 16 ++++++++++++++++ 11 files changed, 44 insertions(+), 40 deletions(-) create mode 100644 test_suite/FGTestApi/testApis.cxx diff --git a/CMakeModules/FlightGearComponent.cmake b/CMakeModules/FlightGearComponent.cmake index cfb25ef66..dcb94bff8 100644 --- a/CMakeModules/FlightGearComponent.cmake +++ b/CMakeModules/FlightGearComponent.cmake @@ -23,6 +23,13 @@ macro(flightgear_component name sources) target_sources(fgfsObjects PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/${h}) endforeach() + # third argument is TEST_SOURCES + foreach(t ${ARGV3}) + set_property(GLOBAL + APPEND PROPERTY FG_TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/${t}") + set(fc "${fh}#${CMAKE_CURRENT_SOURCE_DIR}/${t}") + endforeach() + set_property(GLOBAL APPEND PROPERTY FG_GROUPS_C "${fc}@") set_property(GLOBAL APPEND PROPERTY FG_GROUPS_H "${fh}@") diff --git a/src/Airports/airport.cxx b/src/Airports/airport.cxx index c6d3ec920..742039f39 100644 --- a/src/Airports/airport.cxx +++ b/src/Airports/airport.cxx @@ -989,17 +989,6 @@ void FGAirport::sortBySize(FGPositionedList& airportList) } } -#if defined(BUILDING_TESTSUITE) - -void FGAirport::testSuiteInjectGroundnetXML(const SGPath& path) -{ - _groundNetwork.reset(new FGGroundNetwork(const_cast(this))); - XMLLoader::loadFromPath(_groundNetwork.get(), path); - _groundNetwork->init(); -} - -#endif - FGAirportDynamicsRef FGAirport::getDynamics() const { return flightgear::AirportDynamicsManager::find(const_cast(this)); diff --git a/src/Airports/airport.hxx b/src/Airports/airport.hxx index c36e8ad5e..a8c45fd93 100644 --- a/src/Airports/airport.hxx +++ b/src/Airports/airport.hxx @@ -317,11 +317,9 @@ class FGAirport : public FGPositioned static void clearAirportsCache(); - -#if defined(BUILDING_TESTSUITE) - // helper to allow testing without needing a full Airports heirarchy + // helper to allow testing without needing a full Airports hierarchy + // only for use by the test-suite, not available outside of it. void testSuiteInjectGroundnetXML(const SGPath& path); -#endif private: static flightgear::AirportCache airportCache; diff --git a/src/Main/CMakeLists.txt b/src/Main/CMakeLists.txt index 047da1e3f..308a19830 100644 --- a/src/Main/CMakeLists.txt +++ b/src/Main/CMakeLists.txt @@ -29,7 +29,6 @@ set(SOURCES subsystemFactory.cxx util.cxx XLIFFParser.cxx - sentryIntegration.cxx ErrorReporter.cxx ${MS_RESOURCE_FILE} ) @@ -51,13 +50,13 @@ set(HEADERS subsystemFactory.hxx util.hxx XLIFFParser.hxx - sentryIntegration.hxx ErrorReporter.hxx + sentryIntegration.hxx ) -flightgear_component(Main "${SOURCES}" "${HEADERS}") +flightgear_component(Main "${SOURCES}" "${HEADERS}" sentryIntegration.cxx) -# The main() function. +# the main() function set(MAIN_SOURCE bootstrap.cxx ) @@ -68,12 +67,10 @@ setup_fgfs_embedded_resources() # Sort the sources and headers for MSVC. setup_msvc_grouping() +# souerces which are different for fgfs vs the test-suite +get_property(TEST_SOURCES GLOBAL PROPERTY FG_TEST_SOURCES) -# # All sources and headers to be built into fgfs. -# get_property(FG_SOURCES GLOBAL PROPERTY FG_SOURCES) -# get_property(FG_HEADERS GLOBAL PROPERTY FG_HEADERS) - # important we pass WIN32 here so the console is optional. Other # platforms ignore this option. If a console is needed we allocate # it manually via AllocConsole() @@ -82,6 +79,7 @@ add_executable(fgfs WIN32 MACOSX_BUNDLE ${MAIN_SOURCE} + ${TEST_SOURCES} $ ) diff --git a/src/Main/positioninit.hxx b/src/Main/positioninit.hxx index 488592cba..7e7b0f20b 100644 --- a/src/Main/positioninit.hxx +++ b/src/Main/positioninit.hxx @@ -31,12 +31,9 @@ bool initPosition(); // Listen to /sim/tower/airport-id and set tower view position accordingly void initTowerLocationListener(); -#if defined(BUILDING_TESTSUITE) // allow this to be manually invoked for position init testing void finalizePosition(); -#endif - } // of namespace flightgear #endif // of FG_POSITION_INIT_HXX diff --git a/src/Scripting/CMakeLists.txt b/src/Scripting/CMakeLists.txt index 6a5bb2121..1c955acf0 100644 --- a/src/Scripting/CMakeLists.txt +++ b/src/Scripting/CMakeLists.txt @@ -1,7 +1,6 @@ include(FlightGearComponent) set(SOURCES - NasalSys.cxx nasal-props.cxx NasalAddons.cxx NasalAircraft.cxx @@ -47,5 +46,8 @@ else() endif() endif() -flightgear_component(Scripting "${SOURCES}" "${HEADERS}") +# NasalSys.cxx is passed as TEST_SOURCES since we need to compile it +# seperately whrn building the test_suite + +flightgear_component(Scripting "${SOURCES}" "${HEADERS}" NasalSys.cxx) diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index f59e1f33c..069c73bc9 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -153,11 +153,7 @@ public: simgear::BufferedLogCallback* log() const { return _log.get(); } -#if defined(BUILDING_TESTSUITE) - /// test-suite only API: retrieve all Nasal runtime errors which - /// occurred since we last called this string_list getAndClearErrorList(); -#endif private: void initLogLevelConstants(); diff --git a/src/Time/TimeManager.hxx b/src/Time/TimeManager.hxx index 9e749fe9f..766009fb1 100644 --- a/src/Time/TimeManager.hxx +++ b/src/Time/TimeManager.hxx @@ -58,9 +58,8 @@ public: double getSimSpeedUpFactor() const; private: // test class is a friend so we can fake elapsed system time -#if defined(BUILDING_TESTSUITE) friend class TimeManagerTests; -#endif + /** * Ensure a consistent update-rate using a combination of * sleep()-ing and busy-waiting. diff --git a/test_suite/CMakeLists.txt b/test_suite/CMakeLists.txt index 37783e483..3701b5fe5 100644 --- a/test_suite/CMakeLists.txt +++ b/test_suite/CMakeLists.txt @@ -111,18 +111,19 @@ setup_fgfs_embedded_resources() # Sort the sources and headers for MSVC. setup_msvc_grouping() +# most object files come from fgfsObjects target: this property +# contains all the sources which need to be compiled seperately +# for the test-suite, becuase they depend on BUILDING_TESTSUTIE define +# we setup below via target_compile_definitions - -# All sources and headers to be built into the test suite. -get_property(FG_SOURCES GLOBAL PROPERTY FG_SOURCES) -get_property(FG_HEADERS GLOBAL PROPERTY FG_HEADERS) +get_property(TEST_SOURCES GLOBAL PROPERTY FG_TEST_SOURCES) # Set up the separate executable for running the test suite. add_executable(fgfs_test_suite - ${FG_SOURCES} - ${FG_HEADERS} + ${TEST_SOURCES} ${TESTSUITE_SOURCES} ${TESTSUITE_HEADERS} + $ ) add_dependencies(fgfs_test_suite buildId) diff --git a/test_suite/FGTestApi/CMakeLists.txt b/test_suite/FGTestApi/CMakeLists.txt index 83074ce66..1205c0629 100644 --- a/test_suite/FGTestApi/CMakeLists.txt +++ b/test_suite/FGTestApi/CMakeLists.txt @@ -7,6 +7,7 @@ set(TESTSUITE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/TestPilot.cxx ${CMAKE_CURRENT_SOURCE_DIR}/NasalUnitTesting_TestSuite.cxx ${CMAKE_CURRENT_SOURCE_DIR}/TestDataLogger.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/testApis.cxx PARENT_SCOPE ) diff --git a/test_suite/FGTestApi/testApis.cxx b/test_suite/FGTestApi/testApis.cxx new file mode 100644 index 000000000..44cec3e0e --- /dev/null +++ b/test_suite/FGTestApi/testApis.cxx @@ -0,0 +1,16 @@ + +#include "config.h" + +// implement various test-only methods on classes + +#include +#include +#include + +void FGAirport::testSuiteInjectGroundnetXML(const SGPath& path) +{ + _groundNetwork.reset(new FGGroundNetwork(const_cast(this))); + XMLLoader::loadFromPath(_groundNetwork.get(), path); + _groundNetwork->init(); +} +