1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <locale>
11 
12 // class time_get_byname<charT, InputIterator>
13 
14 // iter_type
15 // get_monthname(iter_type s, iter_type end, ios_base& str,
16 //               ios_base::iostate& err, tm* t) const;
17 
18 #include <locale>
19 #include <cassert>
20 #include "test_iterators.h"
21 
22 #include "platform_support.h" // locale name macros
23 
24 typedef input_iterator<const wchar_t*> I;
25 
26 typedef std::time_get_byname<wchar_t, I> F;
27 
28 class my_facet
29     : public F
30 {
31 public:
32     explicit my_facet(const std::string& nm, std::size_t refs = 0)
33         : F(nm, refs) {}
34 };
35 
36 typedef std::time_put_byname<wchar_t, wchar_t*> F2;
37 class my_facet2
38     : public F2
39 {
40 public:
41     explicit my_facet2(const std::string& nm, std::size_t refs = 0)
42         : F2(nm, refs) {}
43 };
44 
45 int main()
46 {
47     std::ios ios(0);
48     std::ios_base::iostate err;
49     std::tm t;
50     {
51         const my_facet f(LOCALE_en_US_UTF_8, 1);
52         const wchar_t in[] = L"June";
53         err = std::ios_base::goodbit;
54         t = std::tm();
55         I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
56         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
57         assert(t.tm_mon == 5);
58         assert(err == std::ios_base::eofbit);
59     }
60     {
61         const my_facet f(LOCALE_fr_FR_UTF_8, 1);
62         const wchar_t in[] = L"juin";
63         err = std::ios_base::goodbit;
64         t = std::tm();
65         I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
66         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
67         assert(t.tm_mon == 5);
68         assert(err == std::ios_base::eofbit);
69     }
70     {
71         const my_facet f(LOCALE_ru_RU_UTF_8, 1);
72         const wchar_t in[] = L"\x438\x44E\x43D\x44F";
73         err = std::ios_base::goodbit;
74         t = std::tm();
75         I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
76         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
77         assert(t.tm_mon == 5);
78         assert(err == std::ios_base::eofbit);
79     }
80     {
81         const my_facet f(LOCALE_zh_CN_UTF_8, 1);
82         const wchar_t in[] = L"\x516D\x6708";
83         err = std::ios_base::goodbit;
84         t = std::tm();
85         I i = f.get_monthname(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
86         assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
87         assert(t.tm_mon == 5);
88         assert(err == std::ios_base::eofbit);
89     }
90 }
91