set(CMAKE_AUTOMOC on)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui Widgets Test DBus Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets Test DBus Widgets REQUIRED)

include_directories(../)

add_executable(screenMonitorTest
    ../src/main/screen-monitor.cpp
    src/main/screen-monitor-test.cpp)

set(EXTERNAL_LIBS "")
set(PC_PKGS gsettings-qt)

foreach(lib IN ITEMS ${PC_PKGS})
    pkg_check_modules(${lib} REQUIRED ${lib})
    if(${${lib}_FOUND})
        include_directories(${${lib}_INCLUDE_DIRS})
        link_directories(${${lib}_LIBRARY_DIRS})
        list(APPEND EXTERNAL_LIBS ${${lib}_LIBRARIES})
    endif()
endforeach()

target_link_libraries(screenMonitorTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
        ${EXTERNAL_LIBS}
)
add_test(NAME screenMonitorTest COMMAND $<TARGET_FILE:screenMonitorTest>)

# handGestureHelperTest
add_executable(handGestureHelperTest
    ../src/main/hand-gesture-helper.cpp
    ../src/main/screen-monitor.cpp
    src/main/hand-gesture-helper-test.cpp)
target_link_libraries(handGestureHelperTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
        ${EXTERNAL_LIBS}
)
add_test(NAME handGestureHelperTest COMMAND $<TARGET_FILE:handGestureHelperTest>)

# appManagerTest
add_executable(appManagerTest
    ../src/main/app-manager.cpp
    src/main/app-manager-test.cpp)
target_link_libraries(appManagerTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
        ${EXTERNAL_LIBS}
)
add_test(NAME appManagerTest COMMAND $<TARGET_FILE:appManagerTest>)

# accountInformationTest
find_package(ukui-quick COMPONENTS platform REQUIRED)
add_executable(accountInformationTest
    ../src/main/account-information.cpp
    ../src/main/app-manager.cpp
    src/main/account-information-test.cpp)
target_link_libraries(accountInformationTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
        ukui-quick::platform
        ${EXTERNAL_LIBS}
)
add_test(NAME accountInformationTest COMMAND $<TARGET_FILE:accountInformationTest>)

# globalSettingsTest
add_executable(globalSettingsTest
    ../src/main/global-settings.cpp
    src/main/global-settings-test.cpp)
pkg_check_modules(GIO REQUIRED gio-2.0)
target_include_directories(globalSettingsTest PRIVATE ${GIO_INCLUDE_DIRS})
target_link_libraries(globalSettingsTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
        ${EXTERNAL_LIBS}
        ${GIO_LIBRARIES}
)
add_test(NAME globalSettingsTest COMMAND $<TARGET_FILE:globalSettingsTest>)

# widgetDelegateTest
find_package(ukui-quick COMPONENTS framework core REQUIRED)
add_executable(widgetDelegateTest
    ../src/model/widget-delegate.cpp
    src/model/widget-delegate-test.cpp)
target_link_libraries(widgetDelegateTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Quick
        Qt${QT_VERSION_MAJOR}::Test
        ukui-quick::framework
        ukui-quick::core
)
add_test(NAME widgetDelegateTest COMMAND $<TARGET_FILE:widgetDelegateTest>)

# shortcutModelTest
pkg_check_modules(UKUI_SHORTCUT REQUIRED ukui-shortcut)
find_package(ukui-quick COMPONENTS core REQUIRED)
add_executable(shortcutModelTest
    ../src/model/shortcut-model.cpp
    ../src/model/shortcut-item.cpp
    ../src/model/shortcut-filter-model.cpp
    ../src/model/edit-shortcut-model.cpp
    ../src/model/shortcut-config.cpp
    ../src/main/global-settings.cpp
    src/model/shortcut-model-test.cpp)
target_include_directories(shortcutModelTest PRIVATE
    ${UKUI_SHORTCUT_INCLUDE_DIRS}
    ${GIO_INCLUDE_DIRS}
)
target_link_libraries(shortcutModelTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Quick
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
        ukui-quick::platform
        ukui-quick::framework
        ukui-quick::core
        ${EXTERNAL_LIBS}
        ${GIO_LIBRARIES}
        ${UKUI_SHORTCUT_LIBRARIES}
)
add_test(NAME shortcutModelTest COMMAND $<TARGET_FILE:shortcutModelTest>)

