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 get(iter_type s, iter_type end, ios_base& f,
15 // ios_base::iostate& err, tm *t, char format, char modifier = 0) const;
16
17 #include <locale>
18 #include <cassert>
19 #include "test_iterators.h"
20
21 #include "platform_support.h" // locale name macros
22
23 typedef input_iterator<const wchar_t*> I;
24
25 typedef std::time_get_byname<wchar_t, I> F;
26
27 class my_facet
28 : public F
29 {
30 public:
my_facet(const std::string & nm,std::size_t refs=0)31 explicit my_facet(const std::string& nm, std::size_t refs = 0)
32 : F(nm, refs) {}
33 };
34
main()35 int main()
36 {
37 std::ios ios(0);
38 std::ios_base::iostate err;
39 std::tm t;
40 {
41 const my_facet f(LOCALE_en_US_UTF_8, 1);
42 const wchar_t in[] = L"Sat Dec 31 23:55:59 2061";
43 err = std::ios_base::goodbit;
44 t = std::tm();
45 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
46 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
47 assert(t.tm_sec == 59);
48 assert(t.tm_min == 55);
49 assert(t.tm_hour == 23);
50 assert(t.tm_mday == 31);
51 assert(t.tm_mon == 11);
52 assert(t.tm_year == 161);
53 assert(t.tm_wday == 6);
54 assert(err == std::ios_base::eofbit);
55 }
56 {
57 const my_facet f(LOCALE_en_US_UTF_8, 1);
58 const wchar_t in[] = L"23:55:59";
59 err = std::ios_base::goodbit;
60 t = std::tm();
61 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
62 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
63 assert(t.tm_sec == 59);
64 assert(t.tm_min == 55);
65 assert(t.tm_hour == 23);
66 assert(err == std::ios_base::eofbit);
67 }
68 {
69 const my_facet f(LOCALE_fr_FR_UTF_8, 1);
70 const wchar_t in[] = L"Sam 31 d""\xE9""c 23:55:59 2061";
71 err = std::ios_base::goodbit;
72 t = std::tm();
73 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
74 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
75 assert(t.tm_sec == 59);
76 assert(t.tm_min == 55);
77 assert(t.tm_hour == 23);
78 assert(t.tm_mday == 31);
79 assert(t.tm_mon == 11);
80 assert(t.tm_year == 161);
81 assert(t.tm_wday == 6);
82 assert(err == std::ios_base::eofbit);
83 }
84 {
85 const my_facet f(LOCALE_fr_FR_UTF_8, 1);
86 const wchar_t in[] = L"23:55:59";
87 err = std::ios_base::goodbit;
88 t = std::tm();
89 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
90 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
91 assert(t.tm_sec == 59);
92 assert(t.tm_min == 55);
93 assert(t.tm_hour == 23);
94 assert(err == std::ios_base::eofbit);
95 }
96 #ifdef __APPLE__
97 {
98 const my_facet f("ru_RU", 1);
99 const wchar_t in[] = L"\x441\x443\x431\x431\x43E\x442\x430"
100 ", 31 "
101 "\x434\x435\x43A\x430\x431\x440\x44F"
102 " 2061 "
103 "\x433"
104 ". 23:55:59";
105 err = std::ios_base::goodbit;
106 t = std::tm();
107 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
108 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
109 assert(t.tm_sec == 59);
110 assert(t.tm_min == 55);
111 assert(t.tm_hour == 23);
112 assert(t.tm_mday == 31);
113 assert(t.tm_mon == 11);
114 assert(t.tm_year == 161);
115 assert(t.tm_wday == 6);
116 assert(err == std::ios_base::eofbit);
117 }
118 #endif
119 {
120 const my_facet f(LOCALE_ru_RU_UTF_8, 1);
121 const wchar_t in[] = L"23:55:59";
122 err = std::ios_base::goodbit;
123 t = std::tm();
124 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
125 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
126 assert(t.tm_sec == 59);
127 assert(t.tm_min == 55);
128 assert(t.tm_hour == 23);
129 assert(err == std::ios_base::eofbit);
130 }
131 #ifdef __APPLE__
132 {
133 const my_facet f("zh_CN", 1);
134 const wchar_t in[] = L"\x516D"
135 " 12/31 23:55:59 2061";
136 err = std::ios_base::goodbit;
137 t = std::tm();
138 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
139 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
140 assert(t.tm_sec == 59);
141 assert(t.tm_min == 55);
142 assert(t.tm_hour == 23);
143 assert(t.tm_mday == 31);
144 assert(t.tm_mon == 11);
145 assert(t.tm_year == 161);
146 assert(t.tm_wday == 6);
147 assert(err == std::ios_base::eofbit);
148 }
149 #endif
150 {
151 const my_facet f(LOCALE_zh_CN_UTF_8, 1);
152 const wchar_t in[] = L"23""\x65F6""55""\x5206""59""\x79D2";
153 err = std::ios_base::goodbit;
154 t = std::tm();
155 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
156 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
157 assert(t.tm_sec == 59);
158 assert(t.tm_min == 55);
159 assert(t.tm_hour == 23);
160 assert(err == std::ios_base::eofbit);
161 }
162 }
163