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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// XFAIL: no-wide-characters
10
11// REQUIRES: locale.en_US.UTF-8
12// REQUIRES: locale.fr_FR.UTF-8
13// REQUIRES: locale.ru_RU.UTF-8
14// REQUIRES: locale.zh_CN.UTF-8
15
16// <locale>
17
18// class time_get_byname<charT, InputIterator>
19
20// iter_type
21// get_time(iter_type s, iter_type end, ios_base& str,
22// ios_base::iostate& err, tm* t) const;
23
24#include <locale>
25#include <cassert>
26#include <ios>
27#include "test_macros.h"
28#include "test_iterators.h"
29
30#include "platform_support.h" // locale name macros
31
32typedef cpp17_input_iterator<const wchar_t*> I;
33
34typedef std::time_get_byname<wchar_t, I> F;
35
36class my_facet
37 : public F
38{
39public:
40 explicit my_facet(const std::string& nm, std::size_t refs = 0)
41 : F(nm, refs) {}
42};
43
44int main(int, char**)
45{
46 std::ios ios(0);
47 std::ios_base::iostate err;
48 std::tm t;
49 {
50 const my_facet f(LOCALE_en_US_UTF_8, 1);
51 const wchar_t in[] = L"13:14:15";
52 err = std::ios_base::goodbit;
53 t = std::tm();
54 I i = f.get_time(beg: I(in), end: I(in+sizeof(in)/sizeof(in[0])-1), io&: ios, err&: err, tm: &t);
55 assert(base(i) == in+sizeof(in)/sizeof(in[0])-1);
56 assert(t.tm_hour == 13);
57 assert(t.tm_min == 14);
58 assert(t.tm_sec == 15);
59 assert(err == std::ios_base::eofbit);
60 }
61 {
62 const my_facet f(LOCALE_fr_FR_UTF_8, 1);
63 const wchar_t in[] = L"13:14:15";
64 err = std::ios_base::goodbit;
65 t = std::tm();
66 I i = f.get_time(beg: I(in), end: I(in+sizeof(in)/sizeof(in[0])-1), io&: ios, err&: err, tm: &t);
67 assert(base(i) == in+sizeof(in)/sizeof(in[0])-1);
68 assert(t.tm_hour == 13);
69 assert(t.tm_min == 14);
70 assert(t.tm_sec == 15);
71 assert(err == std::ios_base::eofbit);
72 }
73 {
74 const my_facet f(LOCALE_ru_RU_UTF_8, 1);
75 const wchar_t in[] = L"13:14:15";
76 err = std::ios_base::goodbit;
77 t = std::tm();
78 I i = f.get_time(beg: I(in), end: I(in+sizeof(in)/sizeof(in[0])-1), io&: ios, err&: err, tm: &t);
79 assert(base(i) == in+sizeof(in)/sizeof(in[0])-1);
80 assert(t.tm_hour == 13);
81 assert(t.tm_min == 14);
82 assert(t.tm_sec == 15);
83 assert(err == std::ios_base::eofbit);
84 }
85 {
86 const my_facet f(LOCALE_zh_CN_UTF_8, 1);
87 const wchar_t in[] = L"13:14:15";
88 err = std::ios_base::goodbit;
89 t = std::tm();
90 I i = f.get_time(beg: I(in), end: I(in+sizeof(in)/sizeof(in[0])-1), io&: ios, err&: err, tm: &t);
91 assert(base(i) == in+sizeof(in)/sizeof(in[0])-1);
92 assert(t.tm_hour == 13);
93 assert(t.tm_min == 14);
94 assert(t.tm_sec == 15);
95 assert(err == std::ios_base::eofbit);
96 }
97
98 return 0;
99}
100

source code of libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_time_wide.pass.cpp