foreach(name persistence database backup models)
    add_executable(test_${name} test_${name}.cpp)
    target_link_libraries(test_${name} PRIVATE signal-storage Qt5::Core)
    target_compile_options(test_${name} PRIVATE -Wall -Wextra -Wpedantic)
    add_test(NAME ${name} COMMAND test_${name})
endforeach()

# Compile the production engine and run the actual launcher against a fake
# Java entry point. No Signal account, upstream runtime, Lomiri or network needed.
add_executable(test_engine test_engine.cpp ../src/Engine.cpp)
target_link_libraries(test_engine PRIVATE signal-storage Qt5::Core)
target_compile_options(test_engine PRIVATE -Wall -Wextra -Wpedantic)
target_compile_definitions(test_engine PRIVATE
   SIGNAL_BUILD_ENGINE_DIR="${CMAKE_CURRENT_BINARY_DIR}/runtime-fixture"
   SIGNAL_LAUNCHER_SOURCE="${CMAKE_SOURCE_DIR}/tools/run-signal-cli"
)
add_test(NAME engine COMMAND test_engine)
set_tests_properties(engine PROPERTIES TIMEOUT 30)

# Production publication state tests do not require Qt or a live Signal account.
find_package(Threads REQUIRED)
add_executable(test_qr_state test_qr_state.cpp)
target_include_directories(test_qr_state PRIVATE ../src)
target_link_libraries(test_qr_state PRIVATE Threads::Threads)
target_compile_options(test_qr_state PRIVATE -Wall -Wextra -Wpedantic)
foreach(case initial publish-before-notify legacy-reproduction replace cancel snapshot-isolation reentrant utf8 shared-lifetime concurrent)
   add_test(NAME qr-state-${case} COMMAND test_qr_state ${case})
   set_tests_properties(qr-state-${case} PROPERTIES TIMEOUT 15)
endforeach()

# Real Qt Quick Image / production image provider / production QR component.
# Deliberately required, not silently skipped by a successful native test run.
find_package(Qt5 5.15 REQUIRED COMPONENTS Gui Qml Quick)
find_library(QRENCODE_TEST_LIBRARY NAMES qrencode REQUIRED)
add_executable(test_qr test_qr.cpp ../src/QrProvider.cpp ../src/QrProvider.h)
target_include_directories(test_qr PRIVATE ../src)
target_link_libraries(test_qr PRIVATE Qt5::Gui Qt5::Qml Qt5::Quick ${QRENCODE_TEST_LIBRARY} Threads::Threads)
target_compile_options(test_qr PRIVATE -Wall -Wextra -Wpedantic)
target_compile_definitions(test_qr PRIVATE SIGNAL_QR_QML_FIXTURE="${CMAKE_CURRENT_SOURCE_DIR}/QrFixture.qml")
add_test(NAME qr-qml COMMAND test_qr)
set_tests_properties(qr-qml PROPERTIES TIMEOUT 30 ENVIRONMENT "QT_QPA_PLATFORM=offscreen;QT_QUICK_BACKEND=software")
