| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 |
// See https://llvm.org/LICENSE.txt for license information. |
| 4 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 |
// |
| 6 |
//===----------------------------------------------------------------------===// |
| 7 |
|
| 8 |
// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 9 |
// UNSUPPORTED: no-localization |
| 10 |
// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME |
| 11 |
|
| 12 |
// TODO FMT This test should not require std::to_chars(floating-point) |
| 13 |
// XFAIL: availability-fp_to_chars-missing |
| 14 |
|
| 15 |
// XFAIL: libcpp-has-no-experimental-tzdb |
| 16 |
|
| 17 |
// REQUIRES: locale.fr_FR.UTF-8 |
| 18 |
|
| 19 |
// <chrono> |
| 20 |
// |
| 21 |
// template<class charT> struct formatter<chrono::local_info, charT>; |
| 22 |
|
| 23 |
#include <chrono> |
| 24 |
#include <format> |
| 25 |
|
| 26 |
#include <cassert> |
| 27 |
#include <concepts> |
| 28 |
#include <locale> |
| 29 |
#include <iostream> |
| 30 |
#include <type_traits> |
| 31 |
|
| 32 |
#include "formatter_tests.h" |
| 33 |
#include "make_string.h" |
| 34 |
#include "platform_support.h" // locale name macros |
| 35 |
#include "test_macros.h" |
| 36 |
|
| 37 |
template <class CharT> |
| 38 |
static void test_no_chrono_specs() { |
| 39 |
// This test libc++ specific due to |
| 40 |
// [time.zone.info.local]/3 |
| 41 |
// Effects: Streams out the local_info object r in an unspecified format. |
| 42 |
#ifdef _LIBCPP_VERSION |
| 43 |
using namespace std::literals::chrono_literals; |
| 44 |
namespace tz = std::chrono; |
| 45 |
|
| 46 |
std::locale::global(std::locale(LOCALE_fr_FR_UTF_8)); |
| 47 |
|
| 48 |
// Non localized output |
| 49 |
|
| 50 |
// result values matching the "known" results |
| 51 |
check(SV("unique: " |
| 52 |
"{[-10484-10-16 15:30:08, 14423-03-17 15:30:07) 00:00:00 0min \"TZ\", " |
| 53 |
"[1970-01-01 00:00:00, 1970-01-01 00:00:00) 00:00:00 0min \"\"}"), |
| 54 |
SV("{}"), |
| 55 |
tz::local_info{tz::local_info::unique, |
| 56 |
tz::sys_info{tz::sys_seconds::min(), tz::sys_seconds::max(), 0s, 0min, "TZ"}, |
| 57 |
tz::sys_info{}}); |
| 58 |
|
| 59 |
check(SV("non-existent: " |
| 60 |
"{[1970-01-01 00:00:00, 2038-12-31 00:00:00) 12:23:45 -67min \"NEG\", " |
| 61 |
"[1970-01-01 00:00:00, 2038-12-31 00:00:00) -12:23:45 67min \"POS\"}"), |
| 62 |
SV("{}"), |
| 63 |
tz::local_info{ |
| 64 |
tz::local_info::nonexistent, |
| 65 |
tz::sys_info{static_cast<tz::sys_days>(tz::year_month_day{1970y, tz::January, 1d}), |
| 66 |
static_cast<tz::sys_days>(tz::year_month_day{2038y, tz::December, 31d}), |
| 67 |
12h + 23min + 45s, |
| 68 |
-67min, |
| 69 |
"NEG"}, |
| 70 |
tz::sys_info{static_cast<tz::sys_days>(tz::year_month_day{1970y, tz::January, 1d}), |
| 71 |
static_cast<tz::sys_days>(tz::year_month_day{2038y, tz::December, 31d}), |
| 72 |
-(12h + 23min + 45s), |
| 73 |
67min, |
| 74 |
"POS"}}); |
| 75 |
|
| 76 |
check(SV("ambiguous: " |
| 77 |
"{[1970-01-01 00:00:00, 2038-12-31 00:00:00) 12:23:45 -67min \"NEG\", " |
| 78 |
"[1970-01-01 00:00:00, 2038-12-31 00:00:00) -12:23:45 67min \"POS\"}"), |
| 79 |
SV("{}"), |
| 80 |
tz::local_info{ |
| 81 |
tz::local_info::ambiguous, |
| 82 |
tz::sys_info{static_cast<tz::sys_days>(tz::year_month_day{1970y, tz::January, 1d}), |
| 83 |
static_cast<tz::sys_days>(tz::year_month_day{2038y, tz::December, 31d}), |
| 84 |
12h + 23min + 45s, |
| 85 |
-67min, |
| 86 |
"NEG"}, |
| 87 |
tz::sys_info{static_cast<tz::sys_days>(tz::year_month_day{1970y, tz::January, 1d}), |
| 88 |
static_cast<tz::sys_days>(tz::year_month_day{2038y, tz::December, 31d}), |
| 89 |
-(12h + 23min + 45s), |
| 90 |
67min, |
| 91 |
"POS"}}); |
| 92 |
|
| 93 |
// result values not matching the "known" results |
| 94 |
check( |
| 95 |
SV("unspecified result (-1): " |
| 96 |
"{[-10484-10-16 15:30:08, 14423-03-17 15:30:07) 00:00:00 0min \"TZ\", " |
| 97 |
"[1970-01-01 00:00:00, 1970-01-01 00:00:00) 00:00:00 0min \"\"}"), |
| 98 |
SV("{}"), |
| 99 |
tz::local_info{-1, tz::sys_info{tz::sys_seconds::min(), tz::sys_seconds::max(), 0s, 0min, "TZ"}, tz::sys_info{}}); |
| 100 |
check( |
| 101 |
SV("unspecified result (3): " |
| 102 |
"{[-10484-10-16 15:30:08, 14423-03-17 15:30:07) 00:00:00 0min \"TZ\", " |
| 103 |
"[1970-01-01 00:00:00, 1970-01-01 00:00:00) 00:00:00 0min \"\"}"), |
| 104 |
SV("{}"), |
| 105 |
tz::local_info{3, tz::sys_info{tz::sys_seconds::min(), tz::sys_seconds::max(), 0s, 0min, "TZ"}, tz::sys_info{}}); |
| 106 |
|
| 107 |
std::locale::global(std::locale::classic()); |
| 108 |
#endif // _LIBCPP_VERSION |
| 109 |
} |
| 110 |
|
| 111 |
template <class CharT> |
| 112 |
static void test() { |
| 113 |
test_no_chrono_specs<CharT>(); |
| 114 |
|
| 115 |
check_invalid_types<CharT>({}, std::chrono::local_info{0, {}, {}}); |
| 116 |
} |
| 117 |
|
| 118 |
int main(int, char**) { |
| 119 |
test<char>(); |
| 120 |
|
| 121 |
#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 122 |
test<wchar_t>(); |
| 123 |
#endif |
| 124 |
|
| 125 |
return 0; |
| 126 |
} |