SFML/test/System/Clock.test.cpp

69 lines
1.8 KiB
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
2023-01-18 12:51:08 +08:00
#include <catch2/catch_test_macros.hpp>
2021-12-24 07:10:21 +08:00
2022-07-05 00:20:58 +08:00
#include <SystemUtil.hpp>
#include <thread>
#include <type_traits>
TEST_CASE("[System] sf::Clock")
2021-12-24 07:10:21 +08:00
{
2022-07-20 20:40:45 +08:00
using namespace std::chrono_literals;
2023-01-18 12:51:08 +08:00
SECTION("Type traits")
{
STATIC_CHECK(std::is_copy_constructible_v<sf::Clock>);
STATIC_CHECK(std::is_copy_assignable_v<sf::Clock>);
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Clock>);
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Clock>);
}
2022-07-20 20:40:45 +08:00
SECTION("Construction")
{
const sf::Clock clock;
CHECK(clock.isRunning());
CHECK(clock.getElapsedTime() >= sf::microseconds(0));
}
2023-01-18 12:51:08 +08:00
SECTION("getElapsedTime()")
2021-12-24 07:10:21 +08:00
{
const sf::Clock clock;
CHECK(clock.getElapsedTime() >= sf::microseconds(0));
const auto elapsed = clock.getElapsedTime();
2022-07-20 20:40:45 +08:00
std::this_thread::sleep_for(1ms);
2021-12-24 07:10:21 +08:00
CHECK(clock.getElapsedTime() > elapsed);
}
2022-07-20 20:40:45 +08:00
SECTION("start/stop")
{
sf::Clock clock;
clock.stop();
CHECK(!clock.isRunning());
const auto elapsed = clock.getElapsedTime();
std::this_thread::sleep_for(1ms);
CHECK(elapsed == clock.getElapsedTime());
clock.start();
CHECK(clock.isRunning());
CHECK(clock.getElapsedTime() >= elapsed);
}
2023-01-18 12:51:08 +08:00
SECTION("restart()")
2021-12-24 07:10:21 +08:00
{
sf::Clock clock;
CHECK(clock.restart() >= sf::microseconds(0));
2022-07-20 20:40:45 +08:00
CHECK(clock.isRunning());
std::this_thread::sleep_for(1ms);
2021-12-24 07:10:21 +08:00
const auto elapsed = clock.restart();
CHECK(clock.restart() < elapsed);
}
2022-07-20 20:40:45 +08:00
SECTION("reset()")
{
sf::Clock clock;
CHECK(clock.reset() >= sf::microseconds(0));
CHECK(!clock.isRunning());
}
2021-12-24 07:10:21 +08:00
}