2022-07-18 06:18:40 +08:00
|
|
|
include(FetchContent)
|
|
|
|
|
|
|
|
set(DOCTEST_NO_INSTALL ON)
|
|
|
|
FetchContent_Declare(doctest
|
|
|
|
GIT_REPOSITORY "https://github.com/doctest/doctest.git"
|
|
|
|
GIT_TAG v2.4.9
|
|
|
|
)
|
|
|
|
FetchContent_MakeAvailable(doctest)
|
2022-07-18 06:20:02 +08:00
|
|
|
list(APPEND CMAKE_MODULE_PATH ${doctest_SOURCE_DIR}/scripts/cmake)
|
|
|
|
include(doctest)
|
2022-07-18 06:18:40 +08:00
|
|
|
|
2022-09-19 05:24:42 +08:00
|
|
|
add_subdirectory(install)
|
|
|
|
|
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
|
|
|
|
)
|
2022-02-28 12:37:24 +08:00
|
|
|
target_include_directories(sfml-test-main PUBLIC TestUtilities)
|
2022-06-23 03:54:28 +08:00
|
|
|
target_compile_definitions(sfml-test-main PUBLIC DOCTEST_CONFIG_REQUIRE_STRINGIFICATION_FOR_ALL_USED_TYPES)
|
2022-10-17 03:24:28 +08:00
|
|
|
target_link_libraries(sfml-test-main PUBLIC SFML::System doctest::doctest_with_main)
|
2022-05-05 01:11:07 +08:00
|
|
|
set_target_warnings(sfml-test-main)
|
2018-08-19 07:30:53 +08:00
|
|
|
|
2022-08-07 14:06:13 +08:00
|
|
|
set(SYSTEM_SRC
|
2022-01-22 12:09:49 +08:00
|
|
|
System/Angle.cpp
|
|
|
|
System/Clock.cpp
|
2022-07-12 12:56:57 +08:00
|
|
|
System/Config.cpp
|
2022-04-22 06:00:51 +08:00
|
|
|
System/Err.cpp
|
2022-01-22 12:09:49 +08:00
|
|
|
System/FileInputStream.cpp
|
2022-06-24 09:13:55 +08:00
|
|
|
System/MemoryInputStream.cpp
|
2022-07-25 14:36:05 +08:00
|
|
|
System/String.cpp
|
2022-01-22 12:09:49 +08:00
|
|
|
System/Time.cpp
|
|
|
|
System/Vector2.cpp
|
|
|
|
System/Vector3.cpp
|
2015-04-29 03:54:03 +08:00
|
|
|
)
|
2021-12-29 13:28:50 +08:00
|
|
|
sfml_add_test(test-sfml-system "${SYSTEM_SRC}" SFML::System)
|
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
|
2022-07-25 14:36:05 +08:00
|
|
|
Window/Context.cpp
|
2022-03-25 01:49:00 +08:00
|
|
|
Window/ContextSettings.cpp
|
2022-07-25 14:36:05 +08:00
|
|
|
Window/Cursor.cpp
|
|
|
|
Window/GlResource.cpp
|
2022-03-25 01:49:00 +08:00
|
|
|
Window/VideoMode.cpp
|
2022-07-25 14:36:05 +08:00
|
|
|
Window/Window.cpp
|
|
|
|
Window/WindowBase.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-03-25 01:49:00 +08:00
|
|
|
Graphics/BlendMode.cpp
|
2022-04-09 08:52:48 +08:00
|
|
|
Graphics/CircleShape.cpp
|
2022-03-25 01:49:00 +08:00
|
|
|
Graphics/Color.cpp
|
2022-06-02 13:12:48 +08:00
|
|
|
Graphics/ConvexShape.cpp
|
2022-07-25 14:36:05 +08:00
|
|
|
Graphics/Drawable.cpp
|
|
|
|
Graphics/Font.cpp
|
2022-05-22 12:43:10 +08:00
|
|
|
Graphics/Glyph.cpp
|
2022-06-18 01:03:21 +08:00
|
|
|
Graphics/Image.cpp
|
2022-03-25 01:49:00 +08:00
|
|
|
Graphics/Rect.cpp
|
2022-04-09 08:33:50 +08:00
|
|
|
Graphics/RectangleShape.cpp
|
2022-05-26 02:36:06 +08:00
|
|
|
Graphics/RenderStates.cpp
|
2022-07-25 14:36:05 +08:00
|
|
|
Graphics/RenderTarget.cpp
|
|
|
|
Graphics/RenderTexture.cpp
|
|
|
|
Graphics/RenderWindow.cpp
|
|
|
|
Graphics/Shader.cpp
|
|
|
|
Graphics/Shape.cpp
|
|
|
|
Graphics/Sprite.cpp
|
|
|
|
Graphics/Text.cpp
|
|
|
|
Graphics/Texture.cpp
|
2022-03-25 01:49:00 +08:00
|
|
|
Graphics/Transform.cpp
|
|
|
|
Graphics/Transformable.cpp
|
|
|
|
Graphics/Vertex.cpp
|
|
|
|
Graphics/VertexArray.cpp
|
2022-07-25 14:36:05 +08:00
|
|
|
Graphics/VertexBuffer.cpp
|
2022-05-22 13:03:49 +08:00
|
|
|
Graphics/View.cpp
|
2022-03-25 01:49:00 +08:00
|
|
|
)
|
|
|
|
sfml_add_test(test-sfml-graphics "${GRAPHICS_SRC}" SFML::Graphics)
|
2018-08-19 07:30:53 +08:00
|
|
|
|
2022-08-07 14:06:13 +08:00
|
|
|
set(NETWORK_SRC
|
2022-07-25 14:36:05 +08:00
|
|
|
Network/Ftp.cpp
|
|
|
|
Network/Http.cpp
|
2022-06-18 04:57:24 +08:00
|
|
|
Network/IpAddress.cpp
|
2022-03-25 01:49:00 +08:00
|
|
|
Network/Packet.cpp
|
2022-07-25 14:36:05 +08:00
|
|
|
Network/Socket.cpp
|
|
|
|
Network/SocketSelector.cpp
|
|
|
|
Network/TcpListener.cpp
|
|
|
|
Network/TcpSocket.cpp
|
|
|
|
Network/UdpSocket.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
|
2022-07-25 14:36:05 +08:00
|
|
|
Audio/AlResource.cpp
|
|
|
|
Audio/InputSoundFile.cpp
|
|
|
|
Audio/Music.cpp
|
|
|
|
Audio/OutputSoundFile.cpp
|
|
|
|
Audio/Sound.cpp
|
|
|
|
Audio/SoundBuffer.cpp
|
|
|
|
Audio/SoundBufferRecorder.cpp
|
|
|
|
Audio/SoundRecorder.cpp
|
|
|
|
Audio/SoundSource.cpp
|
|
|
|
Audio/SoundStream.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
|
|
|
|
2022-07-18 06:20:02 +08:00
|
|
|
if(SFML_OS_WINDOWS AND NOT SFML_USE_SYSTEM_DEPS)
|
|
|
|
add_custom_command(
|
|
|
|
TARGET test-sfml-audio
|
|
|
|
COMMENT "Copy OpenAL DLL"
|
|
|
|
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/extlibs/bin/$<IF:$<BOOL:${ARCH_64BITS}>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:test-sfml-audio>
|
2022-09-15 00:42:13 +08:00
|
|
|
VERBATIM)
|
2022-07-18 06:20:02 +08:00
|
|
|
endif()
|
|
|
|
|
2018-08-20 02:04:11 +08:00
|
|
|
# Automatically run the tests at the end of the build
|
2018-08-21 05:49:56 +08:00
|
|
|
add_custom_target(runtests ALL
|
2022-02-06 12:38:28 +08:00
|
|
|
DEPENDS test-sfml-system test-sfml-window test-sfml-graphics test-sfml-network test-sfml-audio
|
2018-08-19 07:30:53 +08:00
|
|
|
)
|
2018-11-30 02:38:27 +08:00
|
|
|
|
2022-02-06 12:38:28 +08:00
|
|
|
if(SFML_ENABLE_COVERAGE AND SFML_COMPILER_MSVC)
|
|
|
|
# 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")
|
|
|
|
|
|
|
|
add_custom_command(TARGET runtests
|
|
|
|
COMMENT "Run tests"
|
2022-09-15 00:42:13 +08:00
|
|
|
POST_BUILD COMMAND "${OpenCppCoverage_BINARY}" ARGS --quiet --export_type cobertura:${PROJECT_BINARY_DIR}/coverage.out --cover_children --excluded_modules "${COVERAGE_EXCLUDE}" --sources "${COVERAGE_SRC}" --sources "${COVERAGE_INCLUDE}" -- "${CMAKE_CTEST_COMMAND}" --output-on-failure -C $<CONFIG>
|
|
|
|
VERBATIM)
|
2022-02-06 12:38:28 +08:00
|
|
|
else()
|
|
|
|
# Run tests without a coverage runner
|
|
|
|
add_custom_command(TARGET runtests
|
|
|
|
COMMENT "Run tests"
|
|
|
|
POST_BUILD COMMAND "${CMAKE_CTEST_COMMAND}" --output-on-failure -C $<CONFIG>
|
2022-09-15 00:42:13 +08:00
|
|
|
VERBATIM)
|
2022-02-06 12:38:28 +08:00
|
|
|
endif()
|