forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibTimeZone: Add a unit test for generated time zone data
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
set(TEST_SOURCES | ||
TestTimeZone.cpp | ||
) | ||
|
||
foreach(source IN LISTS TEST_SOURCES) | ||
serenity_test("${source}" LibTimeZone LIBS LibTimeZone) | ||
|
||
get_filename_component(target "${source}" NAME_WLE) | ||
target_compile_definitions("${target}" PRIVATE ENABLE_TIME_ZONE_DATA=$<BOOL:${ENABLE_TIME_ZONE_DATABASE_DOWNLOAD}>) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2022, Tim Flynn <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include <LibTest/TestCase.h> | ||
|
||
#include <AK/StringView.h> | ||
#include <LibTimeZone/TimeZone.h> | ||
|
||
#if ENABLE_TIME_ZONE_DATA | ||
|
||
# include <LibTimeZone/TimeZoneData.h> | ||
|
||
TEST_CASE(time_zone_from_string) | ||
{ | ||
EXPECT_EQ(TimeZone::time_zone_from_string("America/New_York"sv), TimeZone::TimeZone::America_New_York); | ||
EXPECT_EQ(TimeZone::time_zone_from_string("Europe/Paris"sv), TimeZone::TimeZone::Europe_Paris); | ||
EXPECT_EQ(TimeZone::time_zone_from_string("Etc/GMT+2"sv), TimeZone::TimeZone::Etc_GMT_Ahead_2); | ||
EXPECT_EQ(TimeZone::time_zone_from_string("Etc/GMT-5"sv), TimeZone::TimeZone::Etc_GMT_Behind_5); | ||
|
||
EXPECT(!TimeZone::time_zone_from_string("I don't exist"sv).has_value()); | ||
} | ||
|
||
TEST_CASE(time_zone_from_string_link) | ||
{ | ||
auto test_link = [](auto tz1, auto tz2) { | ||
auto result1 = TimeZone::time_zone_from_string(tz1); | ||
EXPECT(result1.has_value()); | ||
|
||
auto result2 = TimeZone::time_zone_from_string(tz2); | ||
EXPECT(result2.has_value()); | ||
|
||
EXPECT_EQ(*result1, *result2); | ||
}; | ||
|
||
test_link("America/New_York"sv, "US/Eastern"sv); | ||
|
||
test_link("Etc/GMT"sv, "GMT"sv); | ||
test_link("Etc/GMT+0"sv, "GMT"sv); | ||
test_link("Etc/GMT-0"sv, "GMT"sv); | ||
|
||
test_link("Etc/UTC"sv, "UTC"sv); | ||
test_link("Etc/Universal"sv, "UTC"sv); | ||
test_link("Universal"sv, "UTC"sv); | ||
} | ||
|
||
#endif |