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