Commit 6f2860a2 authored by math's avatar math
Browse files

[ADD #61] Now the unit tests cmake integrations are generated automatically...

[ADD #61] Now the unit tests cmake integrations are generated automatically and a warning is thrown when a testsuite is not found. For this new behaviour a new macro has to be used, called: CXXTEST_ADD_TESTS_FROM_LIST. Basically you need only the source file list like DATAHANDLER_SRC and a library list where each test target will link to.
parent 239b44b3
ADD_SUBDIRECTORY( io )
ADD_SUBDIRECTORY( exceptions )
FILE( GLOB DATAHANDLER_SRC "*.cpp" "exceptions/*.cpp" )
ADD_LIBRARY( dataHandler SHARED ${DATAHANDLER_SRC} )
FILE( GLOB DATAHANDLER_SRC "*.cpp" )
FILE( GLOB DATAHANDLER_EXCEPTIONS_SRC "exceptions/*.cpp" )
ADD_LIBRARY( dataHandler SHARED ${DATAHANDLER_SRC} ${DATAHANDLER_EXCEPTIONS_SRC} )
# Unit tests
IF( CXXTEST_FOUND )
CXXTEST_ADD_TEST( unittest_WMetaInfo
WMetaInfo_test.cc
${CMAKE_CURRENT_SOURCE_DIR}/test/WMetaInfo_test.h )
TARGET_LINK_LIBRARIES( unittest_WMetaInfo dataHandler )
CXXTEST_ADD_TEST( unittest_WGrid
WGrid_test.cc
${CMAKE_CURRENT_SOURCE_DIR}/test/WGrid_test.h )
TARGET_LINK_LIBRARIES( unittest_WGrid dataHandler )
CXXTEST_ADD_TEST( unittest_WValueSet
WValueSet_test.cc
${CMAKE_CURRENT_SOURCE_DIR}/test/WValueSet_test.h )
TARGET_LINK_LIBRARIES( unittest_WValueSet dataHandler )
CXXTEST_ADD_TEST( unittest_WDataSet
WDataSet_test.cc
${CMAKE_CURRENT_SOURCE_DIR}/test/WDataSet_test.h )
TARGET_LINK_LIBRARIES( unittest_WDataSet dataHandler )
CXXTEST_ADD_TEST( unittest_WDataSetSingle
WDataSetSingle_test.cc
${CMAKE_CURRENT_SOURCE_DIR}/test/WDataSetSingle_test.h )
TARGET_LINK_LIBRARIES( unittest_WDataSetSingle dataHandler )
CXXTEST_ADD_TEST( unittest_WDataSetTimeDependent
WDataSetTimeDependent_test.cc
${CMAKE_CURRENT_SOURCE_DIR}/test/WDataSetTimeDependent_test.h )
TARGET_LINK_LIBRARIES( unittest_WDataSetTimeDependent dataHandler )
CXXTEST_ADD_TEST( unittest_WDataHandler
WDataHandler_test.cc
${CMAKE_CURRENT_SOURCE_DIR}/test/WDataHandler_test.h )
TARGET_LINK_LIBRARIES( unittest_WDataHandler dataHandler )
CXXTEST_ADD_TESTS_FROM_LIST( "${DATAHANDLER_SRC}"
dataHandler
"WValueSetBase.cpp" # its abstract
)
ENDIF( CXXTEST_FOUND )
......@@ -6,5 +6,7 @@ ADD_LIBRARY( gui SHARED ${GUI_SRC} )
# Unit tests
IF( CXXTEST_FOUND )
CXXTEST_ADD_TEST( unittest_WGUI WGUI_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/test/WGUI_test.h )
CXXTEST_ADD_TESTS_FROM_LIST( "${GUI_SRC}"
"" # no libs for linking required
)
ENDIF( CXXTEST_FOUND )
......@@ -4,6 +4,7 @@ ADD_LIBRARY( utils SHARED ${UTILS_SRC} )
# Unit tests
IF( CXXTEST_FOUND )
CXXTEST_ADD_TEST( unittest_WOptionHandler WOptionHandler_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/test/WOptionHandler_test.h )
TARGET_LINK_LIBRARIES( unittest_WOptionHandler utils guiqt4 ${Boost_LIBRARIES} )
CXXTEST_ADD_TESTS_FROM_LIST( "${UTILS_SRC}"
"utils;guiqt4;${Boost_LIBRARIES}"
)
ENDIF( CXXTEST_FOUND )
......@@ -116,6 +116,58 @@ macro( CXXTEST_ADD_TEST _cxxtest_testname _cxxtest_outfname _cxxtest_testsuite )
endmacro(CXXTEST_ADD_TEST)
#=============================================================
# CXXTEST_ADD_TEST_FROM_LIST (public macro)
#=============================================================
#
# Usage:
# CXXTEST_ADD_TESTS_FROM_LIST( A, B, ... )
#
# 1. A is a list of cpp files where the class name is stripped of
# 2. then out of the class name the test targets and testsuite names are generated
# 3. finally they are linked with all libs present in parameter B
# 4. If there are more arguments (ARGN) then they are exclude from A before 1-3 starts)
#
MACRO( CXXTEST_ADD_TESTS_FROM_LIST _SourceLst _TestLbs )
# transform parameters into variables, since macro parameters aren't variables
SET( _SourceList ${_SourceLst} )
SET( _TestLibs ${_TestLbs} )
# remove unwanted tests
IF( ${ARGC} GREATER 2 )
FOREACH( fname ${ARGN} )
LIST( REMOVE_ITEM _SourceList ${CMAKE_CURRENT_SOURCE_DIR}/${fname} )
ENDFOREACH( fname )
ENDIF()
# extract class names from source files
FOREACH( _File ${_SourceList} )
STRING( REGEX REPLACE "^.*/" "" _StrippedPath "${_File}" )
STRING( REGEX REPLACE "\\..*$" "" _StrippedExtension "${_StrippedPath}" )
LIST( APPEND _TestList ${_StrippedExtension} )
ENDFOREACH( _File )
# generate for each class a unit test if there is a testsiute for it
FOREACH( _ClassName ${_TestList} )
SET( _TestName ${_ClassName}_test )
SET( _TestTarget unittest_${_ClassName} )
SET( _TestSuitePath "${CMAKE_CURRENT_SOURCE_DIR}/test/${_TestName}.h" )
# check if testsuite is present and generate code if true
IF( EXISTS ${_TestSuitePath} )
CXXTEST_ADD_TEST( ${_TestTarget}
${_TestName}.cc
${_TestSuitePath}
)
FOREACH( _LIB ${_TestLibs} )
TARGET_LINK_LIBRARIES( ${_TestTarget} ${_LIB} )
ENDFOREACH( _LIB )
ELSE()
MESSAGE( STATUS "WARNING: Skipping ${_ClassName}, no unit test available." )
ENDIF()
ENDFOREACH( _ClassName )
ENDMACRO( CXXTEST_ADD_TESTS_FROM_LIST )
#=============================================================
# main()
#=============================================================
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment