pkg_check_modules(LIBNOTIFY libnotify REQUIRED)
pkg_check_modules(GLIB20 glib-2.0 REQUIRED)

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
)

# tst_qmlplugin

set(TEST tst_qmlplugin)

set(SOURCES
    tst_online_accounts_qml.cpp
)

add_definitions(-DQUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_BINARY_DIR}")
add_definitions(-DTEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../data")

add_executable(${TEST} ${SOURCES})

target_link_libraries(${TEST}
    Qt${QT_VERSION}::Core
    Qt${QT_VERSION}::Quick
    Qt${QT_VERSION}::Test
    Qt${QT_VERSION}QuickTest
)

# Prepare providerId QML module loading...
add_custom_command(
        TARGET ${TEST} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy
                ${CMAKE_CURRENT_SOURCE_DIR}/testPlugin/Main.qml
                ${CMAKE_CURRENT_BINARY_DIR}/testPlugin/Main.qml
)

set(QML_UI_SOURCES
    AccountCreationPage.qml
    AuthorizationPage.qml
    SignOnUiDialog.qml
)

# copy qml online-accounts-ui files over to build dir to be able to import them uninstalled
foreach(_file ${QML_UI_SOURCES})
    add_custom_command(TARGET ${TEST} POST_BUILD
                       COMMAND ${CMAKE_COMMAND} -E copy_if_different
                       ${LomiriOnlineAccountsUi_SOURCE_DIR}/qml/${_file}
                       ${CMAKE_CURRENT_BINARY_DIR}/${_file})
endforeach(_file)

set(QML_TEST_CASES
    tst_AuthorizationPage.qml
    tst_SignOnUiDialog.qml
)


# copy qml test files over to build dir to be able to import them uninstalled
foreach(_file ${QML_TEST_CASES})
    add_custom_command(TARGET ${TEST} POST_BUILD
                       COMMAND ${CMAKE_COMMAND} -E copy_if_different
                       ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
                       ${CMAKE_CURRENT_BINARY_DIR}/${_file})
endforeach(_file)
configure_file(tst_AccountCreationPage.qml.in ${CMAKE_CURRENT_BINARY_DIR}/tst_AccountCreationPage.qml)

add_test(${TEST} ${XVFB_COMMAND} dbus-test-runner -t ${CMAKE_CURRENT_BINARY_DIR}/${TEST})
