CamiTKAdditionalActionTest.cmake 7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!
#! @ingroup group_sdk_cmake_camitk_test
#!
#! camitk_additional_action_test is a macro to create additional level1 test of CamiTK action
#! to the CTest infrastructure.
#!
#! It should be used when a CEP introduces a new component (with new test files)
#! and an existing action should be run using this new component and test files.
#!
#! Usage:
#! \code
#! camitk_additional_action_test(ACTION_EXTENSIONS action1 action2 ...
#!                               [TEST_FILES  file1 file2 ...]
#!                               [TEST_SUFFIX name]
#! )
#! \endcode
#!
#! \param ACTION_EXTENSIONS      List of the action extension that will be additionnaly tested with the given
#!                               test files. Only the action extension name (note the full library/dll name nor
#!                               the path should be given. This macro checks the existence of the extension
#!                               library/dll in the following directories (in this order) : build dir;
#!                               user install dir and global install dir. The first one found is used for the tests.
#! \param TEST_FILES             Optional. List of files to use for testing. If not set, then all the files in the
#!                               testdata dir are used.
#!                               If provided, only the filenames are required (not the absolute paths) and 
#!                               all the given files should be in the testdata subdir.
#! \param TEST_SUFFIX            Optional. suffix name for the additional test. default value is the name of the 
#!                               current component extension. 
#!
#! @sa camitk_extension
macro(camitk_additional_action_test)
    if (NOT PACKAGING_NSIS AND BUILD_TESTING)
        set(options "")
        set(oneValueArgs TEST_SUFFIX)
        set(multiValueArgs ACTION_EXTENSIONS TEST_FILES)
        cmake_parse_arguments(CAMITK_ADDITIONAL_ACTION_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
        
38
        if (CAMITK_ADDITIONAL_ACTION_TEST_TEST_SUFFIX)
39
40
41
42
43
            set(CAMITK_ADDITIONAL_ACTION_TEST_SUFFIX ${CAMITK_ADDITIONAL_ACTION_TEST_TEST_SUFFIX})      
        else()
            set(CAMITK_ADDITIONAL_ACTION_TEST_SUFFIX ${EXTENSION_NAME})
        endif()

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
        # COMPONENT_EXTENSION_PLUGIN_FILE
        # determine the extension full file name depending on the plateform
        if (MSVC)
            set(COMPONENT_EXTENSION_PLUGIN_FILE "components/${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}${CAMITK_DEBUG_POSTFIX}.dll")
        elseif(APPLE)
            set(COMPONENT_EXTENSION_PLUGIN_FILE "components/lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.dylib")
        else()
            # Must be Linux
            set(COMPONENT_EXTENSION_PLUGIN_FILE "components/lib${${TYPE_EXTENSION_CMAKE}_OUTPUT_NAME}.so") 
        endif()
        
        # if this is not SDK, then it is required
        if(NOT CAMITK_SDK_BUILD)
            set(ADDITIONAL_COMPONENT_EXTENSION_ARG "-c ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${COMPONENT_EXTENSION_PLUGIN_FILE}")
        endif()
        
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
        # loop over actions
        #   if (action extension exists in repository) CAMITK_USER_PRIVATE_LIB_DIR CAMITK_PRIVATE_LIB_DIR  CAMITK_BUILD_PRIVATE_LIB_DIR
        #   loop over test files
        #     add test
        #     math(EXPR CAMITK_ADDITIONNAL_TEST_ID "${CAMITK_ADDITIONNAL_TEST_ID} + 1")
        foreach(ACTION_EXTENSION ${CAMITK_ADDITIONAL_ACTION_TEST_ACTION_EXTENSIONS})
            # determine the extension full file name depending on the plateform
            if (MSVC)
                set(EXTENSION_FILE "actions/${ACTION_EXTENSION}${CAMITK_DEBUG_POSTFIX}.dll")
            elseif(APPLE)
                set(EXTENSION_FILE "$actions/lib${ACTION_EXTENSION}.dylib")
            else()
                # Must be Linux
                set(EXTENSION_FILE "actions/lib${ACTION_EXTENSION}.so") 
            endif()
            
            # check if action can be found in (this order) : build dir (CAMITK_BUILD_PRIVATE_LIB_DIR),
77
            # local user install (CAMITK_USER_PRIVATE_LIB_DIR, and global install (CAMITK_PRIVATE_LIB_DIR)
78
            set(ACTION_EXTENSION_PLUGIN_FILE ${CAMITK_BUILD_PRIVATE_LIB_DIR}/${EXTENSION_FILE})
79
80
81
82
83
84
            set(ACTION_EXTENSION_TARGET "action-${ACTION_EXTENSION}")
            # The action should already be compiled.
            # if the action does not yet exists, if there is a target of the current project
            # that will build it, then it is ok as well.
            # otherwise, it should be already installed locally or globally
            if ((NOT EXISTS ${ACTION_EXTENSION_PLUGIN_FILE}) AND (NOT TARGET ${ACTION_EXTENSION_TARGET}))
85
86
87
88
                set(ACTION_EXTENSION_PLUGIN_FILE ${CAMITK_USER_PRIVATE_LIB_DIR}/${EXTENSION_FILE})
                if (NOT EXISTS ${ACTION_EXTENSION_PLUGIN_FILE})
                    set(ACTION_EXTENSION_PLUGIN_FILE ${CAMITK_PRIVATE_LIB_DIR}/${EXTENSION_FILE})
                    if (NOT EXISTS ${ACTION_EXTENSION_PLUGIN_FILE})
89
                        message(SEND_ERROR "Action extension \"${ACTION_EXTENSION}\" not found: no additional test added")
90
91
92
93
94
                        return()
                    endif()
                endif()
            endif()
            
95
            message(STATUS "Adding additional autotest for action-${ACTION_EXTENSION}")
96
97
98
99
100
101
            if (CAMITK_SDK_BUILD)
                camitk_init_test(application-testactions)
            else()
                camitk_init_test(camitk-testactions)
            endif()
            
102
            # add a separator to the wiki page information
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
            camitk_parse_test_add_separator(EXTENSION_TYPE actions EXTENSION_NAME ${ACTION_EXTENSION})

            # Retrieve the files in testdata directory - a test will be applied for each of these files
            # or use only the given files
            if (CAMITK_ADDITIONAL_ACTION_TEST_TEST_FILES)
                # add testdata dir to filename
                set(TESTFILES)
                foreach(COMPONENT_TESTDATA_FILE ${CAMITK_ADDITIONAL_ACTION_TEST_TEST_FILES})
                    list(APPEND TESTFILES ${CMAKE_CURRENT_SOURCE_DIR}/testdata/${COMPONENT_TESTDATA_FILE})
                endforeach()
            else()
                get_subdirectoryfiles( ${CMAKE_CURRENT_SOURCE_DIR}/testdata TESTFILES )
            endif()
                
            foreach( ACTION_TESTDATA_FILE ${TESTFILES})
                # Test procedure: Open a file - load an action extension - Apply an action on the component wrapping the file
119
                camitk_add_test(EXECUTABLE_ARGS "-i ${ACTION_TESTDATA_FILE} -a ${ACTION_EXTENSION_PLUGIN_FILE} ${ADDITIONAL_COMPONENT_EXTENSION_ARG}" 
120
121
122
                                TEST_SUFFIX "-additional-${CAMITK_ADDITIONAL_ACTION_TEST_SUFFIX}-level1-"
                                PROJECT_NAME "action-${ACTION_EXTENSION}"
                )
123
                # add test to the wiki page information 
124
125
126
127
128
129
130
                camitk_parse_test_add(NAME ${CAMITK_TEST_NAME} LEVEL 1 DESCRIPTION "Open a file, load the action and apply it on the component.")
            endforeach()

        endforeach()
    endif()
endmacro()