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// REQUIRES: locale.en_US.UTF-8
10// REQUIRES: locale.fr_FR.UTF-8
11// REQUIRES: locale.zh_CN.UTF-8
12
13// XFAIL: LIBCXX-FREEBSD-FIXME
14
15// <locale>
16
17// class time_get_byname<charT, InputIterator>
18
19// iter_type
20// get_monthname(iter_type s, iter_type end, ios_base& str,
21// ios_base::iostate& err, tm* t) const;
22
23#include <cassert>
24#include <ctime>
25#include <locale>
26
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 char*> I;
33
34typedef std::time_get_byname<char, 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 char in[] = "June";
52 err = std::ios_base::goodbit;
53 t = std::tm();
54 I i = f.get_monthname(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_mon == 5);
57 assert(err == std::ios_base::eofbit);
58 }
59 {
60 const my_facet f(LOCALE_fr_FR_UTF_8, 1);
61 const char in[] = "juin";
62 err = std::ios_base::goodbit;
63 t = std::tm();
64 I i = f.get_monthname(beg: I(in), end: I(in+sizeof(in)/sizeof(in[0])-1), io&: ios, err&: err, tm: &t);
65 assert(base(i) == in+sizeof(in)/sizeof(in[0])-1);
66 assert(t.tm_mon == 5);
67 assert(err == std::ios_base::eofbit);
68 }
69 {
70 const my_facet f(LOCALE_zh_CN_UTF_8, 1);
71 const char in[] = "\xE5\x85\xAD\xE6\x9C\x88";
72 err = std::ios_base::goodbit;
73 t = std::tm();
74 I i = f.get_monthname(beg: I(in), end: I(in+sizeof(in)/sizeof(in[0])-1), io&: ios, err&: err, tm: &t);
75 assert(base(i) == in+sizeof(in)/sizeof(in[0])-1);
76 assert(t.tm_mon == 5);
77 assert(err == std::ios_base::eofbit);
78 }
79
80 return 0;
81}
82

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