# editShortcutModelTest
add_executable(editShortcutModelTest
    ../src/model/shortcut-model.cpp
    ../src/model/shortcut-item.cpp
    ../src/model/shortcut-filter-model.cpp
    ../src/model/edit-shortcut-model.cpp
    ../src/model/shortcut-config.cpp
    ../src/main/global-settings.cpp
    src/model/edit-shortcut-model-test.cpp)
target_include_directories(editShortcutModelTest PRIVATE
    ${UKUI_SHORTCUT_INCLUDE_DIRS}
    ${GIO_INCLUDE_DIRS}
)
target_link_libraries(editShortcutModelTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Quick
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
        ukui-quick::platform
        ukui-quick::framework
        ukui-quick::core
        ${EXTERNAL_LIBS}
        ${GIO_LIBRARIES}
        ${UKUI_SHORTCUT_LIBRARIES}
)
add_test(NAME editShortcutModelTest COMMAND $<TARGET_FILE:editShortcutModelTest>)

# shortcutConfigTest
add_executable(shortcutConfigTest
    ../src/model/shortcut-config.cpp
    src/model/shortcut-config-test.cpp)
target_link_libraries(shortcutConfigTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_VERSION_MAJOR}::Test
        ukui-quick::platform
        ukui-quick::framework
        ukui-quick::core
)
add_test(NAME shortcutConfigTest COMMAND $<TARGET_FILE:shortcutConfigTest>)

# shortcutItemTest
add_executable(shortcutItemTest
    ../src/model/shortcut-item.cpp
    ../src/model/shortcut-config.cpp
    src/model/shortcut-item-test.cpp)
target_include_directories(shortcutItemTest PRIVATE
    ${UKUI_SHORTCUT_INCLUDE_DIRS}
)
target_link_libraries(shortcutItemTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Quick
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
        ukui-quick::platform
        ukui-quick::framework
        ukui-quick::core
        ${EXTERNAL_LIBS}
        ${UKUI_SHORTCUT_LIBRARIES}
)
add_test(NAME shortcutItemTest COMMAND $<TARGET_FILE:shortcutItemTest>)

# shortcutFilterModelTest
add_executable(shortcutFilterModelTest
    ../ukui-shortcut/interface/plugin-common-data.h
    ../ukui-shortcut/interface/ukui-shortcut.h
    ../ukui-shortcut/interface/ukui-shortcut-plugin.cpp
    ../ukui-shortcut/interface/status-info.cpp
    ../src/model/shortcut-model.cpp
    ../src/model/shortcut-item.cpp
    ../src/model/shortcut-filter-model.cpp
    ../src/model/edit-shortcut-model.cpp
    ../src/model/shortcut-config.cpp
    ../src/main/global-settings.cpp
    src/model/shortcut-filter-model-test.cpp)
target_include_directories(shortcutFilterModelTest PRIVATE
    ${UKUI_SHORTCUT_INCLUDE_DIRS}
    ${GIO_INCLUDE_DIRS}
)
target_link_libraries(shortcutFilterModelTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Quick
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
        ukui-quick::platform
        ukui-quick::framework
        ukui-quick::core
        ${EXTERNAL_LIBS}
        ${GIO_LIBRARIES}
)
add_test(NAME shortcutFilterModelTest COMMAND $<TARGET_FILE:shortcutFilterModelTest>)

# notificationUtilsTest
add_executable(notificationUtilsTest
    ../src/notification/notification-utils.cpp
    src/notification/notification-utils-test.cpp)
target_link_libraries(notificationUtilsTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_VERSION_MAJOR}::Test
)
add_test(NAME notificationUtilsTest COMMAND $<TARGET_FILE:notificationUtilsTest>)

# urgencyNotificationModelTest
pkg_check_modules(UKUI_NOTIFICATION REQUIRED ukui-notification)
add_executable(urgencyNotificationModelTest
    ../src/notification/notification-utils.cpp
    ../src/notification/urgency-notification-model.cpp
    src/notification/urgency-notification-model-test.cpp)
target_include_directories(urgencyNotificationModelTest PRIVATE
    ${UKUI_NOTIFICATION_INCLUDE_DIRS}
)
target_link_libraries(urgencyNotificationModelTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Test
        ${UKUI_NOTIFICATION_LIBRARIES}
)
add_test(NAME urgencyNotificationModelTest COMMAND $<TARGET_FILE:urgencyNotificationModelTest>)

# groupCacheProxyModelTest
add_executable(groupCacheProxyModelTest
    ../src/notification/group-cache-proxy-model.cpp
    src/notification/group-cache-proxy-model-test.cpp)
