diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-01-24 15:38:33 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-25 18:39:36 +0000 |
commit | 010ec36d20e6c2d97fd6fb4e6bd7f8582f123c57 (patch) | |
tree | 5173f0e5e15c8bc16efa41554b85c941f1495fcf /Tests | |
parent | 024f869f09575acd3b9de321f6488032feab8f54 (diff) | |
download | serenity-010ec36d20e6c2d97fd6fb4e6bd7f8582f123c57.zip |
LibC: Ensure most time tests run under UTC
This ensures these tests pass even if the user has changed the system
time zone away from UTC.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/LibC/TestLibCTime.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Tests/LibC/TestLibCTime.cpp b/Tests/LibC/TestLibCTime.cpp index 4fa829e2a2..72e0777b2c 100644 --- a/Tests/LibC/TestLibCTime.cpp +++ b/Tests/LibC/TestLibCTime.cpp @@ -17,6 +17,12 @@ public: { } + explicit TimeZoneGuard(char const* tz) + : m_tz(getenv("TZ")) + { + setenv("TZ", tz, 1); + } + ~TimeZoneGuard() { if (m_tz) @@ -31,6 +37,8 @@ private: TEST_CASE(asctime) { + TimeZoneGuard guard("UTC"); + time_t epoch = 0; auto result = asctime(localtime(&epoch)); EXPECT_EQ(expected_epoch, StringView(result)); @@ -38,6 +46,8 @@ TEST_CASE(asctime) TEST_CASE(asctime_r) { + TimeZoneGuard guard("UTC"); + char buffer[26] {}; time_t epoch = 0; auto result = asctime_r(localtime(&epoch), buffer); @@ -46,6 +56,8 @@ TEST_CASE(asctime_r) TEST_CASE(ctime) { + TimeZoneGuard guard("UTC"); + time_t epoch = 0; auto result = ctime(&epoch); @@ -54,6 +66,8 @@ TEST_CASE(ctime) TEST_CASE(ctime_r) { + TimeZoneGuard guard("UTC"); + char buffer[26] {}; time_t epoch = 0; auto result = ctime_r(&epoch, buffer); |