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})
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}@")

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
{
return flightgear::AirportDynamicsManager::find(const_cast<FGAirport*>(this));

View file

@ -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;

View file

@ -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}
$<TARGET_OBJECTS:fgfsObjects>
)

View file

@ -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

View file

@ -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)

View file

@ -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();

View file

@ -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.

View file

@ -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}
$<TARGET_OBJECTS:fgfsObjects>
)
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}/NasalUnitTesting_TestSuite.cxx
${CMAKE_CURRENT_SOURCE_DIR}/TestDataLogger.cxx
${CMAKE_CURRENT_SOURCE_DIR}/testApis.cxx
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();
}