2022-07-18 06:18:40 +08:00
|
|
|
include(FetchContent)
|
|
|
|
|
2022-09-19 05:24:42 +08:00
|
|
|
add_subdirectory(install)
|
2022-10-27 06:42:44 +08:00
|
|
|
set_target_warnings(test-sfml-install)
|
2022-09-19 05:24:42 +08:00
|
|
|
|
2023-05-16 06:02:45 +08:00
|
|
|
set(CATCH_CONFIG_FAST_COMPILE ON CACHE BOOL "")
|
2023-07-13 22:09:06 +08:00
|
|
|
set(CATCH_CONFIG_NO_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT ON CACHE BOOL "")
|
2023-01-18 12:51:08 +08:00
|
|
|
FetchContent_Declare(Catch2
|
|
|
|
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
2024-05-06 03:13:12 +08:00
|
|
|
GIT_TAG v3.6.0
|
2023-09-15 12:35:12 +08:00
|
|
|
GIT_SHALLOW ON)
|
2023-01-18 12:51:08 +08:00
|
|
|
FetchContent_MakeAvailable(Catch2)
|
|
|
|
include(Catch)
|
|
|
|
|
|
|
|
# Build Catch2 in C++17 mode to enable C++17 features
|
|
|
|
target_compile_features(Catch2 PRIVATE cxx_std_17)
|
|
|
|
|
|
|
|
# Ensure that Catch2 sources and headers are not analyzed by any tools
|
|
|
|
set_target_properties(Catch2 PROPERTIES COMPILE_OPTIONS "" EXPORT_COMPILE_COMMANDS OFF)
|
|
|
|
set_target_properties(Catch2WithMain PROPERTIES EXPORT_COMPILE_COMMANDS OFF)
|
|
|
|
get_target_property(CATCH2_INCLUDE_DIRS Catch2 INTERFACE_INCLUDE_DIRECTORIES)
|
|
|
|
target_include_directories(Catch2 SYSTEM INTERFACE ${CATCH2_INCLUDE_DIRS})
|
|
|
|
|
2022-01-21 12:00:36 +08:00
|
|
|
add_library(sfml-test-main STATIC
|
|
|
|
TestUtilities/SystemUtil.hpp
|
|
|
|
TestUtilities/SystemUtil.cpp
|
|
|
|
TestUtilities/WindowUtil.hpp
|
|
|
|
TestUtilities/WindowUtil.cpp
|
|
|
|
TestUtilities/GraphicsUtil.hpp
|
|
|
|
TestUtilities/GraphicsUtil.cpp
|
2023-04-16 10:50:24 +08:00
|
|
|
TestUtilities/AudioUtil.hpp
|
|
|
|
TestUtilities/AudioUtil.cpp
|
2022-01-21 12:00:36 +08:00
|
|
|
)
|
2022-02-28 12:37:24 +08:00
|
|
|
target_include_directories(sfml-test-main PUBLIC TestUtilities)
|
2023-01-18 12:51:08 +08:00
|
|
|
target_link_libraries(sfml-test-main PUBLIC SFML::System Catch2::Catch2WithMain)
|
2022-05-05 01:11:07 +08:00
|
|
|
set_target_warnings(sfml-test-main)
|
2018-08-19 07:30:53 +08:00
|
|
|
|
2023-10-03 11:52:40 +08:00
|
|
|
# set the target flags to use the appropriate C++ standard library
|
|
|
|
sfml_set_stdlib(Catch2)
|
|
|
|
sfml_set_stdlib(Catch2WithMain)
|
|
|
|
sfml_set_stdlib(sfml-test-main)
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
sfml_set_option(SFML_RUN_DISPLAY_TESTS ON BOOL "TRUE to run tests that require a display, FALSE to ignore it")
|
|
|
|
if(SFML_RUN_DISPLAY_TESTS)
|
|
|
|
target_compile_definitions(sfml-test-main PRIVATE SFML_RUN_DISPLAY_TESTS)
|
|
|
|
endif()
|
|
|
|
|
2023-04-16 10:50:24 +08:00
|
|
|
sfml_set_option(SFML_RUN_AUDIO_DEVICE_TESTS ON BOOL "TRUE to run tests that require an audio device, FALSE to ignore it")
|
|
|
|
if(SFML_RUN_AUDIO_DEVICE_TESTS)
|
|
|
|
target_compile_definitions(sfml-test-main PRIVATE SFML_RUN_AUDIO_DEVICE_TESTS)
|
|
|
|
endif()
|
|
|
|
|
2022-08-07 14:06:13 +08:00
|
|
|
set(SYSTEM_SRC
|
2022-10-11 15:29:34 +08:00
|
|
|
System/Angle.test.cpp
|
|
|
|
System/Clock.test.cpp
|
|
|
|
System/Config.test.cpp
|
|
|
|
System/FileInputStream.test.cpp
|
|
|
|
System/MemoryInputStream.test.cpp
|
2023-04-20 01:49:41 +08:00
|
|
|
System/Sleep.test.cpp
|
2022-10-11 15:29:34 +08:00
|
|
|
System/String.test.cpp
|
|
|
|
System/Time.test.cpp
|
|
|
|
System/Vector2.test.cpp
|
|
|
|
System/Vector3.test.cpp
|
2015-04-29 03:54:03 +08:00
|
|
|
)
|
2023-10-09 13:13:48 +08:00
|
|
|
sfml_add_test(test-sfml-system "${SYSTEM_SRC}" "")
|
2022-07-12 12:56:57 +08:00
|
|
|
target_compile_definitions(test-sfml-system PRIVATE
|
|
|
|
EXPECTED_SFML_VERSION_MAJOR=${SFML_VERSION_MAJOR}
|
|
|
|
EXPECTED_SFML_VERSION_MINOR=${SFML_VERSION_MINOR}
|
|
|
|
EXPECTED_SFML_VERSION_PATCH=${SFML_VERSION_PATCH}
|
|
|
|
EXPECTED_SFML_VERSION_IS_RELEASE=$<IF:$<BOOL:${VERSION_IS_RELEASE}>,true,false>
|
|
|
|
)
|
2015-04-29 03:54:03 +08:00
|
|
|
|
2022-08-07 14:06:13 +08:00
|
|
|
set(WINDOW_SRC
|
2023-09-02 13:06:32 +08:00
|
|
|
Window/Clipboard.test.cpp
|
2022-10-11 15:29:34 +08:00
|
|
|
Window/Context.test.cpp
|
|
|
|
Window/ContextSettings.test.cpp
|
|
|
|
Window/Cursor.test.cpp
|
2024-07-11 04:01:59 +08:00
|
|
|
Window/Err.test.cpp # Tested alongside Window module because the System module performs no logging
|
2023-08-23 13:39:44 +08:00
|
|
|
Window/Event.test.cpp
|
2022-10-11 15:29:34 +08:00
|
|
|
Window/GlResource.test.cpp
|
2023-09-24 09:22:30 +08:00
|
|
|
Window/Joystick.test.cpp
|
2023-09-02 12:56:00 +08:00
|
|
|
Window/Keyboard.test.cpp
|
2022-10-11 15:29:34 +08:00
|
|
|
Window/VideoMode.test.cpp
|
2023-09-25 07:34:31 +08:00
|
|
|
Window/Vulkan.test.cpp
|
2022-10-11 15:29:34 +08:00
|
|
|
Window/Window.test.cpp
|
|
|
|
Window/WindowBase.test.cpp
|
2022-03-25 01:49:00 +08:00
|
|
|
)
|
|
|
|
sfml_add_test(test-sfml-window "${WINDOW_SRC}" SFML::Window)
|
2018-08-19 07:30:53 +08:00
|
|
|
|
2022-08-07 14:06:13 +08:00
|
|
|
set(GRAPHICS_SRC
|
2022-10-11 15:29:34 +08:00
|
|
|
Graphics/BlendMode.test.cpp
|
|
|
|
Graphics/CircleShape.test.cpp
|
|
|
|
Graphics/Color.test.cpp
|
|
|
|
Graphics/ConvexShape.test.cpp
|
2021-07-04 14:47:48 +08:00
|
|
|
Graphics/CoordinateType.test.cpp
|
2022-10-11 15:29:34 +08:00
|
|
|
Graphics/Drawable.test.cpp
|
|
|
|
Graphics/Font.test.cpp
|
2024-04-08 08:12:20 +08:00
|
|
|
Graphics/Glsl.test.cpp
|
2022-10-11 15:29:34 +08:00
|
|
|
Graphics/Glyph.test.cpp
|
|
|
|
Graphics/Image.test.cpp
|
|
|
|
Graphics/Rect.test.cpp
|
|
|
|
Graphics/RectangleShape.test.cpp
|
2015-04-29 11:28:02 +08:00
|
|
|
Graphics/Render.test.cpp
|
2022-10-11 15:29:34 +08:00
|
|
|
Graphics/RenderStates.test.cpp
|
|
|
|
Graphics/RenderTarget.test.cpp
|
|
|
|
Graphics/RenderTexture.test.cpp
|
|
|
|
Graphics/RenderWindow.test.cpp
|
|
|
|
Graphics/Shader.test.cpp
|
|
|
|
Graphics/Shape.test.cpp
|
|
|
|
Graphics/Sprite.test.cpp
|
2015-04-29 11:28:02 +08:00
|
|
|
Graphics/StencilMode.test.cpp
|
2022-10-11 15:29:34 +08:00
|
|
|
Graphics/Text.test.cpp
|
|
|
|
Graphics/Texture.test.cpp
|
|
|
|
Graphics/Transform.test.cpp
|
|
|
|
Graphics/Transformable.test.cpp
|
|
|
|
Graphics/Vertex.test.cpp
|
|
|
|
Graphics/VertexArray.test.cpp
|
|
|
|
Graphics/VertexBuffer.test.cpp
|
|
|
|
Graphics/View.test.cpp
|
2022-03-25 01:49:00 +08:00
|
|
|
)
|
|
|
|
sfml_add_test(test-sfml-graphics "${GRAPHICS_SRC}" SFML::Graphics)
|
2022-12-27 12:30:18 +08:00
|
|
|
if(SFML_RUN_DISPLAY_TESTS)
|
|
|
|
target_compile_definitions(test-sfml-graphics PRIVATE SFML_RUN_DISPLAY_TESTS)
|
|
|
|
endif()
|
2018-08-19 07:30:53 +08:00
|
|
|
|
2022-08-07 14:06:13 +08:00
|
|
|
set(NETWORK_SRC
|
2022-10-11 15:29:34 +08:00
|
|
|
Network/Ftp.test.cpp
|
|
|
|
Network/Http.test.cpp
|
|
|
|
Network/IpAddress.test.cpp
|
|
|
|
Network/Packet.test.cpp
|
|
|
|
Network/Socket.test.cpp
|
|
|
|
Network/SocketSelector.test.cpp
|
|
|
|
Network/TcpListener.test.cpp
|
|
|
|
Network/TcpSocket.test.cpp
|
|
|
|
Network/UdpSocket.test.cpp
|
2022-03-25 01:49:00 +08:00
|
|
|
)
|
|
|
|
sfml_add_test(test-sfml-network "${NETWORK_SRC}" SFML::Network)
|
2021-12-06 06:27:48 +08:00
|
|
|
|
2022-08-07 14:06:13 +08:00
|
|
|
set(AUDIO_SRC
|
2023-04-16 22:12:31 +08:00
|
|
|
Audio/AudioResource.test.cpp
|
2022-10-11 15:29:34 +08:00
|
|
|
Audio/InputSoundFile.test.cpp
|
|
|
|
Audio/Music.test.cpp
|
|
|
|
Audio/OutputSoundFile.test.cpp
|
|
|
|
Audio/Sound.test.cpp
|
|
|
|
Audio/SoundBuffer.test.cpp
|
|
|
|
Audio/SoundBufferRecorder.test.cpp
|
2023-11-27 06:31:42 +08:00
|
|
|
Audio/SoundFileFactory.test.cpp
|
2024-04-17 04:55:52 +08:00
|
|
|
Audio/SoundFileReader.test.cpp
|
2024-04-17 05:02:16 +08:00
|
|
|
Audio/SoundFileWriter.test.cpp
|
2022-10-11 15:29:34 +08:00
|
|
|
Audio/SoundRecorder.test.cpp
|
|
|
|
Audio/SoundSource.test.cpp
|
|
|
|
Audio/SoundStream.test.cpp
|
2022-03-25 01:49:00 +08:00
|
|
|
)
|
|
|
|
sfml_add_test(test-sfml-audio "${AUDIO_SRC}" SFML::Audio)
|
2022-02-06 12:38:28 +08:00
|
|
|
|
2024-04-14 07:23:36 +08:00
|
|
|
if(SFML_OS_ANDROID AND DEFINED ENV{LIBCXX_SHARED_SO})
|
|
|
|
# Because we can only write to the tmp directory on the Android virtual device we will need to build our directory tree under it
|
|
|
|
set(TARGET_DIR "/data/local/tmp/$<TARGET_FILE_DIR:test-sfml-system>")
|
|
|
|
|
|
|
|
# Generate script that copies necessary files over to the Android virtual device
|
|
|
|
file(GENERATE OUTPUT "${PROJECT_BINARY_DIR}/prepare-android-files.sh" CONTENT
|
|
|
|
"#!/bin/bash\n\
|
|
|
|
adb shell \"mkdir -p ${TARGET_DIR}\"\n\
|
|
|
|
adb push $<TARGET_FILE:test-sfml-audio> ${TARGET_DIR}\n\
|
|
|
|
adb push $<TARGET_FILE:test-sfml-graphics> ${TARGET_DIR}\n\
|
|
|
|
adb push $<TARGET_FILE:test-sfml-network> ${TARGET_DIR}\n\
|
|
|
|
adb push $<TARGET_FILE:test-sfml-system> ${TARGET_DIR}\n\
|
|
|
|
adb push $<TARGET_FILE:test-sfml-window> ${TARGET_DIR}\n\
|
|
|
|
adb push $<TARGET_FILE:SFML::Audio> ${TARGET_DIR}\n\
|
|
|
|
adb push $<TARGET_FILE:SFML::Graphics> ${TARGET_DIR}\n\
|
|
|
|
adb push $<TARGET_FILE:SFML::Network> ${TARGET_DIR}\n\
|
|
|
|
adb push $<TARGET_FILE:SFML::System> ${TARGET_DIR}\n\
|
|
|
|
adb push $<TARGET_FILE:SFML::Window> ${TARGET_DIR}\n\
|
|
|
|
adb push $<TARGET_FILE:Catch2> ${TARGET_DIR}\n\
|
|
|
|
adb push $<TARGET_FILE:Catch2WithMain> ${TARGET_DIR}\n\
|
|
|
|
adb push $ENV{LIBCXX_SHARED_SO} ${TARGET_DIR}\n\
|
|
|
|
adb push ${CMAKE_CURRENT_LIST_DIR} ${TARGET_DIR}\n\
|
|
|
|
adb shell \"chmod -R 775 ${TARGET_DIR} && ls -la ${TARGET_DIR}\"\n"
|
|
|
|
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
|
|
|
|
|
|
|
|
# Add the target to invoke the file copy script
|
|
|
|
add_custom_target(prepare-android-files COMMAND "${PROJECT_BINARY_DIR}/prepare-android-files.sh")
|
|
|
|
|
|
|
|
# Generate proxy script that translates CTest commands into adb shell commands
|
|
|
|
file(GENERATE OUTPUT "${PROJECT_BINARY_DIR}/run-in-adb-shell.sh" CONTENT
|
|
|
|
"#!/bin/bash\n\
|
|
|
|
adb shell \"cd ${TARGET_DIR}/test; LD_LIBRARY_PATH=${TARGET_DIR} /data/local/tmp/$1 \\\"$2\\\" \\\"$3\\\" \\\"$4\\\" \\\"$5\\\" \\\"$6\\\" \\\"$7\\\" \\\"$8\\\" \\\"$9\\\"\"\n"
|
|
|
|
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
|
|
|
|
endif()
|
|
|
|
|
2024-04-12 02:54:19 +08:00
|
|
|
if(SFML_ENABLE_COVERAGE AND SFML_OS_WINDOWS AND NOT SFML_COMPILER_GCC)
|
2022-02-06 12:38:28 +08:00
|
|
|
# Try to find and use OpenCppCoverage for coverage reporting when building with MSVC
|
|
|
|
find_program(OpenCppCoverage_BINARY "OpenCppCoverage.exe")
|
|
|
|
|
|
|
|
if(OpenCppCoverage_BINARY)
|
|
|
|
execute_process(COMMAND "${OpenCppCoverage_BINARY}" --help ERROR_VARIABLE OpenCppCoverage_HELP_OUTPUT OUTPUT_QUIET)
|
|
|
|
|
|
|
|
if(OpenCppCoverage_HELP_OUTPUT MATCHES "OpenCppCoverage Version: ([.0-9]+)")
|
|
|
|
set(OpenCppCoverage_VERSION "${CMAKE_MATCH_1}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
|
|
|
|
find_package_handle_standard_args(OpenCppCoverage
|
|
|
|
REQUIRED_VARS OpenCppCoverage_BINARY
|
|
|
|
VERSION_VAR OpenCppCoverage_VERSION
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(SFML_ENABLE_COVERAGE AND OpenCppCoverage_FOUND)
|
|
|
|
# Use OpenCppCoverage
|
|
|
|
message(STATUS "Using OpenCppCoverage to generate coverage report")
|
|
|
|
|
|
|
|
string(REPLACE "/" "\\" COVERAGE_EXCLUDE "${CMAKE_CTEST_COMMAND}")
|
|
|
|
string(REPLACE "/" "\\" COVERAGE_SRC "${PROJECT_SOURCE_DIR}/src")
|
|
|
|
string(REPLACE "/" "\\" COVERAGE_INCLUDE "${PROJECT_SOURCE_DIR}/include")
|
|
|
|
|
2024-04-11 03:37:45 +08:00
|
|
|
# We need to patch the OpenCppCoverage output to remove path prefixes so Coveralls doesn't get confused
|
|
|
|
cmake_path(GET PROJECT_SOURCE_DIR ROOT_NAME COVERAGE_ROOT_NAME)
|
|
|
|
string(REPLACE "/" "\\\\" COVERAGE_PATH_PREFIX "${PROJECT_SOURCE_DIR}/")
|
|
|
|
string(REPLACE "${COVERAGE_ROOT_NAME}\\\\" "" COVERAGE_PATH_PREFIX "${COVERAGE_PATH_PREFIX}")
|
|
|
|
|
|
|
|
file(WRITE "${PROJECT_BINARY_DIR}/patch_coverage.cmake"
|
|
|
|
"file(READ \"${PROJECT_BINARY_DIR}/coverage.out\" COVERAGE_OUT)\n\
|
|
|
|
string(REPLACE \"${COVERAGE_PATH_PREFIX}\" \"\" COVERAGE_OUT \"\${COVERAGE_OUT}\")\n\
|
|
|
|
string(REPLACE \"${COVERAGE_ROOT_NAME}\" \".\" COVERAGE_OUT \"\${COVERAGE_OUT}\")\n\
|
|
|
|
file(WRITE \"${PROJECT_BINARY_DIR}/coverage.out\" \"\${COVERAGE_OUT}\")\n")
|
|
|
|
|
|
|
|
set(COVERAGE_PREFIX ${OpenCppCoverage_BINARY} --quiet --export_type cobertura:${PROJECT_BINARY_DIR}/coverage.out --cover_children --excluded_modules "${COVERAGE_EXCLUDE}" --sources "${COVERAGE_SRC}" --sources "${COVERAGE_INCLUDE}" --)
|
|
|
|
else()
|
|
|
|
# On all other systems, we just run an empty script
|
|
|
|
file(WRITE "${PROJECT_BINARY_DIR}/patch_coverage.cmake" "")
|
2022-02-06 12:38:28 +08:00
|
|
|
endif()
|
2022-12-17 11:01:47 +08:00
|
|
|
|
2023-03-15 01:51:22 +08:00
|
|
|
# Convenience for building and running tests in a single command
|
|
|
|
add_custom_target(runtests DEPENDS test-sfml-system test-sfml-window test-sfml-graphics test-sfml-network test-sfml-audio)
|
2022-12-17 11:01:47 +08:00
|
|
|
add_custom_command(TARGET runtests
|
|
|
|
COMMENT "Run tests"
|
2024-04-11 03:37:45 +08:00
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${COVERAGE_PREFIX} ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>
|
|
|
|
COMMAND ${CMAKE_COMMAND} -P "${PROJECT_BINARY_DIR}/patch_coverage.cmake"
|
2022-12-17 11:01:47 +08:00
|
|
|
VERBATIM)
|