Skip to content

Commit

Permalink
improvement: added tests to tarball
Browse files Browse the repository at this point in the history
  • Loading branch information
BartSte committed Feb 14, 2024
1 parent 1a05992 commit f5a8259
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 21 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ jobs:
- name: Build project
run: |
./scripts/configure -- -DBUILD_TESTING=ON
cmake --build ./build
cmake --build ./build --target package
- name: Run test
run: |
ctest --test-dir ./build --verbose
- name: Run test tarball
run: |
tar -xvf ./build/snapshot-*.tar.gz -C /tmp
/tmp/snapshot-*/run_tests
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

configure_file(${CMAKE_SOURCE_DIR}/include/version.h.in
${CMAKE_SOURCE_DIR}/include/version.h @ONLY)
Expand Down
22 changes: 12 additions & 10 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_executable(snapshot_bin main.cpp ${CMAKE_SOURCE_DIR}/resources/resources.qrc)
add_executable(snapshot_bin main.cpp
${CMAKE_SOURCE_DIR}/resources/resources.qrc)
target_link_libraries(snapshot_bin PRIVATE snapshot)

install(
Expand All @@ -20,37 +21,38 @@ install(
# alongside the application in the platforms directory.
if(QT6_LIB_TYPE STREQUAL "SHARED_LIBRARY")

# TODO: use the path to Qt from the find_package command, instead of assuming
# the path to Qt is in the 3rdparty directory.
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/Qt/plugins/egldeviceintegrations/
DIRECTORY ${QT6_TOP_DIR}/plugins/egldeviceintegrations/
DESTINATION egldeviceintegrations
PATTERN "libqeglfs-.*")

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/Qt/plugins/platforms/
DIRECTORY ${QT6_TOP_DIR}/plugins/platforms/
DESTINATION platforms
PATTERN "libqwayland-.*"
PATTERN "libqxcb.*"
PATTERN "libqminimal.*"
PATTERN "libqoffscreen.*")

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/Qt/plugins/imageformats/
DIRECTORY ${QT6_TOP_DIR}/plugins/imageformats/
DESTINATION imageformats
PATTERN "libqjpeg\\..*")

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/Qt/plugins/multimedia/
DIRECTORY ${QT6_TOP_DIR}/plugins/multimedia/
DESTINATION multimedia
PATTERN "libffmpegmediaplugin\\..*")

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/Qt/plugins/tls/
DIRECTORY ${QT6_TOP_DIR}/plugins/tls/
DESTINATION tls
PATTERN "libqopenssl\\..*")

install(
DIRECTORY
${CMAKE_SOURCE_DIR}/3rdparty/Qt/plugins/wayland-graphics-integration-client/
DIRECTORY ${QT6_TOP_DIR}/plugins/wayland-graphics-integration-client/
DESTINATION wayland-graphics-integration-client
PATTERN "libqt-plugin-wayland-egl.*"
PATTERN "libdmabuf-server\\..*"
Expand All @@ -60,14 +62,14 @@ if(QT6_LIB_TYPE STREQUAL "SHARED_LIBRARY")
PATTERN "libvulkan-server\\..*")

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/Qt/plugins/wayland-shell-integration/
DIRECTORY ${QT6_TOP_DIR}/plugins/wayland-shell-integration/
DESTINATION wayland-shell-integration
PATTERN ".*-shell\\..*"
PATTERN ".*-shell-v1\\..*"
PATTERN ".*-shell-plugin\\..*")

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/Qt/plugins/xcbglintegrations/
DIRECTORY ${QT6_TOP_DIR}/plugins/xcbglintegrations/
DESTINATION xcbglintegrations
PATTERN "libqxcb-.*-integration\\.*")

Expand Down
19 changes: 19 additions & 0 deletions scripts/run_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/env bash

source=${BASH_SOURCE[0]}
# resolve $source until the file is no longer a symlink
while [ -L "$source" ]; do
this_dir=$(cd -P "$(dirname "$source")" >/dev/null 2>&1 && pwd)
source=$(readlink "$source")

# if $source was a relative symlink, we need to resolve it relative to
# the path where the symlink file was located
[[ $source != /* ]] && source=$this_dir/$source
done
this_dir=$(cd -P "$(dirname "$source")" >/dev/null 2>&1 && pwd)

LD_LIBRARY_PATH="$this_dir"
export LD_LIBRARY_PATH
export QT_QPA_PLATFORM=offscreen
"$this_dir/tests_bin" "$@"

8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ find_package(Qt6 REQUIRED COMPONENTS Widgets Multimedia MultimediaWidgets
get_target_property(QT6_LIB_TYPE Qt6::Widgets TYPE)
set(QT6_LIB_TYPE
${QT6_LIB_TYPE}
PARENT_SCOPE)
CACHE STRING "Type of the Qt6 library (STATIC_LIBRARY or SHARED_LIBRARY)")

set(_qt6_top_dir_relative "${Qt6_DIR}/../../../")
cmake_path(NORMAL_PATH _qt6_top_dir_relative OUTPUT_VARIABLE _qt6_top_dir)
set(QT6_TOP_DIR "${_qt6_top_dir}" CACHE PATH "Qt6 top directory")

message(STATUS "Qt6 was found at ${Qt6_DIR}")
message(STATUS "Qt6 its top directory is ${QT6_TOP_DIR}")
message(STATUS "Qt6 library type is ${QT6_LIB_TYPE}")
message(STATUS "FFmpeg libraries are: ${FFMPEG_LIBRARIES}")

Expand Down
20 changes: 15 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(googletest)

file(COPY static DESTINATION ${CMAKE_BINARY_DIR})
file(COPY static DESTINATION .)
file(GLOB_RECURSE TEST_SOURCES "*.cpp")
add_executable(tests ${TEST_SOURCES})
target_link_libraries(tests snapshot gtest gmock Qt6::Test)
add_test(NAME tests COMMAND tests)
set_tests_properties(tests PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
add_executable(tests_bin ${TEST_SOURCES})
target_link_libraries(tests_bin snapshot gtest gmock Qt6::Test)
add_test(NAME tests_bin COMMAND tests_bin)
set_tests_properties(tests_bin PROPERTIES ENVIRONMENT
"QT_QPA_PLATFORM=offscreen")

install(TARGETS tests_bin DESTINATION .)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/scripts/run_tests DESTINATION .)
install(DIRECTORY static DESTINATION .)

# When Qt is built as a shared library, the Qt6::Test must be added as well.
if(QT6_LIB_TYPE STREQUAL "SHARED_LIBRARY")
install(FILES $<TARGET_FILE:Qt6::Test> DESTINATION .)
endif()
2 changes: 1 addition & 1 deletion tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using path = std::filesystem::path;

extern const path static_dir(Path::program_location().parent_path() / "static");
extern const path static_dir(Path::program_location() / "static");
extern const path config_test(static_dir / "config_test.json");
extern const path debug_video(static_dir / "sample.mp4");

Expand Down

0 comments on commit f5a8259

Please sign in to comment.