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 // XFAIL: android
11
12 // <locale>
13
14 // class time_put<charT, OutputIterator>
15
16 // iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
17 // char format, char modifier = 0) const;
18
19 #include <locale>
20 #include <cassert>
21 #include "test_iterators.h"
22
23 typedef std::time_put<char, output_iterator<char*> > F;
24
25 class my_facet
26 : public F
27 {
28 public:
my_facet(std::size_t refs=0)29 explicit my_facet(std::size_t refs = 0)
30 : F(refs) {}
31 };
32
main()33 int main()
34 {
35 const my_facet f(1);
36 char str[200];
37 output_iterator<char*> iter;
38 tm t = {};
39 t.tm_sec = 6;
40 t.tm_min = 3;
41 t.tm_hour = 13;
42 t.tm_mday = 2;
43 t.tm_mon = 4;
44 t.tm_year = 109;
45 t.tm_wday = 6;
46 t.tm_yday = 121;
47 t.tm_isdst = 1;
48 std::ios ios(0);
49 {
50 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'A');
51 std::string ex(str, iter.base());
52 assert(ex == "Saturday");
53 }
54 {
55 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'a');
56 std::string ex(str, iter.base());
57 assert(ex == "Sat");
58 }
59 {
60 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'B');
61 std::string ex(str, iter.base());
62 assert(ex == "May");
63 }
64 {
65 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'b');
66 std::string ex(str, iter.base());
67 assert(ex == "May");
68 }
69 {
70 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'C');
71 std::string ex(str, iter.base());
72 assert(ex == "20");
73 }
74 {
75 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'c');
76 std::string ex(str, iter.base());
77 assert(ex == "Sat May 2 13:03:06 2009");
78 }
79 {
80 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'D');
81 std::string ex(str, iter.base());
82 assert(ex == "05/02/09");
83 }
84 {
85 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'd');
86 std::string ex(str, iter.base());
87 assert(ex == "02");
88 }
89 {
90 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'c', 'E');
91 std::string ex(str, iter.base());
92 assert(ex == "Sat May 2 13:03:06 2009");
93 }
94 {
95 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'C', 'E');
96 std::string ex(str, iter.base());
97 assert(ex == "20");
98 }
99 {
100 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'x', 'E');
101 std::string ex(str, iter.base());
102 assert(ex == "05/02/09");
103 }
104 {
105 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'X', 'E');
106 std::string ex(str, iter.base());
107 assert(ex == "13:03:06");
108 }
109 {
110 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'y', 'E');
111 std::string ex(str, iter.base());
112 assert(ex == "09");
113 }
114 {
115 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'Y', 'E');
116 std::string ex(str, iter.base());
117 assert(ex == "2009");
118 }
119 {
120 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'd', 'O');
121 std::string ex(str, iter.base());
122 assert(ex == "02");
123 }
124 {
125 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'e', 'O');
126 std::string ex(str, iter.base());
127 assert(ex == " 2");
128 }
129 {
130 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'H', 'O');
131 std::string ex(str, iter.base());
132 assert(ex == "13");
133 }
134 {
135 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'I', 'O');
136 std::string ex(str, iter.base());
137 assert(ex == "01");
138 }
139 {
140 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'm', 'O');
141 std::string ex(str, iter.base());
142 assert(ex == "05");
143 }
144 {
145 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'M', 'O');
146 std::string ex(str, iter.base());
147 assert(ex == "03");
148 }
149 {
150 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'S', 'O');
151 std::string ex(str, iter.base());
152 assert(ex == "06");
153 }
154 {
155 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'u', 'O');
156 std::string ex(str, iter.base());
157 assert(ex == "6");
158 }
159 {
160 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'U', 'O');
161 std::string ex(str, iter.base());
162 assert(ex == "17");
163 }
164 {
165 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'V', 'O');
166 std::string ex(str, iter.base());
167 assert(ex == "18");
168 }
169 {
170 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'w', 'O');
171 std::string ex(str, iter.base());
172 assert(ex == "6");
173 }
174 {
175 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'W', 'O');
176 std::string ex(str, iter.base());
177 assert(ex == "17");
178 }
179 {
180 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'y', 'O');
181 std::string ex(str, iter.base());
182 assert(ex == "09");
183 }
184 {
185 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'e');
186 std::string ex(str, iter.base());
187 assert(ex == " 2");
188 }
189 {
190 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'F');
191 std::string ex(str, iter.base());
192 assert(ex == "2009-05-02");
193 }
194 {
195 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'G');
196 std::string ex(str, iter.base());
197 assert(ex == "2009");
198 }
199 {
200 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'g');
201 std::string ex(str, iter.base());
202 assert(ex == "09");
203 }
204 {
205 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'H');
206 std::string ex(str, iter.base());
207 assert(ex == "13");
208 }
209 {
210 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'h');
211 std::string ex(str, iter.base());
212 assert(ex == "May");
213 }
214 {
215 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'I');
216 std::string ex(str, iter.base());
217 assert(ex == "01");
218 }
219 {
220 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'j');
221 std::string ex(str, iter.base());
222 assert(ex == "122");
223 }
224 {
225 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'M');
226 std::string ex(str, iter.base());
227 assert(ex == "03");
228 }
229 {
230 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'm');
231 std::string ex(str, iter.base());
232 assert(ex == "05");
233 }
234 {
235 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'n');
236 std::string ex(str, iter.base());
237 assert(ex == "\n");
238 }
239 {
240 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'p');
241 std::string ex(str, iter.base());
242 assert(ex == "PM");
243 }
244 {
245 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'R');
246 std::string ex(str, iter.base());
247 assert(ex == "13:03");
248 }
249 {
250 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'r');
251 std::string ex(str, iter.base());
252 assert(ex == "01:03:06 PM");
253 }
254 {
255 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'S');
256 std::string ex(str, iter.base());
257 assert(ex == "06");
258 }
259 {
260 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'T');
261 std::string ex(str, iter.base());
262 assert(ex == "13:03:06");
263 }
264 {
265 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 't');
266 std::string ex(str, iter.base());
267 assert(ex == "\t");
268 }
269 {
270 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'U');
271 std::string ex(str, iter.base());
272 assert(ex == "17");
273 }
274 {
275 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'u');
276 std::string ex(str, iter.base());
277 assert(ex == "6");
278 }
279 {
280 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'V');
281 std::string ex(str, iter.base());
282 assert(ex == "18");
283 }
284 {
285 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'W');
286 std::string ex(str, iter.base());
287 assert(ex == "17");
288 }
289 {
290 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'w');
291 std::string ex(str, iter.base());
292 assert(ex == "6");
293 }
294 {
295 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'X');
296 std::string ex(str, iter.base());
297 assert(ex == "13:03:06");
298 }
299 {
300 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'x');
301 std::string ex(str, iter.base());
302 assert(ex == "05/02/09");
303 }
304 {
305 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'Y');
306 std::string ex(str, iter.base());
307 assert(ex == "2009");
308 }
309 {
310 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'y');
311 std::string ex(str, iter.base());
312 assert(ex == "09");
313 }
314 {
315 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'Z');
316 std::string ex(str, iter.base());
317 // assert(ex == "EDT"); depends on time zone
318 }
319 {
320 iter = f.put(output_iterator<char*>(str), ios, '*', &t, 'z');
321 std::string ex(str, iter.base());
322 // assert(ex == "-0400"); depends on time zone
323 }
324 {
325 iter = f.put(output_iterator<char*>(str), ios, '*', &t, '+');
326 std::string ex(str, iter.base());
327 // assert(ex == "Sat May 2 13:03:06 EDT 2009"); depends on time zone
328 }
329 {
330 iter = f.put(output_iterator<char*>(str), ios, '*', &t, '%');
331 std::string ex(str, iter.base());
332 assert(ex == "%");
333 }
334 }
335