add_definitions(-DTESTDATADIR=\"${TESTDATADIR}\")

include_directories(
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}/../src
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}/../src
)

macro(QT6_ADD_SIMPLETEST exe source)
  string(REPLACE "-" "" test_name ${exe})
  set(${test_name}_SOURCES
    ${source}
  )
  poppler_add_test(${exe} BUILD_QT6_TESTS ${${test_name}_SOURCES})
  target_link_libraries(${exe} poppler-qt6 Qt6::Widgets)
endmacro()

macro(QT6_ADD_QTEST exe source)
    string(REPLACE "-" "" test_name ${exe})
    set(${test_name}_SOURCES
      ${source}
    )
    poppler_add_test(${exe} BUILD_QT6_TESTS ${${test_name}_SOURCES})
    if(BUILD_QT6_TESTS)
      add_test(${exe} ${EXECUTABLE_OUTPUT_PATH}/${exe})
    endif()
    target_link_libraries(${exe} poppler-qt6 Qt6::Widgets Qt6::Test Qt6::Gui)
endmacro()

macro(QT_ADD_FUZZER exe)
  string(REPLACE "-" "" test_name ${exe})
  set(${test_name}_SOURCES
    ${ARGN}
  )
  poppler_add_test(${exe} BUILD_QT6_TESTS ${${test_name}_SOURCES})
  target_link_libraries(${exe} poppler-qt6 Qt6::Widgets Qt6::Test Qt6::Core Qt6::Gui)
endmacro(QT_ADD_FUZZER)

qt6_add_simpletest(test-poppler-qt6 test-poppler-qt6.cpp)
qt6_add_simpletest(test-password-qt6 test-password-qt6.cpp)
qt6_add_simpletest(test-render-to-file-qt6 test-render-to-file.cpp)
qt6_add_simpletest(poppler-qt6-forms poppler-forms.cpp)
qt6_add_simpletest(poppler-qt6-fonts poppler-fonts.cpp)
qt6_add_simpletest(poppler-qt6-attachments poppler-attachments.cpp)
qt6_add_simpletest(stress-poppler-qt6 stress-poppler-qt6.cpp)
qt6_add_simpletest(stress-poppler-dir-qt6 stress-poppler-dir.cpp)
qt6_add_simpletest(stress-threads-qt6 stress-threads-qt6.cpp)
qt6_add_simpletest(poppler-qt6-texts poppler-texts.cpp)
qt6_add_simpletest(poppler-qt6-page-labels poppler-page-labels.cpp)

qt6_add_qtest(check_qt6_attachments check_attachments.cpp)
qt6_add_qtest(check_qt6_dateConversion check_dateConversion.cpp)
qt6_add_qtest(check_qt6_fonts check_fonts.cpp)
qt6_add_qtest(check_qt6_links check_links.cpp)
qt6_add_qtest(check_qt6_annotations check_annotations.cpp)
qt6_add_qtest(check_qt6_metadata check_metadata.cpp)
qt6_add_qtest(check_qt6_optcontent check_optcontent.cpp)
qt6_add_qtest(check_qt6_forms check_forms.cpp)
qt6_add_qtest(check_qt6_pagelayout check_pagelayout.cpp)
qt6_add_qtest(check_qt6_pagemode check_pagemode.cpp)
qt6_add_qtest(check_qt6_password check_password.cpp)
qt6_add_qtest(check_qt6_permissions check_permissions.cpp)
qt6_add_qtest(check_qt6_search check_search.cpp)
qt6_add_qtest(check_qt6_actualtext check_actualtext.cpp)
qt6_add_qtest(check_qt6_lexer check_lexer.cpp)
qt6_add_qtest(check_qt6_internal_outline check_internal_outline.cpp)
qt6_add_qtest(check_qt6_goostring check_goostring.cpp)
qt6_add_qtest(check_qt6_object check_object.cpp)
qt6_add_qtest(check_qt6_stroke_opacity check_stroke_opacity.cpp)
qt6_add_qtest(check_qt6_utf_conversion check_utf_conversion.cpp)
qt6_add_qtest(check_qt6_outline check_outline.cpp)
qt6_add_qtest(check_qt6_signature_basics check_signature_basics.cpp)
qt6_add_qtest(check_qt6_signature_basics_pgp check_signature_basics_pgp.cpp)
qt6_add_qtest(check_qt6_utf8document check_utf8document.cpp)
qt6_add_qtest(check_qt6_distinguished_name_parser check_distinguished_name_parser.cpp)
qt6_add_qtest(check_qt6_cidfontswidthsbuilder check_cidfontswidthsbuilder.cpp)
qt6_add_qtest(check_qt6_overprint check_overprint.cpp)
qt6_add_qtest(check_qt6_endoflines check_endoflines.cpp)
if (ENABLE_GPGME)
  target_link_libraries(check_qt6_signature_basics Gpgmepp)
  target_link_libraries(check_qt6_signature_basics_pgp Gpgmepp)
  qt6_add_qtest(check_qt6_untrusted_signature check_untrusted_signature.cpp)
  target_link_libraries(check_qt6_untrusted_signature Gpgmepp)
  qt6_add_qtest(check_qt6_untrusted_signature_keylist check_untrusted_signature_keylist.cpp)
  target_link_libraries(check_qt6_untrusted_signature_keylist Gpgmepp)
  qt6_add_qtest(check_create_pgp_signature1 check_create_pgp_signature1.cpp)
  target_link_libraries(check_create_pgp_signature1 Gpgmepp)
  if (ENABLE_NSS3)
  target_link_libraries(check_create_pgp_signature1 PkgConfig::NSS3)
  qt6_add_qtest(check_qt6_signature_cross_validation check_signature_cross_validation.cpp)
  target_link_libraries(check_qt6_signature_cross_validation PkgConfig::NSS3)
  target_link_libraries(check_qt6_signature_cross_validation Gpgmepp)
  endif()
endif()
if (NOT WIN32)
  qt6_add_qtest(check_qt6_pagelabelinfo check_pagelabelinfo.cpp)
  qt6_add_qtest(check_qt6_strings check_strings.cpp)
endif ()

if(ENABLE_FUZZER)
    qt_add_fuzzer(qt_annot_fuzzer ./fuzzing/qt_annot_fuzzer.cc)
    qt_add_fuzzer(qt_pdf_fuzzer ./fuzzing/qt_pdf_fuzzer.cc)
    qt_add_fuzzer(qt_label_fuzzer ./fuzzing/qt_label_fuzzer.cc)
    qt_add_fuzzer(qt_search_fuzzer ./fuzzing/qt_search_fuzzer.cc)
    qt_add_fuzzer(qt_textbox_fuzzer ./fuzzing/qt_textbox_fuzzer.cc)
    qt_add_fuzzer(qt_signature_fuzzer ./fuzzing/qt_signature_fuzzer.cc)
endif()
