# use the application extension macro
camitk_application(NEEDS_QT_MODULES #we use QtXML
                   ADDITIONAL_SOURCES CommandLineOptions.cxx CommandLineOptions.hxx
                   CEP_NAME SDK
                   NEEDS_VIEWER_EXTENSION explorer interactivesliceviewer interactivegeometryviewer medicalimageviewer
                   DESCRIPTION "Simple action state machine to pipeline actions from an XML file"
)

# Recursively update the shiboken path variable containing the CamiTK SDK tree structure
set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") 

# Automatic tests
set(TEST_BASENAME ${APPLICATION_TARGET_NAME})
camitk_init_test(${TEST_BASENAME})

# should pass because invoking camitk-actionstatemachine without arguments or with help
# arg shows usage and exit success
camitk_add_test(EXECUTABLE_ARGS "--help" PROJECT_NAME ${TEST_BASENAME} TEST_SUFFIX "-")
camitk_add_test(EXECUTABLE_ARGS "-h"     PROJECT_NAME ${TEST_BASENAME} TEST_SUFFIX "-")

# should pass because invoking testcomponents with a faulty arguments results in printing
# an "Argument error" message (and exit failure)
camitk_add_test(EXECUTABLE_ARGS "-badarg" 
                PASS_REGULAR_EXPRESSION "unknown option '-badarg'"
                PROJECT_NAME ${TEST_BASENAME} TEST_SUFFIX "-")

# Testing using the testdata scxml  
# note for the regular expression: 
# as [ ] are regex wild card and " is not easy to escaped, all theses characters are replaced by .
# see https://cmake.org/cmake/help/latest/command/string.html#regex-specification
# for more information on CMake regex
camitk_add_test(EXECUTABLE_ARGS "-f ${PROJECT_SOURCE_DIR}/sdk/applications/actionstatemachine/testdata/asmSimpleImageFilter.xml -o ${PROJECT_BINARY_DIR}/Testing/Temporary/application-actionstatemachine-4 -a" 
                PASS_REGULAR_EXPRESSION ".INFO   . Application .camitk-actionstatemachine. - Exiting application..."
                PROJECT_NAME ${TEST_BASENAME} TEST_SUFFIX "-")

camitk_add_test(EXECUTABLE_ARGS "-f ${PROJECT_SOURCE_DIR}/sdk/applications/actionstatemachine/testdata/asmSimpleMeshProcessing.xml -o ${PROJECT_BINARY_DIR}/Testing/Temporary/application-actionstatemachine-5 -a" 
                PASS_REGULAR_EXPRESSION ".INFO   . Application .camitk-actionstatemachine. - Exiting application..."
                PROJECT_NAME ${TEST_BASENAME} TEST_SUFFIX "-")

# cannot test on windows (OpenGL missing)
camitk_tests_requirement(TESTS application-actionstatemachine-4 application-actionstatemachine-5
                         REQUIRES "NOT WIN32"
                         REASON "WIN32 OpenGL failure on a VM
   This test will always fail when run inside a VM due to OpenGL crash.
   E.g. 131: ERR: egl::Display::initialize(482): ANGLE Display::initialize error 12289: No available renderers.
   This test will pass when run directly from a physical windows machine."
)
