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${QT_VERSION}/${_file}
                       ${CMAKE_CURRENT_BINARY_DIR}/${_file})
endforeach(_file)

set(QML_TEST_CASES
    tst_AuthorizationPage.qml
    tst_SignOnUiDialog.qml
    tst_AccountCreationPage.qml
)

set(LOMIRI_TEST_VERSION)
if(QT_VERSION LESS 6)
    set(LOMIRI_TEST_VERSION 0.1)
endif()
foreach(_file ${QML_TEST_CASES})
    configure_file(${_file}.in ${CMAKE_CURRENT_BINARY_DIR}/${_file} @ONLY)
endforeach(_file)

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