63 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710// UNSUPPORTED: no-filesystem, no-localization, no-tzdb11 12// XFAIL: libcpp-has-no-experimental-tzdb13// XFAIL: availability-tzdb-missing14 15// <chrono>16 17// const time_zone* locate_zone(string_view tz_name);18 19#include <cassert>20#include <chrono>21#include <string_view>22 23#include "test_macros.h"24#include "assert_macros.h"25#include "concat_macros.h"26 27static void test_zone(std::string_view zone) {28 const std::chrono::time_zone* tz = std::chrono::locate_zone(zone);29 assert(tz);30 assert(tz->name() == zone);31}32 33static void test_link(std::string_view link, std::string_view zone) {34 const std::chrono::time_zone* tz = std::chrono::locate_zone(link);35 assert(tz);36 assert(tz->name() == zone);37}38 39static void test_exception([[maybe_unused]] std::string_view zone) {40 TEST_VALIDATE_EXCEPTION(41 std::runtime_error,42 [&]([[maybe_unused]] const std::runtime_error& e) {43 [[maybe_unused]] std::string_view what{"tzdb: requested time zone not found"};44 TEST_LIBCPP_REQUIRE(45 e.what() == what,46 TEST_WRITE_CONCATENATED("\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));47 },48 TEST_IGNORE_NODISCARD std::chrono::locate_zone(zone));49}50 51int main(int, const char**) {52 const std::chrono::tzdb& db = std::chrono::get_tzdb();53 for (const auto& zone : db.zones)54 test_zone(zone.name());55 56 for (const auto& link : db.links)57 test_link(link.name(), link.target());58 59 test_exception("This is not a time zone");60 61 return 0;62}63