mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-16 17:00:35 +03:00
LibTimeZone: Fix tests when ENABLE_TIME_ZONE_DATABASE_DOWNLOAD is OFF
This commit is contained in:
parent
6af9bf1a1e
commit
3748370dfd
Notes:
sideshowbarker
2024-07-17 07:45:17 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/3748370dfd Pull-request: https://github.com/SerenityOS/serenity/pull/15012 Reviewed-by: https://github.com/linusg ✅
@ -12,6 +12,14 @@
|
||||
|
||||
using enum TimeZone::InDST;
|
||||
|
||||
static void test_offset(StringView time_zone, i64 time, i64 expected_offset, TimeZone::InDST expected_in_dst)
|
||||
{
|
||||
auto actual_offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_seconds(time));
|
||||
VERIFY(actual_offset.has_value());
|
||||
EXPECT_EQ(actual_offset->seconds, expected_offset);
|
||||
EXPECT_EQ(actual_offset->in_dst, expected_in_dst);
|
||||
}
|
||||
|
||||
#if ENABLE_TIME_ZONE_DATA
|
||||
|
||||
# include <LibTimeZone/TimeZoneData.h>
|
||||
@ -92,14 +100,6 @@ static i64 offset(i64 sign, i64 hours, i64 minutes, i64 seconds)
|
||||
return sign * ((hours * 3600) + (minutes * 60) + seconds);
|
||||
}
|
||||
|
||||
static void test_offset(StringView time_zone, i64 time, i64 expected_offset, TimeZone::InDST expected_in_dst)
|
||||
{
|
||||
auto actual_offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_seconds(time));
|
||||
VERIFY(actual_offset.has_value());
|
||||
EXPECT_EQ(actual_offset->seconds, expected_offset);
|
||||
EXPECT_EQ(actual_offset->in_dst, expected_in_dst);
|
||||
}
|
||||
|
||||
TEST_CASE(get_time_zone_offset)
|
||||
{
|
||||
test_offset("America/Chicago"sv, -2717668237, offset(-1, 5, 50, 36), No); // Sunday, November 18, 1883 12:09:23 PM
|
||||
@ -183,7 +183,7 @@ TEST_CASE(get_named_time_zone_offsets)
|
||||
|
||||
TEST_CASE(time_zone_from_string)
|
||||
{
|
||||
EXPECT_EQ(TimeZone::time_zone_from_string("UTC"sv), TimeZone::TimeZone::UTC);
|
||||
EXPECT(TimeZone::time_zone_from_string("UTC"sv).has_value());
|
||||
|
||||
EXPECT(!TimeZone::time_zone_from_string("Europe/Paris"sv).has_value());
|
||||
EXPECT(!TimeZone::time_zone_from_string("Etc/UTC"sv).has_value());
|
||||
@ -192,7 +192,7 @@ TEST_CASE(time_zone_from_string)
|
||||
|
||||
TEST_CASE(get_time_zone_offset)
|
||||
{
|
||||
EXPECT_EQ(TimeZone::get_time_zone_offset("UTC", AK::Time::from_seconds(123456)), { 0, No });
|
||||
test_offset("UTC"sv, 123456, 0, No);
|
||||
|
||||
EXPECT(!TimeZone::get_time_zone_offset("Europe/Paris"sv, {}).has_value());
|
||||
EXPECT(!TimeZone::get_time_zone_offset("Etc/UTC"sv, {}).has_value());
|
||||
|
Loading…
Reference in New Issue
Block a user