if(NOT BUILD_TESTING)
     # Skip everything. Particularly trying to look for integration test deps.
    return()
endif()

remove_definitions(-DQT_NO_CAST_FROM_ASCII)

find_package(Qt5Test ${REQUIRED_QT_VERSION} CONFIG REQUIRED)

# Test helper for systeminformationtest
add_executable(lsb_release lsb_release_double.c)

ecm_add_tests(
    systeminformationtest
    LINK_LIBRARIES
        Qt5::Core
        Qt5::Test
        DrKonqiInternal
)

add_subdirectory(crashtest)
add_subdirectory(backtraceparsertest)
add_subdirectory(bugzillalibtest)

if(NOT APPLE)
    if(NOT RUBY_EXECTUABLE)
        find_program(RUBY_EXECUTABLE ruby)
    endif()
    if(RUBY_EXECUTABLE)
        execute_process(COMMAND ${RUBY_EXECUTABLE} -e "require 'atspi'"
            RESULT_VARIABLE RUBY_ATSPI)
    endif()
    if(NOT GDB_EXECUTABLE)
        # Needed so drkonqi can actually trace something.
        find_program(GDB_EXECUTABLE gdb)
    endif()
    if(NOT XVFB_RUN_EXECTUABLE)
        find_program(XVFB_RUN_EXECTUABLE xvfb-run)
    endif()

    set(ATSPI_PATHS
        /usr/lib/at-spi2-core/ # debians
        /usr/lib/at-spi2/      # suses
    )
    if(NOT ATSPI_BUS_LAUNCHER_EXECUTABLE)
        find_program(ATSPI_BUS_LAUNCHER_EXECUTABLE
            NAMES at-spi-bus-launcher
            PATHS ${ATSPI_PATHS}
            DOC "AT-SPI accessibility dbus launcher")
    endif()
    if(NOT ATSPI_REGISTRYD_EXECUTABLE)
        find_program(ATSPI_REGISTRYD_EXECUTABLE
            NAMES at-spi2-registryd
            PATHS ${ATSPI_PATHS}
            DOC "AT-SPI accessibility registry daemon")
    endif()

    if(RUBY_EXECUTABLE AND XVFB_RUN_EXECTUABLE AND ATSPI_BUS_LAUNCHER_EXECUTABLE
       AND ATSPI_REGISTRYD_EXECUTABLE AND GDB_EXECUTABLE
       AND RUBY_ATSPI EQUAL 0)
        set(WITH_DRKONI_INTEGRATION_TESTING TRUE)
        add_subdirectory(integration)
    endif()
    add_feature_info(DrKonqiIntegrationTesting WITH_DRKONI_INTEGRATION_TESTING
        "Needs Ruby, functional atspi gem, gdb, as well as xvfb-run.")
endif()
