brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 08ce48d Raw
65 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// struct tzdb18 19// const time_zone* locate_zone(string_view tz_name) const;20 21#include <cassert>22#include <chrono>23#include <string_view>24 25#include "test_macros.h"26#include "assert_macros.h"27#include "concat_macros.h"28 29static void test_zone(std::string_view zone) {30  const std::chrono::time_zone* tz = std::chrono::get_tzdb().locate_zone(zone);31  assert(tz);32  assert(tz->name() == zone);33}34 35static void test_link(std::string_view link, std::string_view zone) {36  const std::chrono::time_zone* tz = std::chrono::get_tzdb().locate_zone(link);37  assert(tz);38  assert(tz->name() == zone);39}40 41static void test_exception([[maybe_unused]] std::string_view zone) {42  TEST_VALIDATE_EXCEPTION(43      std::runtime_error,44      [&]([[maybe_unused]] const std::runtime_error& e) {45        [[maybe_unused]] std::string_view what{"tzdb: requested time zone not found"};46        TEST_LIBCPP_REQUIRE(47            e.what() == what,48            TEST_WRITE_CONCATENATED("\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));49      },50      TEST_IGNORE_NODISCARD std::chrono::get_tzdb().locate_zone(zone));51}52 53int main(int, const char**) {54  const std::chrono::tzdb& db = std::chrono::get_tzdb();55  for (const auto& zone : db.zones)56    test_zone(zone.name());57 58  for (const auto& link : db.links)59    test_link(link.name(), link.target());60 61  test_exception("This is not a time zone");62 63  return 0;64}65