Add tests for sf::Clock

This commit is contained in:
Chris Thrasher 2021-12-23 17:10:21 -06:00 committed by Vittorio Romeo
parent 4586db91a9
commit da6a226941
2 changed files with 27 additions and 0 deletions

View File

@ -8,6 +8,7 @@ target_compile_features(sfml-test-main PRIVATE cxx_std_17)
# System is always built # System is always built
SET(SYSTEM_SRC SET(SYSTEM_SRC
"${SRCROOT}/System/Clock.cpp"
"${SRCROOT}/System/FileInputStream.cpp" "${SRCROOT}/System/FileInputStream.cpp"
"${SRCROOT}/System/Time.cpp" "${SRCROOT}/System/Time.cpp"
"${SRCROOT}/System/Vector2.cpp" "${SRCROOT}/System/Vector2.cpp"

26
test/System/Clock.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <SFML/System/Clock.hpp>
#include "SystemUtil.hpp"
#include <thread>
#include <doctest.h>
TEST_CASE("sf::Clock class - [system]")
{
SUBCASE("getElapsedTime()")
{
const sf::Clock clock;
CHECK(clock.getElapsedTime() >= sf::microseconds(0));
const auto elapsed = clock.getElapsedTime();
std::this_thread::sleep_for(std::chrono::milliseconds(1));
CHECK(clock.getElapsedTime() > elapsed);
}
SUBCASE("restart()")
{
sf::Clock clock;
CHECK(clock.restart() >= sf::microseconds(0));
std::this_thread::sleep_for(std::chrono::milliseconds(1));
const auto elapsed = clock.restart();
CHECK(clock.restart() < elapsed);
}
}