From da6a226941318c4df8a33a19f92ec8ad7e6ab0f2 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Thu, 23 Dec 2021 17:10:21 -0600 Subject: [PATCH] Add tests for sf::Clock --- test/CMakeLists.txt | 1 + test/System/Clock.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 test/System/Clock.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3d5b6d504..936fb5d41 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,6 +8,7 @@ target_compile_features(sfml-test-main PRIVATE cxx_std_17) # System is always built SET(SYSTEM_SRC + "${SRCROOT}/System/Clock.cpp" "${SRCROOT}/System/FileInputStream.cpp" "${SRCROOT}/System/Time.cpp" "${SRCROOT}/System/Vector2.cpp" diff --git a/test/System/Clock.cpp b/test/System/Clock.cpp new file mode 100644 index 000000000..69765f79a --- /dev/null +++ b/test/System/Clock.cpp @@ -0,0 +1,26 @@ +#include +#include "SystemUtil.hpp" +#include + +#include + +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); + } +}