Add unit tests

Yay tests!
This commit is contained in:
Chris Thrasher committed 2024-04-15 15:24:51 -06:00
1 parent 36c234fd90
commit 330b423ee9
10 files changed
+166 -7

No files matched your search

+11
View File
@@ -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);
}
+25
View File
@@ -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);
}
+11
View File
@@ -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));
}
+31
View File
@@ -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);
}
+27
View File
@@ -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);
}
}
+13
View File
@@ -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);
}
}