| 1 | // { dg-do run { target c++20 } } |
| 2 | // { dg-require-effective-target cxx11_abi } |
| 3 | |
| 4 | #include <chrono> |
| 5 | #include <testsuite_hooks.h> |
| 6 | |
| 7 | using namespace std::chrono; |
| 8 | |
| 9 | void |
| 10 | test_version() |
| 11 | { |
| 12 | const tzdb& db = get_tzdb(); |
| 13 | VERIFY( &db == &get_tzdb_list().front() ); |
| 14 | |
| 15 | const char* func; |
| 16 | try { |
| 17 | func = "remote_version"; |
| 18 | VERIFY( db.version == remote_version() ); |
| 19 | func = "reload_tzdb"; |
| 20 | const tzdb& reloaded = reload_tzdb(); |
| 21 | if (reloaded.version == db.version) |
| 22 | VERIFY( &reloaded == &db ); |
| 23 | } catch (const std::exception&) { |
| 24 | std::printf("std::chrono::%s() failed\n", func); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | void |
| 29 | test_current() |
| 30 | { |
| 31 | const tzdb& db = get_tzdb(); |
| 32 | const time_zone* tz = db.current_zone(); |
| 33 | VERIFY( tz == std::chrono::current_zone() ); |
| 34 | } |
| 35 | |
| 36 | void |
| 37 | test_locate() |
| 38 | { |
| 39 | const tzdb& db = get_tzdb(); |
| 40 | const time_zone* tz = db.locate_zone("GMT"); |
| 41 | VERIFY( tz != nullptr ); |
| 42 | VERIFY( tz == std::chrono::locate_zone("GMT") ); |
| 43 | VERIFY( tz == db.locate_zone("Etc/GMT") ); |
| 44 | VERIFY( tz == db.locate_zone("Etc/GMT+0") ); |
| 45 | |
| 46 | // Since 2022f GMT is now a Zone and Etc/GMT a link instead of vice versa, |
| 47 | // but only when using the vanguard format. As of 2024a, the main and |
| 48 | // rearguard formats still have Etc/GMT as a Zone and GMT as a link. |
| 49 | VERIFY( tz->name() == "GMT" || tz->name() == "Etc/GMT" ); |
| 50 | |
| 51 | VERIFY( db.locate_zone(db.current_zone()->name()) == db.current_zone() ); |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | test_all_zones() |
| 56 | { |
| 57 | const tzdb& db = get_tzdb(); |
| 58 | |
| 59 | for (const auto& zone : db.zones) |
| 60 | VERIFY( locate_zone(zone.name())->name() == zone.name() ); |
| 61 | |
| 62 | for (const auto& link : db.links) |
| 63 | VERIFY( locate_zone(link.name()) == locate_zone(link.target()) ); |
| 64 | } |
| 65 | |
| 66 | int main() |
| 67 | { |
| 68 | test_version(); |
| 69 | test_current(); |
| 70 | test_locate(); |
| 71 | } |