# Copyright © 2014 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authored by: Manuel de la Peña <manuel.delapena@canonical.com>

set(QML_TESTS
    test_single_download
    test_metadata
)

foreach(test ${QML_TESTS})
    # set the sources per test
    set(${test}_QML_SOURCES
            ${test}.cpp
    )

    set(${test}_QML_HEADERS
        download.h
        error.h
        manager.h
        testable_single_download.h
        ${test}.h
    )

endforeach(test)

include_directories(${DBUS_INCLUDE_DIRS})
include_directories(${GTEST_INCLUDE_DIRS})
include_directories(${GMOCK_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/common/public)
include_directories(${CMAKE_SOURCE_DIR}/src/downloads/common)
include_directories(${CMAKE_SOURCE_DIR}/src/downloads/client)
include_directories(${CMAKE_SOURCE_DIR}/src/downloads/qml)
include_directories(${CMAKE_SOURCE_DIR}/tests/common)

set(QML_TESTS_LIBS
    Qt5::Core
    Qt5::Sql
    Qt5::DBus
    Qt5::Test
    ${GMOCK_LIBRARY}
    ${GTEST_BOTH_LIBRARIES}
    ldm-common
    lomiri-download-manager-common
    lomiri-download-manager-test-lib
    LomiriDownloadManager
)

find_program(XVFB xvfb-run)

if(XVFB)
    set(XVFB_CMD xvfb-run -a -s "-screen 0 540x960x24")

    foreach(test ${QML_TESTS})
        # set targets, linked libs and test
        add_executable(${test}_qml
            ${${test}_QML_SOURCES}
            ${${test}_QML_HEADERS}
        )

        target_link_libraries(${test}_qml
            ${QML_TESTS_LIBS}
        )


    ADD_TEST(NAME qml_${test} COMMAND ${XVFB_CMD} ${CMAKE_CURRENT_BINARY_DIR}/${test}_qml)
    endforeach(test)
else(XVFB)
        message(WARNING "xvfb-run binary not found: qml tests will be disabled")
endif(XVFB)
