Computer Assisted Medical Intervention Tool Kit  version 5.2
CamiTKAddIntegrationTest.h
Go to the documentation of this file.
28 
29  #-- set the name of the current test and other parameters
30  set(CAMITK_INTEGRATION_TEST_NAME ${TYPE_EXTENSION}-${EXTENSION_NAME}-integration-test)
31 
32  #-- check integration data availability
33  set(CAMITK_INTEGRATION_TESTDATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/integration-testdata)
34  if (NOT EXISTS ${CAMITK_INTEGRATION_TESTDATA_DIR})
35  message(FATAL_ERROR "Can not add test ${CAMITK_INTEGRATION_TEST_NAME}: \"integration-testdata\" subdirectory not found." )
36  endif()
37 
38  set(CAMITK_INTEGRATION_SCXML asm-input.scxml)
39  if (NOT EXISTS ${CAMITK_INTEGRATION_TESTDATA_DIR})
40  message(FATAL_ERROR "Can not add test ${CAMITK_INTEGRATION_TEST_NAME}: CamiTK SCXML document not found." )
41  endif()
42 
43  # look for all the files that called "output-*"
44  file(GLOB CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES RELATIVE ${CAMITK_INTEGRATION_TESTDATA_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/integration-testdata/output-*.*)
45  list(LENGTH CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES NUMBER_OF_EXPECTED_OUTPUT_FILES)
46  if (NUMBER_OF_EXPECTED_OUTPUT_FILES EQUAL 0)
47  message(FATAL_ERROR "Can not add test ${CAMITK_INTEGRATION_TEST_NAME}: no expected output file found." )
48  endif()
49 
50  #-- clean/create test output directory
51  set(CAMITK_TEST_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Testing/Temporary/${CAMITK_INTEGRATION_TEST_NAME}")
52  file(REMOVE_RECURSE ${CAMITK_TEST_OUTPUT_DIR})
53  file(MAKE_DIRECTORY ${CAMITK_TEST_OUTPUT_DIR})
54 
55  #-- replace the input file names
56  # Read the file in a variable
57  file(READ ${CAMITK_INTEGRATION_TESTDATA_DIR}/${CAMITK_INTEGRATION_SCXML} ASM_INPUT_FILE_AS_STRING)
58  # get all the lines that have a non-empty "File Name" parameter
59  string(REGEX MATCHALL "<camitk:parameter name=\"File Name\" value=\".*\" type=\"QString\"/>" FILENAME_LINES "${ASM_INPUT_FILE_AS_STRING}")
60  # intialize ASM_INPUT_FILE_AS_STRING_OK
61  set(ASM_INPUT_FILE_AS_STRING_OK "${ASM_INPUT_FILE_AS_STRING}")
62  # for each lines that have a non-empty "File Name" parameter
63  foreach(CURRENT_LINE ${FILENAME_LINES})
64  # first replace the file name so that the file can be copied to the temp directory
65  string(REGEX REPLACE "value=\"(.*)\"" "value=\"${CAMITK_TEST_OUTPUT_DIR}/\\1\"" CURRENT_LINE_OK ${CURRENT_LINE})
66  # second replace the line in ASM_INPUT_FILE_AS_STRING_OK
67  string(REPLACE "${CURRENT_LINE}" "${CURRENT_LINE_OK}" ASM_INPUT_FILE_AS_STRING_OK "${ASM_INPUT_FILE_AS_STRING_OK}")
68  # extract the File Name
69  string(REGEX REPLACE ".*value=\"(.*)\" .*" "\\1" INPUT_FILE_NAME ${CURRENT_LINE})
70  # copy the corresponding file to the temp directory
71  file(COPY ${CAMITK_INTEGRATION_TESTDATA_DIR}/${INPUT_FILE_NAME}
72  DESTINATION ${CAMITK_TEST_OUTPUT_DIR})
73  endforeach()
74 
75  # Finally write the file in the temp directory
76  # Beware/Note: you need to add the quote around the ASM_INPUT_FILE_AS_STRING_OK value otherwise "" will be
77  # interprated as list/argument separator and will be transformed to " " (for XML files that means that each
78  # substitution will get damaged: &lt -> &lt ... not good...)
79  file(WRITE ${CAMITK_TEST_OUTPUT_DIR}/${CAMITK_INTEGRATION_SCXML} "${ASM_INPUT_FILE_AS_STRING_OK}")
80 
81  # And copy the expected output files
82  foreach(EXPECTED_OUTPUT_FILE ${CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES})
83  file(COPY ${CAMITK_INTEGRATION_TESTDATA_DIR}/${EXPECTED_OUTPUT_FILE}
84  DESTINATION ${CAMITK_TEST_OUTPUT_DIR})
85  endforeach()
86 
87  #-- run actionstatemachine
88  set(CAMITK_TEST_EXECUTABLE_ARG "-f ${CAMITK_TEST_OUTPUT_DIR}/${CAMITK_INTEGRATION_SCXML} -o ${CAMITK_TEST_OUTPUT_DIR} -a")
89 
90  #-- determine cmake macro path
91  if (NOT EXISTS SDK_TOP_LEVEL_SOURCE_DIR)
92  # this macro is called outside the sdk
93  set(CAMITK_CMAKE_MACRO_PATH ${CAMITK_CMAKE_DIR}/modules/macros/camitk/test)
94  if(NOT IS_DIRECTORY ${CAMITK_CMAKE_MACRO_PATH})
95  # inside opensource but not in sdk (modeling or imaging)
96  set(CAMITK_CMAKE_MACRO_PATH ${CMAKE_SOURCE_DIR}/sdk/cmake/modules/macros/camitk/test)
97  endif()
98  else()
99  # directly use the macro source dir
100  set(CAMITK_CMAKE_MACRO_PATH ${SDK_TOP_LEVEL_SOURCE_DIR}/cmake/modules/macros/camitk/test)
101  endif()
102 
103  #-- check if debug postfix is needed
104  set(APP_NAME camitk-actionstatemachine)
105  if(NOT CAMITK_COMMUNITY_EDITION_BUILD)
106  # this macro is called outside CamiTK CE
107 
108  # find the complete path to the test programs (removing any previous attempt to find a test application
109  # as this could be another application)
110  unset(CAMITK_INTEGRATION_TEST_EXECUTABLE CACHE)
111  find_program(CAMITK_INTEGRATION_TEST_EXECUTABLE
112  NAMES ${APP_NAME}${CAMITK_DEBUG_POSTFIX} ${APP_NAME}
113  PATH_SUFFIXES "bin"
114  PATHS ${CAMITK_BIN_DIR}
115  )
116 
117  if (NOT CAMITK_INTEGRATION_TEST_EXECUTABLE)
118  # Test programs should be installed
119  message(FATAL_ERROR "${APP_NAME} not found.\n This means that action state machine was not installed during CamiTK SDK installation.")
120  endif()
121  else()
122  # in CamiTK CE build
123 
124  # add debug postfix if needed by MSVC
125  set(APP_SUFFIX "")
126  # determine which version of the executable to use (debug-suffixed or not)
127  if(MSVC)
128  if(NOT CMAKE_BUILD_TYPE)
129  # Assume the developer that is running the test suite compiled everything in Debug
130  set(APP_SUFFIX ${CAMITK_DEBUG_POSTFIX})
131  else()
132  # support multiplaform (sometimes the "Debug" type is all uppercase, as on Win32, sometimes it is CamelCase)
133  string(TOUPPER ${CMAKE_BUILD_TYPE} CAMITK_BUILD_TYPE_UPPER)
134  if (CAMITK_BUILD_TYPE_UPPER STREQUAL "DEBUG")
135  # manage debug build only
136  set(APP_SUFFIX ${CAMITK_DEBUG_POSTFIX})
137  endif()
138  # if build type is not debug, everything is ok as
139  endif()
140  endif()
141 
142  # In CamiTK CE build directly use the binary dir version
143  set(CAMITK_INTEGRATION_TEST_EXECUTABLE ${CMAKE_BINARY_DIR}/bin/${APP_NAME}${APP_SUFFIX})
144  endif()
145 
146  #-- and add the test
147  # Construct a specific string for outputfiles to pass them properly to the test command
148  unset(CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG)
149  foreach(TEST_EXPECTED_OUTPUT_FILE ${CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES})
150  # add specific "::" separator
151  if(CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG)
152  string(CONCAT CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG "${CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG}::${TEST_EXPECTED_OUTPUT_FILE}")
153  else()
154  set(CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG ${TEST_EXPECTED_OUTPUT_FILE})
155  endif()
156  endforeach()
157  add_test(NAME ${CAMITK_INTEGRATION_TEST_NAME}
158  COMMAND ${CMAKE_COMMAND}
159  -DCAMITK_TEST_COMMAND=${CAMITK_INTEGRATION_TEST_EXECUTABLE}
160  -DCAMITK_TEST_COMMAND_ARG=${CAMITK_TEST_EXECUTABLE_ARG}
161  -DCAMITK_TEST_EXPECTED_FILES=${CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG}
162  -DCAMITK_TEST_OUTPUT_DIR=${CAMITK_TEST_OUTPUT_DIR}
163  -DCAMITK_TEST_NAME=${CAMITK_INTEGRATION_TEST_NAME}
164  -P ${CAMITK_CMAKE_MACRO_PATH}/CamiTKTestActionStateMachine.cmake
165  WORKING_DIRECTORY ${CMAKE_BINARY_DIR} # needs to be at the top of the CamiTK module repository
166  )
167 
168 
169  # set the label for tests / associate tests to a project name in CDash
170  if( CAMITK_ADD_TEST_PROJECT_NAME )
171  set_tests_properties( ${CAMITK_INTEGRATION_TEST_NAME} PROPERTIES LABELS ${CAMITK_ADD_TEST_PROJECT_NAME} )#
172  else()
173  set_tests_properties( ${CAMITK_INTEGRATION_TEST_NAME} PROPERTIES LABELS ${CAMITK_INTEGRATION_TEST_NAME} )
174  endif()
175 
176 end(){)
if(${CMAKE_VERSION} VERSION_GREATER "3.3" OR ${CMAKE_VERSION} VERSION_EQUAL "3.3") option(CAMITK_INCLUDE_WHAT_YOU_USE "Enable the header analysis on you code
cmake modules macros camitk test endif() add_custom_target(camitk-ce-iwyu COMMAND $
Definition: CamiTKIncludeWhatYouUse.h:37
#define a
iwyu out CACHE PATH Output filename for include what you use set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_EXECUTABLE}) if(NOT EXISTS $
Definition: CamiTKIncludeWhatYouUse.h:22
test result unset(PREVIOUS_ATTEMPTS) file(GLOB ALL_OUTPUT_FILES $
Definition: CamiTKTestActionStateMachine.h:16
camitk_add_integration_test()
camitk_add_integration_test is a macro to add a new test to the CTest infrastructure It encapsulates ...
Definition: CamiTKAddIntegrationTest.h:27
Definition: Action.cpp:36