# SPDX-License-Identifier: BSD-3-Clause

include(ECMAddTests)

find_package(Qt6 ${QT6_MIN_VERSION} REQUIRED COMPONENTS Test)
find_package(Qt6 ${QT6_MIN_VERSION} REQUIRED COMPONENTS CanvasPainter)

ecm_add_test(pdfpagemodeltest.cpp ../src/pdfannotationtype.h ../src/pdfannotationmodel.cpp ../src/pdfannotationgeometry.cpp ../src/pdfannotationselectionmodel.cpp ../src/pdfannotationcoordinate.cpp ../src/pdfannotationserializer.cpp ../src/pdfannotationitem.cpp ../src/pdfpagetransform.cpp ../src/pdfcommands.cpp ../src/pdfpagemodel.cpp
    TEST_NAME pdfpagemodeltest
    LINK_LIBRARIES Qt6::Core Qt6::Gui Qt6::Qml Qt6::Test Qt6::Quick Qt6::CanvasPainter Poppler::Qt6 qpdf::libqpdf imprint_commands)
target_include_directories(pdfpagemodeltest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../src)

ecm_add_test(pdfannotationcoordinatetest.cpp ../src/pdfannotationcoordinate.cpp
    TEST_NAME pdfannotationcoordinatetest
    LINK_LIBRARIES Qt6::Core Qt6::Gui Qt6::Test)
target_include_directories(pdfannotationcoordinatetest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../src)

ecm_add_test(pdfannotationserializertest.cpp ../src/pdfannotationtype.h ../src/pdfannotationserializer.cpp ../src/pdfannotationmodel.cpp ../src/pdfannotationgeometry.cpp ../src/pdfannotationcoordinate.cpp
    TEST_NAME pdfannotationserializertest
    LINK_LIBRARIES Qt6::Core Qt6::Gui Qt6::Qml Qt6::Test qpdf::libqpdf)
target_include_directories(pdfannotationserializertest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../src)

ecm_add_test(pdfannotationitemtest.cpp ../src/pdfannotationtype.h ../src/pdfannotationitem.cpp ../src/pdfannotationmodel.cpp ../src/pdfannotationgeometry.cpp ../src/pdfpagetransform.cpp
    TEST_NAME pdfannotationitemtest
    LINK_LIBRARIES Qt6::Core Qt6::Gui Qt6::Qml Qt6::Quick Qt6::Test Qt6::CanvasPainter)
target_include_directories(pdfannotationitemtest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../src)
set_tests_properties(pdfannotationitemtest PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")

add_test(NAME imprint-self-test COMMAND $<TARGET_FILE:imprint> --self-test)
set_tests_properties(imprint-self-test PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen;QT_QUICK_CONTROLS_STYLE=Basic;QML2_IMPORT_PATH=${CMAKE_INSTALL_FULL_LIBDIR}/qml")

ecm_add_test(pdfpagetransformtest.cpp ../src/pdfpagetransform.cpp
    TEST_NAME pdfpagetransformtest
    LINK_LIBRARIES Qt6::Core Qt6::Gui Qt6::Qml Qt6::Test)
target_include_directories(pdfpagetransformtest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../src)

ecm_add_test(pagepreviewqmltest.cpp
    TEST_NAME pagepreviewqmltest
    LINK_LIBRARIES imprint_static imprint_staticplugin Qt6::Core Qt6::Gui Qt6::Qml Qt6::Quick Qt6::Test Qt6::CanvasPainter Poppler::Qt6 qpdf::libqpdf imprint_commands)
target_include_directories(pagepreviewqmltest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../src)
set_tests_properties(pagepreviewqmltest PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen;QT_QUICK_CONTROLS_STYLE=Basic;QML2_IMPORT_PATH=${CMAKE_INSTALL_FULL_LIBDIR}/qml")
