Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkMacroCreateModuleTests.cmake
Go to the documentation of this file.
1 #
2 # Create tests and testdriver for this module
3 #
4 # Usage: MITK_CREATE_MODULE_TESTS( [EXTRA_DRIVER_INIT init_code] )
5 #
6 # EXTRA_DRIVER_INIT is inserted as c++ code in the testdriver and will be executed before each test
7 #
9  cmake_parse_arguments(MODULE_TEST
10  "US_MODULE;NO_INIT" "EXTRA_DRIVER_INIT;EXTRA_DRIVER_INCLUDE" "EXTRA_DEPENDS;DEPENDS;PACKAGE_DEPENDS" ${ARGN})
11 
12  if(BUILD_TESTING AND MODULE_IS_ENABLED)
13  include(files.cmake)
14  include_directories(.)
15 
16  set(TESTDRIVER ${MODULE_NAME}TestDriver)
17 
18  set(MODULE_TEST_EXTRA_DRIVER_INIT "${MODULE_TEST_EXTRA_DRIVER_INIT}")
19 
20  if(MODULE_TEST_US_MODULE)
21  message(WARNING "The US_MODULE argument is deprecated and should be removed")
22  endif()
23 
24  if(MODULE_TEST_US_MODULE AND MODULE_TEST_NO_INIT)
25  message(WARNING "Conflicting arguments US_MODULE and NO_INIT: NO_INIT wins.")
26  endif()
27 
28  set(_no_init)
29  if(MODULE_TEST_NO_INIT)
30  set(_no_init NO_INIT)
31  endif()
32 
33  set(MITK_MODULE_NAME_REGEX_MATCH )
34  set(MITK_MODULE_NAME_REGEX_NOT_MATCH )
35 
36  set(_testdriver_file_list ${CMAKE_CURRENT_BINARY_DIR}/testdriver_files.cmake)
37  configure_file(${MITK_CMAKE_DIR}/mitkTestDriverFiles.cmake.in ${_testdriver_file_list} @ONLY)
38  mitk_create_executable(${TESTDRIVER}
39  DEPENDS ${MODULE_NAME} ${MODULE_TEST_DEPENDS} ${MODULE_TEST_EXTRA_DEPENDS} MitkTestingHelper
40  PACKAGE_DEPENDS ${MODULE_TEST_PACKAGE_DEPENDS}
41  SUBPROJECTS ${MODULE_SUBPROJECTS}
42  FILES_CMAKE ${_testdriver_file_list}
43  NO_FEATURE_INFO NO_BATCH_FILE ${_no_init})
44 
45  #
46  # Now tell CMake which tests should be run. This is done automatically
47  # for all tests in ${KITNAME}_TESTS and ${KITNAME}_IMAGE_TESTS. The IMAGE_TESTS
48  # are run for each image in the TESTIMAGES list.
49  #
50  include(files.cmake)
51  foreach( test ${MODULE_TESTS} )
52  get_filename_component(TName ${test} NAME_WE)
53  add_test(${TName} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} ${TName})
54  # Add labels for CDash subproject support
55  if(MODULE_SUBPROJECTS)
56  set_property(TEST ${TName} PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK)
57  endif()
58  endforeach()
59 
60  set(TEST_TYPES IMAGE SURFACE POINTSET) # add other file types here
61 
62  foreach(test_type ${TEST_TYPES})
63  foreach(test_data ${MODULE_TEST${test_type}} ${ADDITIONAL_TEST_${test_type}})
64  if(EXISTS ${test_data})
65  set(TEST_DATA_FULL_PATH ${test_data})
66  else()
67  # todo: maybe search other paths as well
68  # yes, please in mitk/Testing/Data, too
69  set(TEST_DATA_FULL_PATH ${MITK_DATA_DIR}/${test_data})
70  endif()
71 
72  if(EXISTS ${TEST_DATA_FULL_PATH})
73  foreach( test ${MODULE_${test_type}_TESTS})
74  get_filename_component(TName ${test} NAME_WE)
75  get_filename_component(DName ${TEST_DATA_FULL_PATH} NAME)
76  add_test(${TName}_${DName} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} ${TName} ${TEST_DATA_FULL_PATH})
77  # Add labels for CDash subproject support
78  if(MODULE_SUBPROJECTS)
79  set_property(TEST ${TName}_${DName} PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK)
80  endif()
81  endforeach()
82  else()
83  message("!!!!! No such file: ${TEST_DATA_FULL_PATH} !!!!!")
84  endif()
85  endforeach()
86  endforeach()
87 
88  endif()
89 
90 endmacro()
#define MITK_DATA_DIR
MITK_CREATE_MODULE_TESTS()
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
Definition: testcase.h:32
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Definition: jsoncpp.cpp:244
const std::string NAME
mitk_create_executable()