mirror of
https://github.com/thunderbrewhq/bc.git
synced 2025-12-12 01:52:30 +00:00
test(time): rudimentary tests for timekeeping
This commit is contained in:
parent
ee0277da1b
commit
4470aeabae
1 changed files with 41 additions and 0 deletions
41
test/Time.cpp
Normal file
41
test/Time.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include "bc/Time.hpp"
|
||||||
|
#include "bc/Process.hpp"
|
||||||
|
#include "test/Test.hpp"
|
||||||
|
|
||||||
|
TEST_CASE("Blizzard::Time::FromUnixTime", "[time]") {
|
||||||
|
SECTION("convert zero Blizzard time from UNIX timestamp of Sat Jan 01 2000 00:00:00 GMT") {
|
||||||
|
auto stamp = Blizzard::Time::FromUnixTime(946684800);
|
||||||
|
REQUIRE(stamp == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Blizzard::Time::ToUnixTime", "[time]") {
|
||||||
|
SECTION("convert zero Blizzard timestamp to Unix timestamp of Sat Jan 01 2000 00:00:00 GMT+0000") {
|
||||||
|
auto stamp = Blizzard::Time::ToUnixTime(0);
|
||||||
|
REQUIRE(stamp == 946684800);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Blizzard::Time::GetTimestamp", "[time]") {
|
||||||
|
SECTION("Get timestamp") {
|
||||||
|
auto now = Blizzard::Time::GetTimestamp();
|
||||||
|
REQUIRE(now > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Timestamp increases after 200 ms") {
|
||||||
|
auto t1 = Blizzard::Time::GetTimestamp();
|
||||||
|
Blizzard::Process::Sleep(200);
|
||||||
|
auto t2 = Blizzard::Time::GetTimestamp();
|
||||||
|
auto delta = t2 - t1;
|
||||||
|
REQUIRE(delta > 0);
|
||||||
|
REQUIRE(delta >= 180000000LL);
|
||||||
|
REQUIRE(delta <= 220000000LL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Blizzard::Time::Nanoseconds", "[time]") {
|
||||||
|
SECTION("Read wall clock") {
|
||||||
|
auto wctime = Blizzard::Time::Nanoseconds();
|
||||||
|
REQUIRE(wctime > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue