2828#include " filesystem_test_helper.h"
2929#include " test_tzdb.h"
3030
31+ #if defined(__APPLE__)
32+ # define TEST_USE_BINARY_LEAP_SECONDS
33+ #else
34+ # define TEST_USE_LIST_LEAP_SECONDS
35+ #endif
36+
3137scoped_test_env env;
3238[[maybe_unused]] const std::filesystem::path dir = env.create_dir(" zoneinfo" );
3339const std::filesystem::path tzdata = env.create_file(" zoneinfo/tzdata.zi" );
34- const std::filesystem::path leap_seconds = env.create_file(" zoneinfo/leap-seconds.list" );
40+ #ifdef TEST_USE_BINARY_LEAP_SECONDS
41+ const std::filesystem::path leap_seconds = env.create_file(" zoneinfo/leapseconds" );
42+ #else
43+ const std::filesystem::path leap_seconds = env.create_file(" zoneinfo/leap-seconds.list" );
44+ #endif
3545
3646std::string_view std::chrono::__libcpp_tzdb_directory () {
3747 static std::string result = dir.string ();
@@ -65,21 +75,23 @@ static void test_exception(std::string_view input, [[maybe_unused]] std::string_
6575}
6676
6777static void test_invalid () {
78+ #ifdef TEST_USE_BINARY_LEAP_SECONDS
79+ test_exception (" 0" , " corrupt tzdb: expected character 'l' from string 'leap', got '0' instead" );
80+ test_exception (" Leap x" , " corrupt tzdb: expected a digit" );
81+ test_exception (" Leap 1970 J" , " corrupt tzdb month: invalid name" );
82+ test_exception (" Leap 1970 Jan 1 23:59:60 x" , " corrupt tzdb: invalid leap second sign x" );
83+ #else
6884 test_exception (" 0" , " corrupt tzdb: expected a non-zero digit" );
69-
7085 test_exception (" 1" , " corrupt tzdb: expected whitespace" );
71-
7286 test_exception (" 1 " , " corrupt tzdb: expected a non-zero digit" );
73-
7487 test_exception (" 5764607523034234880 2" , " corrupt tzdb: integral too large" );
88+ #endif
7589}
7690
7791static void test_leap_seconds () {
7892 using namespace std ::chrono;
7993
80- // Test whether loading also sorts the entries in the proper order.
81- const tzdb& result = parse (
82- R"(
94+ std::string list_format = R"(
83952303683200 12 # 1 Jan 1973
84962287785600 11 # 1 Jul 1972
85972272060800 10 # 1 Jan 1972
@@ -91,7 +103,25 @@ static void test_leap_seconds() {
91103
92104# largest accepted value by the parser
931055764607523034234879 12
94- )" );
106+ )" ;
107+
108+ std::string binary_format = R"(
109+ Leap 1973 Jan 1 23:59:60 + S
110+ Leap 1972 Jul 1 23:59:60 + S
111+ Leap 1972 Jan 1 23:59:60 + S
112+ Leap 1900 Jan 2 23:59:60 + S # 2 Jan 1900 Dummy entry to test before 1970
113+ Leap 1900 Jan 2 00:00:01 + S # 2 Jan 1900 Dummy entry to test before 1970
114+
115+ Leap 1973 Jan 2 23:59:60 - S # Fictional negative leap second
116+ Leap 32767 Jan 1 23:59:60 + S # Largest year accepted by the parser
117+ )" ;
118+
119+ // Test whether loading also sorts the entries in the proper order.
120+ #ifdef TEST_USE_BINARY_LEAP_SECONDS
121+ const tzdb& result = parse (binary_format);
122+ #else
123+ const tzdb& result = parse (list_format);
124+ #endif
95125
96126 assert (result.leap_seconds .size () == 6 );
97127
0 commit comments