1
0
Fork 0

Switch test_suite build to use an OBJECT library

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.
This commit is contained in:
James Turner 2021-03-08 16:44:42 +00:00
parent 33e205f123
commit c92c41a50f
11 changed files with 44 additions and 40 deletions

View file

@ -23,6 +23,13 @@ macro(flightgear_component name sources)
target_sources(fgfsObjects PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/${h}) target_sources(fgfsObjects PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/${h})
endforeach() 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_C "${fc}@")
set_property(GLOBAL APPEND PROPERTY FG_GROUPS_H "${fh}@") set_property(GLOBAL APPEND PROPERTY FG_GROUPS_H "${fh}@")

View file

@ -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<FGAirport*>(this)));
XMLLoader::loadFromPath(_groundNetwork.get(), path);
_groundNetwork->init();
}
#endif
FGAirportDynamicsRef FGAirport::getDynamics() const FGAirportDynamicsRef FGAirport::getDynamics() const
{ {
return flightgear::AirportDynamicsManager::find(const_cast<FGAirport*>(this)); return flightgear::AirportDynamicsManager::find(const_cast<FGAirport*>(this));

View file

@ -317,11 +317,9 @@ class FGAirport : public FGPositioned
static void clearAirportsCache(); static void clearAirportsCache();
// helper to allow testing without needing a full Airports hierarchy
#if defined(BUILDING_TESTSUITE) // only for use by the test-suite, not available outside of it.
// helper to allow testing without needing a full Airports heirarchy
void testSuiteInjectGroundnetXML(const SGPath& path); void testSuiteInjectGroundnetXML(const SGPath& path);
#endif
private: private:
static flightgear::AirportCache airportCache; static flightgear::AirportCache airportCache;

View file

@ -29,7 +29,6 @@ set(SOURCES
subsystemFactory.cxx subsystemFactory.cxx
util.cxx util.cxx
XLIFFParser.cxx XLIFFParser.cxx
sentryIntegration.cxx
ErrorReporter.cxx ErrorReporter.cxx
${MS_RESOURCE_FILE} ${MS_RESOURCE_FILE}
) )
@ -51,13 +50,13 @@ set(HEADERS
subsystemFactory.hxx subsystemFactory.hxx
util.hxx util.hxx
XLIFFParser.hxx XLIFFParser.hxx
sentryIntegration.hxx
ErrorReporter.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 set(MAIN_SOURCE
bootstrap.cxx bootstrap.cxx
) )
@ -68,12 +67,10 @@ setup_fgfs_embedded_resources()
# Sort the sources and headers for MSVC. # Sort the sources and headers for MSVC.
setup_msvc_grouping() 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 # important we pass WIN32 here so the console is optional. Other
# platforms ignore this option. If a console is needed we allocate # platforms ignore this option. If a console is needed we allocate
# it manually via AllocConsole() # it manually via AllocConsole()
@ -82,6 +79,7 @@ add_executable(fgfs
WIN32 WIN32
MACOSX_BUNDLE MACOSX_BUNDLE
${MAIN_SOURCE} ${MAIN_SOURCE}
${TEST_SOURCES}
$<TARGET_OBJECTS:fgfsObjects> $<TARGET_OBJECTS:fgfsObjects>
) )

View file

@ -31,12 +31,9 @@ bool initPosition();
// Listen to /sim/tower/airport-id and set tower view position accordingly // Listen to /sim/tower/airport-id and set tower view position accordingly
void initTowerLocationListener(); void initTowerLocationListener();
#if defined(BUILDING_TESTSUITE)
// allow this to be manually invoked for position init testing // allow this to be manually invoked for position init testing
void finalizePosition(); void finalizePosition();
#endif
} // of namespace flightgear } // of namespace flightgear
#endif // of FG_POSITION_INIT_HXX #endif // of FG_POSITION_INIT_HXX

View file

@ -1,7 +1,6 @@
include(FlightGearComponent) include(FlightGearComponent)
set(SOURCES set(SOURCES
NasalSys.cxx
nasal-props.cxx nasal-props.cxx
NasalAddons.cxx NasalAddons.cxx
NasalAircraft.cxx NasalAircraft.cxx
@ -47,5 +46,8 @@ else()
endif() endif()
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)

View file

@ -153,11 +153,7 @@ public:
simgear::BufferedLogCallback* log() const simgear::BufferedLogCallback* log() const
{ return _log.get(); } { 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(); string_list getAndClearErrorList();
#endif
private: private:
void initLogLevelConstants(); void initLogLevelConstants();

View file

@ -58,9 +58,8 @@ public:
double getSimSpeedUpFactor() const; double getSimSpeedUpFactor() const;
private: private:
// test class is a friend so we can fake elapsed system time // test class is a friend so we can fake elapsed system time
#if defined(BUILDING_TESTSUITE)
friend class TimeManagerTests; friend class TimeManagerTests;
#endif
/** /**
* Ensure a consistent update-rate using a combination of * Ensure a consistent update-rate using a combination of
* sleep()-ing and busy-waiting. * sleep()-ing and busy-waiting.

View file

@ -111,18 +111,19 @@ setup_fgfs_embedded_resources()
# Sort the sources and headers for MSVC. # Sort the sources and headers for MSVC.
setup_msvc_grouping() 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
get_property(TEST_SOURCES GLOBAL PROPERTY FG_TEST_SOURCES)
# 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)
# Set up the separate executable for running the test suite. # Set up the separate executable for running the test suite.
add_executable(fgfs_test_suite add_executable(fgfs_test_suite
${FG_SOURCES} ${TEST_SOURCES}
${FG_HEADERS}
${TESTSUITE_SOURCES} ${TESTSUITE_SOURCES}
${TESTSUITE_HEADERS} ${TESTSUITE_HEADERS}
$<TARGET_OBJECTS:fgfsObjects>
) )
add_dependencies(fgfs_test_suite buildId) add_dependencies(fgfs_test_suite buildId)

View file

@ -7,6 +7,7 @@ set(TESTSUITE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/TestPilot.cxx ${CMAKE_CURRENT_SOURCE_DIR}/TestPilot.cxx
${CMAKE_CURRENT_SOURCE_DIR}/NasalUnitTesting_TestSuite.cxx ${CMAKE_CURRENT_SOURCE_DIR}/NasalUnitTesting_TestSuite.cxx
${CMAKE_CURRENT_SOURCE_DIR}/TestDataLogger.cxx ${CMAKE_CURRENT_SOURCE_DIR}/TestDataLogger.cxx
${CMAKE_CURRENT_SOURCE_DIR}/testApis.cxx
PARENT_SCOPE PARENT_SCOPE
) )

View file

@ -0,0 +1,16 @@
#include "config.h"
// implement various test-only methods on classes
#include <Airports/groundnetwork.hxx>
#include <Airports/airport.hxx>
#include <Airports/xmlloader.hxx>
void FGAirport::testSuiteInjectGroundnetXML(const SGPath& path)
{
_groundNetwork.reset(new FGGroundNetwork(const_cast<FGAirport*>(this)));
XMLLoader::loadFromPath(_groundNetwork.get(), path);
_groundNetwork->init();
}