mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-26 13:06:13 +01:00
Add unit tests
Yay tests!
This commit is contained in:
1 parent
36c234fd90
commit
330b423ee9
10 files changed
+166
-7
No files matched your search
@@ -0,0 +1,36 @@
|
||||
include(FetchContent)
|
||||
|
||||
set(CATCH_CONFIG_FAST_COMPILE ON CACHE BOOL "")
|
||||
set(CATCH_CONFIG_NO_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT ON CACHE BOOL "")
|
||||
FetchContent_Declare(Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v3.5.3
|
||||
GIT_SHALLOW ON)
|
||||
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})
|
||||
|
||||
add_executable(test-csfml-system
|
||||
System/Buffer.test.cpp
|
||||
System/Clock.test.cpp
|
||||
System/Sleep.test.cpp
|
||||
System/Time.test.cpp
|
||||
System/Vector2.test.cpp
|
||||
System/Vector3.test.cpp
|
||||
)
|
||||
target_link_libraries(test-csfml-system PRIVATE csfml-system Catch2::Catch2WithMain)
|
||||
set_target_warnings(test-csfml-system)
|
||||
catch_discover_tests(test-csfml-system)
|
||||
|
||||
# Copy DLLs into the same directory
|
||||
if(SFML_OS_WINDOWS AND NOT CSFML_LINK_SFML_STATICALLY)
|
||||
add_custom_command(TARGET test-csfml-system PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:test-csfml-system> $<TARGET_FILE_DIR:test-csfml-system> COMMAND_EXPAND_LISTS)
|
||||
endif()
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <SFML/System/Buffer.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("[System] sfBuffer")
|
||||
{
|
||||
sfBuffer* buffer = sfBuffer_create();
|
||||
CHECK(sfBuffer_getSize(buffer) == 0);
|
||||
CHECK(sfBuffer_getData(buffer) == 0);
|
||||
sfBuffer_destroy(buffer);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <SFML/System/Clock.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <thread>
|
||||
|
||||
TEST_CASE("[System] sfClock")
|
||||
{
|
||||
sfClock* clock = sfClock_create();
|
||||
|
||||
CHECK(sfTime_asMicroseconds(sfClock_getElapsedTime(clock)) >= 0);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
CHECK(sfTime_asMicroseconds(sfClock_getElapsedTime(clock)) >= 1'000);
|
||||
|
||||
sfClock_restart(clock);
|
||||
CHECK(sfTime_asMicroseconds(sfClock_getElapsedTime(clock)) >= 0);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
CHECK(sfTime_asMicroseconds(sfClock_getElapsedTime(clock)) >= 1'000);
|
||||
|
||||
sfClock* anotherClock = sfClock_copy(clock);
|
||||
CHECK(sfTime_asMicroseconds(sfClock_getElapsedTime(anotherClock)) >= 1'000);
|
||||
|
||||
sfClock_destroy(anotherClock);
|
||||
sfClock_destroy(clock);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <SFML/System/Sleep.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("[System] sfSleep")
|
||||
{
|
||||
const auto startTime = std::chrono::steady_clock::now();
|
||||
sfSleep(sfMilliseconds(10));
|
||||
const auto elapsed = std::chrono::steady_clock::now() - startTime;
|
||||
CHECK(elapsed >= std::chrono::milliseconds(10));
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <SFML/System/Time.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("[System] sfTime")
|
||||
{
|
||||
CHECK(sfTime_Zero.microseconds == 0);
|
||||
|
||||
sfTime time{};
|
||||
CHECK(time.microseconds == 0);
|
||||
CHECK(sfTime_asSeconds(time) == 0);
|
||||
CHECK(sfTime_asMilliseconds(time) == 0);
|
||||
CHECK(sfTime_asMicroseconds(time) == 0);
|
||||
|
||||
time.microseconds = 1'234'567;
|
||||
CHECK(sfTime_asSeconds(time) == 1.234567f);
|
||||
CHECK(sfTime_asMilliseconds(time) == 1234);
|
||||
CHECK(sfTime_asMicroseconds(time) == 1'234'567);
|
||||
|
||||
CHECK(sfSeconds(0).microseconds == 0);
|
||||
CHECK(sfMilliseconds(0).microseconds == 0);
|
||||
CHECK(sfMicroseconds(0).microseconds == 0);
|
||||
|
||||
CHECK(sfSeconds(1).microseconds == 1'000'000);
|
||||
CHECK(sfMilliseconds(1).microseconds == 1'000);
|
||||
CHECK(sfMicroseconds(1).microseconds == 1);
|
||||
|
||||
CHECK(sfSeconds(10).microseconds == 10'000'000);
|
||||
CHECK(sfMilliseconds(10).microseconds == 10'000);
|
||||
CHECK(sfMicroseconds(10).microseconds == 10);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <SFML/System/Vector2.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("[System] sfVector2")
|
||||
{
|
||||
SECTION("sfVector2i")
|
||||
{
|
||||
const sfVector2i vector{};
|
||||
CHECK(vector.x == 0);
|
||||
CHECK(vector.y == 0);
|
||||
}
|
||||
|
||||
SECTION("sfVector2u")
|
||||
{
|
||||
const sfVector2u vector{};
|
||||
CHECK(vector.x == 0);
|
||||
CHECK(vector.y == 0);
|
||||
}
|
||||
|
||||
SECTION("sfVector2f")
|
||||
{
|
||||
const sfVector2f vector{};
|
||||
CHECK(vector.x == 0);
|
||||
CHECK(vector.y == 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <SFML/System/Vector3.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("[System] sfVector3")
|
||||
{
|
||||
SECTION("sfVector3f")
|
||||
{
|
||||
const sfVector3f vector{};
|
||||
CHECK(vector.x == 0);
|
||||
CHECK(vector.y == 0);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user