SFML/test/System/Clock.cpp

35 lines
1014 B
C++
Raw Normal View History

2021-12-24 07:10:21 +08:00
#include <SFML/System/Clock.hpp>
#include <SFML/System/Time.hpp>
2021-12-24 07:10:21 +08:00
2022-07-18 06:18:40 +08:00
#include <doctest/doctest.h>
2021-12-24 07:10:21 +08:00
2022-07-05 00:20:58 +08:00
#include <SystemUtil.hpp>
#include <thread>
#include <type_traits>
static_assert(std::is_copy_constructible_v<sf::Clock>);
static_assert(std::is_copy_assignable_v<sf::Clock>);
static_assert(std::is_nothrow_move_constructible_v<sf::Clock>);
static_assert(std::is_nothrow_move_assignable_v<sf::Clock>);
2022-07-05 00:20:58 +08:00
TEST_CASE("[System] sf::Clock")
2021-12-24 07:10:21 +08:00
{
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);
}
}