mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-26 21:16: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,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