diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-01-10 12:22:47 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-11 00:36:45 +0100 |
commit | b493c2ca902569fbde6151d3953ac06863c75c7c (patch) | |
tree | c3cd4832e9191fd6340ad1f6101b4ecf6e69e9ae | |
parent | ccce9e5c7f9a91c25aa7211917bc823d67594703 (diff) | |
download | serenity-b493c2ca902569fbde6151d3953ac06863c75c7c.zip |
LibTimeZone: Add a unit test for generated time zone data
-rw-r--r-- | Meta/Lagom/CMakeLists.txt | 9 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/LibTimeZone/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Tests/LibTimeZone/TestTimeZone.cpp | 49 |
4 files changed, 69 insertions, 0 deletions
diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index ed9581ac84..fcc5d15a67 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -576,6 +576,15 @@ if (BUILD_LAGOM) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibTLS) endforeach() + # TimeZone + file(GLOB LIBTIMEZONE_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/LibTimeZone/*.cpp") + foreach(source ${LIBTIMEZONE_TEST_SOURCES}) + lagom_test(${source} LIBS LagomTimeZone) + + get_filename_component(target "${source}" NAME_WLE) + target_compile_definitions("${target}_lagom" PRIVATE ENABLE_TIME_ZONE_DATA=$<BOOL:${ENABLE_TIME_ZONE_DATABASE_DOWNLOAD}>) + endforeach() + # Unicode file(GLOB LIBUNICODE_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/LibUnicode/*.cpp") foreach(source ${LIBUNICODE_TEST_SOURCES}) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 9164ffb885..b7b2951385 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -17,6 +17,7 @@ add_subdirectory(LibRegex) add_subdirectory(LibSQL) add_subdirectory(LibTest) add_subdirectory(LibThreading) +add_subdirectory(LibTimeZone) add_subdirectory(LibUnicode) add_subdirectory(LibWasm) add_subdirectory(LibWeb) diff --git a/Tests/LibTimeZone/CMakeLists.txt b/Tests/LibTimeZone/CMakeLists.txt new file mode 100644 index 0000000000..26f88bf4ce --- /dev/null +++ b/Tests/LibTimeZone/CMakeLists.txt @@ -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() diff --git a/Tests/LibTimeZone/TestTimeZone.cpp b/Tests/LibTimeZone/TestTimeZone.cpp new file mode 100644 index 0000000000..15a4115267 --- /dev/null +++ b/Tests/LibTimeZone/TestTimeZone.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022, Tim Flynn <trflynn89@pm.me> + * + * 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 |