mirror of
https://github.com/hyprwm/Hyprland
synced 2025-12-25 21:10:13 +01:00
ightened chrono literal usage, unsigned expectations, and added a regression test ensuring nsec overflow is normalized into
whole seconds.
This commit is contained in:
parent
c9389b27ee
commit
2f99fe45a5
1 changed files with 20 additions and 9 deletions
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
TEST(HelpersTime, DiffBorrowsNanoseconds) {
|
||||
const Time::detail::sec_nsec newer{5, 1};
|
||||
const Time::detail::sec_nsec older{4, 999999999};
|
||||
const Time::detail::sec_nsec older{4, 999'999'999};
|
||||
|
||||
const auto diff = Time::detail::diff(newer, older);
|
||||
|
||||
EXPECT_EQ(diff.first, 0);
|
||||
EXPECT_EQ(diff.second, 2);
|
||||
EXPECT_EQ(diff.first, 0u);
|
||||
EXPECT_EQ(diff.second, 2u);
|
||||
}
|
||||
|
||||
TEST(HelpersTime, DiffWithoutBorrow) {
|
||||
|
|
@ -17,13 +17,23 @@ TEST(HelpersTime, DiffWithoutBorrow) {
|
|||
|
||||
const auto diff = Time::detail::diff(newer, older);
|
||||
|
||||
EXPECT_EQ(diff.first, 1);
|
||||
EXPECT_EQ(diff.second, 250);
|
||||
EXPECT_EQ(diff.first, 1u);
|
||||
EXPECT_EQ(diff.second, 250u);
|
||||
}
|
||||
|
||||
TEST(HelpersTime, NormalizesTimespecNsecOverflow) {
|
||||
const Time::detail::sec_nsec raw{1u, 2'000'000'050u};
|
||||
|
||||
const auto normalized = Time::detail::normalize(raw);
|
||||
|
||||
EXPECT_EQ(normalized.first, 3u);
|
||||
EXPECT_EQ(normalized.second, 50u);
|
||||
}
|
||||
|
||||
TEST(HelpersTime, SecNsecSteadyFixedPoint) {
|
||||
using namespace std::chrono;
|
||||
const Time::steady_tp tp{steady_clock::duration{seconds(1) + nanoseconds(5000)}};
|
||||
using namespace std::chrono_literals;
|
||||
const Time::steady_tp tp{steady_clock::duration{1s + 5000ns}};
|
||||
|
||||
const auto secNsec = Time::secNsec(tp);
|
||||
|
||||
|
|
@ -33,11 +43,12 @@ TEST(HelpersTime, SecNsecSteadyFixedPoint) {
|
|||
|
||||
TEST(HelpersTime, SecNsecSystemFixedPoint) {
|
||||
using namespace std::chrono;
|
||||
using namespace std::chrono_literals;
|
||||
// 5000ns keeps compatibility with coarser system_clock periods (e.g. microseconds).
|
||||
const Time::system_tp tp{system_clock::duration{seconds(2) + nanoseconds(5000)}};
|
||||
const Time::system_tp tp{system_clock::duration{2s + 5000ns}};
|
||||
|
||||
const auto secNsec = Time::secNsec(tp);
|
||||
|
||||
EXPECT_EQ(secNsec.first, 2);
|
||||
EXPECT_EQ(secNsec.second, 5000);
|
||||
EXPECT_EQ(secNsec.first, 2u);
|
||||
EXPECT_EQ(secNsec.second, 5000u);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue