Computer Assited Medical Intervention Tool Kit  version 4.1
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  # message("===== Input File = ${INPUT_FILE_NAME}")
72  file(COPY ${CAMITK_INTEGRATION_TESTDATA_DIR}/${INPUT_FILE_NAME}
73  DESTINATION ${CAMITK_TEST_OUTPUT_DIR})
74  endforeach()
75 
76  # Finally write the file in the temp directory
77  # Beware/Note: you need to add the quote around the ASM_INPUT_FILE_AS_STRING_OK value otherwise "" will be
78  # interprated as list/argument separator and will be transformed to " " (for XML files that means that each
79  # substitution will get damaged: &lt -> &lt ... not good...)
80  file(WRITE ${CAMITK_TEST_OUTPUT_DIR}/${CAMITK_INTEGRATION_SCXML} "${ASM_INPUT_FILE_AS_STRING_OK}")
81 
82  # And copy the expected output files
83  foreach(EXPECTED_OUTPUT_FILE ${CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES})
84  file(COPY ${CAMITK_INTEGRATION_TESTDATA_DIR}/${EXPECTED_OUTPUT_FILE}
85  DESTINATION ${CAMITK_TEST_OUTPUT_DIR})
86  endforeach()
87 
88  #-- run actionstatemachine
89  set(CAMITK_TEST_EXECUTABLE_ARG "-f ${CAMITK_TEST_OUTPUT_DIR}/${CAMITK_INTEGRATION_SCXML} -o ${CAMITK_TEST_OUTPUT_DIR} -a")
90 
91  #-- determine cmake macro path
92  if (NOT EXISTS SDK_TOP_LEVEL_SOURCE_DIR)
93  # this macro is called outside the sdk
94  set(CAMITK_CMAKE_MACRO_PATH ${CAMITK_CMAKE_DIR}/modules/macros/camitk/test)
95  if(NOT IS_DIRECTORY ${CAMITK_CMAKE_MACRO_PATH})
96  # inside opensource but not in sdk (modeling or imaging)
97  set(CAMITK_CMAKE_MACRO_PATH ${CMAKE_SOURCE_DIR}/sdk/cmake/modules/macros/camitk/test)
98  endif()
99  else()
100  # directly use the macro source dir
101  set(CAMITK_CMAKE_MACRO_PATH ${SDK_TOP_LEVEL_SOURCE_DIR}/cmake/modules/macros/camitk/test)
102  endif()
103 
104  #-- check if debug postfix is needed
105  set(APP_NAME camitk-actionstatemachine)
106  if(NOT CAMITK_COMMUNITY_EDITION_BUILD)
107  # this macro is called outside CamiTK CE
108 
109  # find the complete path to the test programs (removing any previous attempt to find a test application
110  # as this could be another application)
111  unset(CAMITK_INTEGRATION_TEST_EXECUTABLE CACHE)
112  find_program(CAMITK_INTEGRATION_TEST_EXECUTABLE
113  NAMES ${APP_NAME}${CAMITK_DEBUG_POSTFIX} ${APP_NAME}
114  PATH_SUFFIXES "bin"
115  PATHS ${CAMITK_BIN_DIR}
116  )
117 
118  if (NOT CAMITK_INTEGRATION_TEST_EXECUTABLE)
119  # Test programs should be installed
120  message(FATAL_ERROR "${APP_NAME} not found.\n This means that action state machine was not installed during CamiTK SDK installation.")
121  endif()
122  else()
123  # in CamiTK CE build
124 
125  # add debug postfix if needed by MSVC
126  set(APP_SUFFIX "")
127  # determine which version of the executable to use (debug-suffixed or not)
128  if(MSVC)
129  if(NOT CMAKE_BUILD_TYPE)
130  # Assume the developer that is running the test suite compiled everything in Debug
131  set(APP_SUFFIX ${CAMITK_DEBUG_POSTFIX})
132  else()
133  # support multiplaform (sometimes the "Debug" type is all uppercase, as on Win32, sometimes it is CamelCase)
134  string(TOUPPER ${CMAKE_BUILD_TYPE} CAMITK_BUILD_TYPE_UPPER)
135  if (CAMITK_BUILD_TYPE_UPPER STREQUAL "DEBUG")
136  # manage debug build only
137  set(APP_SUFFIX ${CAMITK_DEBUG_POSTFIX})
138  endif()
139  # if build type is not debug, everything is ok as
140  endif()
141  endif()
142 
143  # In CamiTK CE build directly use the binary dir version
144  set(CAMITK_INTEGRATION_TEST_EXECUTABLE ${CMAKE_BINARY_DIR}/bin/${APP_NAME}${APP_SUFFIX})
145  endif()
146 
147  #-- and add the test
148  # Construct a specific string for outputfiles to pass them properly to the test command
149  unset(CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG)
150  foreach(TEST_EXPECTED_OUTPUT_FILE ${CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES})
151  # add specific "::" separator
152  if(CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG)
153  string(CONCAT CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG "${CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG}::${TEST_EXPECTED_OUTPUT_FILE}")
154  else()
155  set(CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG ${TEST_EXPECTED_OUTPUT_FILE})
156  endif()
157  endforeach()
158  add_test(NAME ${CAMITK_INTEGRATION_TEST_NAME}
159  COMMAND ${CMAKE_COMMAND}
160  -DCAMITK_TEST_COMMAND=${CAMITK_INTEGRATION_TEST_EXECUTABLE}
161  -DCAMITK_TEST_COMMAND_ARG=${CAMITK_TEST_EXECUTABLE_ARG}
162  -DCAMITK_TEST_EXPECTED_FILES=${CAMITK_INTEGRATION_TEST_EXPECTED_OUTPUT_FILES_ARG}
163  -DCAMITK_TEST_OUTPUT_DIR=${CAMITK_TEST_OUTPUT_DIR}
164  -DCAMITK_TEST_NAME=${CAMITK_INTEGRATION_TEST_NAME}
165  -P ${CAMITK_CMAKE_MACRO_PATH}/CamiTKTestActionStateMachine.cmake
166  WORKING_DIRECTORY ${CMAKE_BINARY_DIR} # needs to be at the top of the CamiTK module repository
167  )
168 
169 
170  # set the label for tests / associate tests to a project name in CDash
171  if( CAMITK_ADD_TEST_PROJECT_NAME )
172  set_tests_properties( ${CAMITK_INTEGRATION_TEST_NAME} PROPERTIES LABELS ${CAMITK_ADD_TEST_PROJECT_NAME} )#
173  else()
174  set_tests_properties( ${CAMITK_INTEGRATION_TEST_NAME} PROPERTIES LABELS ${CAMITK_INTEGRATION_TEST_NAME} )
175  endif()
176 
177 end(){)
test result unset(PREVIOUS_ATTEMPTS) file(GLOB ALL_OUTPUT_FILES $
Definition: CamiTKTestActionStateMachine.h:43
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
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
Definition: Action.cpp:36
cmake modules macros camitk test endif() add_custom_target(camitk-ce-iwyu COMMAND $
Definition: CamiTKIncludeWhatYouUse.h:37
#define a
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