target_include_directories(groupCacheProxyModelTest PRIVATE
    ${UKUI_NOTIFICATION_INCLUDE_DIRS}
)
target_link_libraries(groupCacheProxyModelTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Test
        ${UKUI_NOTIFICATION_LIBRARIES}
)
add_test(NAME groupCacheProxyModelTest COMMAND $<TARGET_FILE:groupCacheProxyModelTest>)

# notificationGroupModelTest
add_executable(notificationGroupModelTest
    ../src/notification/notification-group-model.cpp
    src/notification/notification-group-model-test.cpp)
target_include_directories(notificationGroupModelTest PRIVATE
    ${UKUI_NOTIFICATION_INCLUDE_DIRS}
)
target_link_libraries(notificationGroupModelTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Test
        ${UKUI_NOTIFICATION_LIBRARIES}
)
add_test(NAME notificationGroupModelTest COMMAND $<TARGET_FILE:notificationGroupModelTest>)

# notificationManagerTest
add_executable(notificationManagerTest
    ../src/notification/notification-manager.cpp
    src/notification/notification-manager-test.cpp
    src/notification/stubs/app-manager.h
    src/notification/stubs/notification-helper.h
    src/notification/stubs/notification-manager-stubs.cpp)
target_include_directories(notificationManagerTest BEFORE PRIVATE
    src/notification/stubs
)
target_link_libraries(notificationManagerTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
)
add_test(NAME notificationManagerTest COMMAND $<TARGET_FILE:notificationManagerTest>)

# popupNotificationModelTest
add_executable(popupNotificationModelTest
    ../src/notification/popup-notification-model.cpp
    src/notification/popup-notification-model-test.cpp
    src/notification/stubs/global-settings.h
    src/notification/stubs/screen-monitor.h
    src/notification/stubs/notification-ui-stubs.cpp)
target_include_directories(popupNotificationModelTest BEFORE PRIVATE
    src/notification/stubs
    ${UKUI_NOTIFICATION_INCLUDE_DIRS}
)
target_link_libraries(popupNotificationModelTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Test
        ${UKUI_NOTIFICATION_LIBRARIES}
)
add_test(NAME popupNotificationModelTest COMMAND $<TARGET_FILE:popupNotificationModelTest>)

# notificationModelTest
add_executable(notificationModelTest
    ../src/notification/notification-utils.cpp
    ../src/notification/notification-model.cpp
    src/notification/notification-model-test.cpp
    src/notification/stubs/popup-notification.h
    src/notification/stubs/notification-close-reason.h
    src/notification/stubs/notification-client.h
    src/notification/stubs/applications-settings.h
    src/notification/stubs/notification-global-settings.h
    src/notification/stubs/global-settings.h
    src/notification/stubs/screen-monitor.h
    src/notification/stubs/notification-ui-stubs.cpp
    src/notification/stubs/notification-model-stubs.cpp)
target_include_directories(notificationModelTest BEFORE PRIVATE
    src/notification/stubs
)
target_link_libraries(notificationModelTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
)
add_test(NAME notificationModelTest COMMAND $<TARGET_FILE:notificationModelTest>)

# shortcutModelIsolatedTest
add_executable(shortcutModelIsolatedTest
    ../ukui-shortcut/interface/plugin-common-data.h
    ../ukui-shortcut/interface/value-type.h
    ../ukui-shortcut/interface/ukui-shortcut.h
    ../ukui-shortcut/interface/ukui-shortcut-plugin.cpp
    ../ukui-shortcut/interface/status-info.cpp
    ../src/model/plugin-state.h
    ../src/model/shortcut-model.cpp
    ../src/model/shortcut-item.cpp
    ../src/model/shortcut-filter-model.cpp
    ../src/model/edit-shortcut-model.cpp
    ../src/model/shortcut-config.cpp
    ../src/main/global-settings.cpp
    src/model/shortcut-model-isolated-test.cpp)
target_include_directories(shortcutModelIsolatedTest PRIVATE
    ${UKUI_SHORTCUT_INCLUDE_DIRS}
    ${GIO_INCLUDE_DIRS}
)
target_link_libraries(shortcutModelIsolatedTest
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Quick
        Qt${QT_VERSION_MAJOR}::Test
        Qt${QT_VERSION_MAJOR}::DBus
        ukui-quick::platform
        ukui-quick::framework
        ukui-quick::core
        ${EXTERNAL_LIBS}
        ${GIO_LIBRARIES}
)
add_test(NAME shortcutModelIsolatedTest COMMAND $<TARGET_FILE:shortcutModelIsolatedTest>)
