mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
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.
This commit is contained in:
committed by
Linus Groh
parent
024f869f09
commit
010ec36d20
@@ -17,6 +17,12 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
explicit TimeZoneGuard(char const* tz)
|
||||||
|
: m_tz(getenv("TZ"))
|
||||||
|
{
|
||||||
|
setenv("TZ", tz, 1);
|
||||||
|
}
|
||||||
|
|
||||||
~TimeZoneGuard()
|
~TimeZoneGuard()
|
||||||
{
|
{
|
||||||
if (m_tz)
|
if (m_tz)
|
||||||
@@ -31,6 +37,8 @@ private:
|
|||||||
|
|
||||||
TEST_CASE(asctime)
|
TEST_CASE(asctime)
|
||||||
{
|
{
|
||||||
|
TimeZoneGuard guard("UTC");
|
||||||
|
|
||||||
time_t epoch = 0;
|
time_t epoch = 0;
|
||||||
auto result = asctime(localtime(&epoch));
|
auto result = asctime(localtime(&epoch));
|
||||||
EXPECT_EQ(expected_epoch, StringView(result));
|
EXPECT_EQ(expected_epoch, StringView(result));
|
||||||
@@ -38,6 +46,8 @@ TEST_CASE(asctime)
|
|||||||
|
|
||||||
TEST_CASE(asctime_r)
|
TEST_CASE(asctime_r)
|
||||||
{
|
{
|
||||||
|
TimeZoneGuard guard("UTC");
|
||||||
|
|
||||||
char buffer[26] {};
|
char buffer[26] {};
|
||||||
time_t epoch = 0;
|
time_t epoch = 0;
|
||||||
auto result = asctime_r(localtime(&epoch), buffer);
|
auto result = asctime_r(localtime(&epoch), buffer);
|
||||||
@@ -46,6 +56,8 @@ TEST_CASE(asctime_r)
|
|||||||
|
|
||||||
TEST_CASE(ctime)
|
TEST_CASE(ctime)
|
||||||
{
|
{
|
||||||
|
TimeZoneGuard guard("UTC");
|
||||||
|
|
||||||
time_t epoch = 0;
|
time_t epoch = 0;
|
||||||
auto result = ctime(&epoch);
|
auto result = ctime(&epoch);
|
||||||
|
|
||||||
@@ -54,6 +66,8 @@ TEST_CASE(ctime)
|
|||||||
|
|
||||||
TEST_CASE(ctime_r)
|
TEST_CASE(ctime_r)
|
||||||
{
|
{
|
||||||
|
TimeZoneGuard guard("UTC");
|
||||||
|
|
||||||
char buffer[26] {};
|
char buffer[26] {};
|
||||||
time_t epoch = 0;
|
time_t epoch = 0;
|
||||||
auto result = ctime_r(&epoch, buffer);
|
auto result = ctime_r(&epoch, buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user