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: apple-darwin
11
12 // REQUIRES: locale.fr_FR.UTF-8
13
14 // <locale>
15
16 // class money_put<charT, OutputIterator>
17
18 // iter_type put(iter_type s, bool intl, ios_base& f, char_type fill,
19 // long double units) const;
20
21 #include <locale>
22 #include <ios>
23 #include <streambuf>
24 #include <cassert>
25 #include "test_iterators.h"
26
27 #include "platform_support.h" // locale name macros
28
29 typedef std::money_put<char, output_iterator<char*> > Fn;
30
31 class my_facet
32 : public Fn
33 {
34 public:
my_facet(std::size_t refs=0)35 explicit my_facet(std::size_t refs = 0)
36 : Fn(refs) {}
37 };
38
39 typedef std::money_put<wchar_t, output_iterator<wchar_t*> > Fw;
40
41 class my_facetw
42 : public Fw
43 {
44 public:
my_facetw(std::size_t refs=0)45 explicit my_facetw(std::size_t refs = 0)
46 : Fw(refs) {}
47 };
48
main()49 int main()
50 {
51 std::ios ios(0);
52 std::string loc_name(LOCALE_fr_FR_UTF_8);
53 ios.imbue(std::locale(ios.getloc(),
54 new std::moneypunct_byname<char, false>(loc_name)));
55 ios.imbue(std::locale(ios.getloc(),
56 new std::moneypunct_byname<char, true>(loc_name)));
57 ios.imbue(std::locale(ios.getloc(),
58 new std::moneypunct_byname<wchar_t, false>(loc_name)));
59 ios.imbue(std::locale(ios.getloc(),
60 new std::moneypunct_byname<wchar_t, true>(loc_name)));
61 {
62 const my_facet f(1);
63 // char, national
64 { // zero
65 long double v = 0;
66 char str[100];
67 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
68 false, ios, '*', v);
69 std::string ex(str, iter.base());
70 assert(ex == "0,00");
71 }
72 { // negative one
73 long double v = -1;
74 char str[100];
75 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
76 false, ios, '*', v);
77 std::string ex(str, iter.base());
78 assert(ex == "-0,01");
79 }
80 { // positive
81 long double v = 123456789;
82 char str[100];
83 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
84 false, ios, '*', v);
85 std::string ex(str, iter.base());
86 assert(ex == "1 234 567,89");
87 }
88 { // negative
89 long double v = -123456789;
90 char str[100];
91 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
92 false, ios, '*', v);
93 std::string ex(str, iter.base());
94 assert(ex == "-1 234 567,89");
95 }
96 { // zero, showbase
97 long double v = 0;
98 showbase(ios);
99 char str[100];
100 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
101 false, ios, '*', v);
102 std::string ex(str, iter.base());
103 assert(ex == "0,00 \u20ac");
104 }
105 { // negative one, showbase
106 long double v = -1;
107 showbase(ios);
108 char str[100];
109 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
110 false, ios, '*', v);
111 std::string ex(str, iter.base());
112 assert(ex == "-0,01 \u20ac");
113 }
114 { // positive, showbase
115 long double v = 123456789;
116 showbase(ios);
117 char str[100];
118 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
119 false, ios, '*', v);
120 std::string ex(str, iter.base());
121 assert(ex == "1 234 567,89 \u20ac");
122 }
123 { // negative, showbase
124 long double v = -123456789;
125 showbase(ios);
126 char str[100];
127 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
128 false, ios, '*', v);
129 std::string ex(str, iter.base());
130 assert(ex == "-1 234 567,89 \u20ac");
131 }
132 { // negative, showbase, left
133 long double v = -123456789;
134 showbase(ios);
135 ios.width(20);
136 left(ios);
137 char str[100];
138 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
139 false, ios, ' ', v);
140 std::string ex(str, iter.base());
141 assert(ex == "-1 234 567,89 \u20ac ");
142 assert(ios.width() == 0);
143 }
144 { // negative, showbase, internal
145 long double v = -123456789;
146 showbase(ios);
147 ios.width(20);
148 internal(ios);
149 char str[100];
150 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
151 false, ios, ' ', v);
152 std::string ex(str, iter.base());
153 assert(ex == "-1 234 567,89 \u20ac");
154 assert(ios.width() == 0);
155 }
156 { // negative, showbase, right
157 long double v = -123456789;
158 showbase(ios);
159 ios.width(20);
160 right(ios);
161 char str[100];
162 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
163 false, ios, ' ', v);
164 std::string ex(str, iter.base());
165 assert(ex == " -1 234 567,89 \u20ac");
166 assert(ios.width() == 0);
167 }
168
169 // char, international
170 noshowbase(ios);
171 ios.unsetf(std::ios_base::adjustfield);
172 { // zero
173 long double v = 0;
174 char str[100];
175 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
176 true, ios, '*', v);
177 std::string ex(str, iter.base());
178 assert(ex == "0,00");
179 }
180 { // negative one
181 long double v = -1;
182 char str[100];
183 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
184 true, ios, '*', v);
185 std::string ex(str, iter.base());
186 assert(ex == "-0,01");
187 }
188 { // positive
189 long double v = 123456789;
190 char str[100];
191 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
192 true, ios, '*', v);
193 std::string ex(str, iter.base());
194 assert(ex == "1 234 567,89");
195 }
196 { // negative
197 long double v = -123456789;
198 char str[100];
199 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
200 true, ios, '*', v);
201 std::string ex(str, iter.base());
202 assert(ex == "-1 234 567,89");
203 }
204 { // zero, showbase
205 long double v = 0;
206 showbase(ios);
207 char str[100];
208 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
209 true, ios, '*', v);
210 std::string ex(str, iter.base());
211 assert(ex == "0,00 EUR");
212 }
213 { // negative one, showbase
214 long double v = -1;
215 showbase(ios);
216 char str[100];
217 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
218 true, ios, '*', v);
219 std::string ex(str, iter.base());
220 assert(ex == "-0,01 EUR");
221 }
222 { // positive, showbase
223 long double v = 123456789;
224 showbase(ios);
225 char str[100];
226 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
227 true, ios, '*', v);
228 std::string ex(str, iter.base());
229 assert(ex == "1 234 567,89 EUR");
230 }
231 { // negative, showbase
232 long double v = -123456789;
233 showbase(ios);
234 char str[100];
235 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
236 true, ios, '*', v);
237 std::string ex(str, iter.base());
238 assert(ex == "-1 234 567,89 EUR");
239 }
240 { // negative, showbase, left
241 long double v = -123456789;
242 showbase(ios);
243 ios.width(20);
244 left(ios);
245 char str[100];
246 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
247 true, ios, ' ', v);
248 std::string ex(str, iter.base());
249 assert(ex == "-1 234 567,89 EUR ");
250 assert(ios.width() == 0);
251 }
252 { // negative, showbase, internal
253 long double v = -123456789;
254 showbase(ios);
255 ios.width(20);
256 internal(ios);
257 char str[100];
258 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
259 true, ios, ' ', v);
260 std::string ex(str, iter.base());
261 assert(ex == "-1 234 567,89 EUR");
262 assert(ios.width() == 0);
263 }
264 { // negative, showbase, right
265 long double v = -123456789;
266 showbase(ios);
267 ios.width(20);
268 right(ios);
269 char str[100];
270 output_iterator<char*> iter = f.put(output_iterator<char*>(str),
271 true, ios, ' ', v);
272 std::string ex(str, iter.base());
273 assert(ex == " -1 234 567,89 EUR");
274 assert(ios.width() == 0);
275 }
276 }
277 {
278 const my_facetw f(1);
279 // wchar_t, national
280 noshowbase(ios);
281 ios.unsetf(std::ios_base::adjustfield);
282 { // zero
283 long double v = 0;
284 wchar_t str[100];
285 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
286 false, ios, '*', v);
287 std::wstring ex(str, iter.base());
288 assert(ex == L"0,00");
289 }
290 { // negative one
291 long double v = -1;
292 wchar_t str[100];
293 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
294 false, ios, '*', v);
295 std::wstring ex(str, iter.base());
296 assert(ex == L"-0,01");
297 }
298 { // positive
299 long double v = 123456789;
300 wchar_t str[100];
301 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
302 false, ios, '*', v);
303 std::wstring ex(str, iter.base());
304 assert(ex == L"1 234 567,89");
305 }
306 { // negative
307 long double v = -123456789;
308 wchar_t str[100];
309 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
310 false, ios, '*', v);
311 std::wstring ex(str, iter.base());
312 assert(ex == L"-1 234 567,89");
313 }
314 { // zero, showbase
315 long double v = 0;
316 showbase(ios);
317 wchar_t str[100];
318 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
319 false, ios, '*', v);
320 std::wstring ex(str, iter.base());
321 assert(ex == L"0,00 \u20ac");
322 }
323 { // negative one, showbase
324 long double v = -1;
325 showbase(ios);
326 wchar_t str[100];
327 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
328 false, ios, '*', v);
329 std::wstring ex(str, iter.base());
330 assert(ex == L"-0,01 \u20ac");
331 }
332 { // positive, showbase
333 long double v = 123456789;
334 showbase(ios);
335 wchar_t str[100];
336 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
337 false, ios, '*', v);
338 std::wstring ex(str, iter.base());
339 assert(ex == L"1 234 567,89 \u20ac");
340 }
341 { // negative, showbase
342 long double v = -123456789;
343 showbase(ios);
344 wchar_t str[100];
345 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
346 false, ios, '*', v);
347 std::wstring ex(str, iter.base());
348 assert(ex == L"-1 234 567,89 \u20ac");
349 }
350 { // negative, showbase, left
351 long double v = -123456789;
352 showbase(ios);
353 ios.width(20);
354 left(ios);
355 wchar_t str[100];
356 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
357 false, ios, ' ', v);
358 std::wstring ex(str, iter.base());
359 assert(ex == L"-1 234 567,89 \u20ac ");
360 assert(ios.width() == 0);
361 }
362 { // negative, showbase, internal
363 long double v = -123456789;
364 showbase(ios);
365 ios.width(20);
366 internal(ios);
367 wchar_t str[100];
368 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
369 false, ios, ' ', v);
370 std::wstring ex(str, iter.base());
371 assert(ex == L"-1 234 567,89 \u20ac");
372 assert(ios.width() == 0);
373 }
374 { // negative, showbase, right
375 long double v = -123456789;
376 showbase(ios);
377 ios.width(20);
378 right(ios);
379 wchar_t str[100];
380 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
381 false, ios, ' ', v);
382 std::wstring ex(str, iter.base());
383 assert(ex == L" -1 234 567,89 \u20ac");
384 assert(ios.width() == 0);
385 }
386
387 // wchar_t, international
388 noshowbase(ios);
389 ios.unsetf(std::ios_base::adjustfield);
390 { // zero
391 long double v = 0;
392 wchar_t str[100];
393 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
394 true, ios, '*', v);
395 std::wstring ex(str, iter.base());
396 assert(ex == L"0,00");
397 }
398 { // negative one
399 long double v = -1;
400 wchar_t str[100];
401 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
402 true, ios, '*', v);
403 std::wstring ex(str, iter.base());
404 assert(ex == L"-0,01");
405 }
406 { // positive
407 long double v = 123456789;
408 wchar_t str[100];
409 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
410 true, ios, '*', v);
411 std::wstring ex(str, iter.base());
412 assert(ex == L"1 234 567,89");
413 }
414 { // negative
415 long double v = -123456789;
416 wchar_t str[100];
417 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
418 true, ios, '*', v);
419 std::wstring ex(str, iter.base());
420 assert(ex == L"-1 234 567,89");
421 }
422 { // zero, showbase
423 long double v = 0;
424 showbase(ios);
425 wchar_t str[100];
426 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
427 true, ios, '*', v);
428 std::wstring ex(str, iter.base());
429 assert(ex == L"0,00 EUR");
430 }
431 { // negative one, showbase
432 long double v = -1;
433 showbase(ios);
434 wchar_t str[100];
435 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
436 true, ios, '*', v);
437 std::wstring ex(str, iter.base());
438 assert(ex == L"-0,01 EUR");
439 }
440 { // positive, showbase
441 long double v = 123456789;
442 showbase(ios);
443 wchar_t str[100];
444 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
445 true, ios, '*', v);
446 std::wstring ex(str, iter.base());
447 assert(ex == L"1 234 567,89 EUR");
448 }
449 { // negative, showbase
450 long double v = -123456789;
451 showbase(ios);
452 wchar_t str[100];
453 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
454 true, ios, '*', v);
455 std::wstring ex(str, iter.base());
456 assert(ex == L"-1 234 567,89 EUR");
457 }
458 { // negative, showbase, left
459 long double v = -123456789;
460 showbase(ios);
461 ios.width(20);
462 left(ios);
463 wchar_t str[100];
464 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
465 true, ios, ' ', v);
466 std::wstring ex(str, iter.base());
467 assert(ex == L"-1 234 567,89 EUR ");
468 assert(ios.width() == 0);
469 }
470 { // negative, showbase, internal
471 long double v = -123456789;
472 showbase(ios);
473 ios.width(20);
474 internal(ios);
475 wchar_t str[100];
476 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
477 true, ios, ' ', v);
478 std::wstring ex(str, iter.base());
479 assert(ex == L"-1 234 567,89 EUR");
480 assert(ios.width() == 0);
481 }
482 { // negative, showbase, right
483 long double v = -123456789;
484 showbase(ios);
485 ios.width(20);
486 right(ios);
487 wchar_t str[100];
488 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str),
489 true, ios, ' ', v);
490 std::wstring ex(str, iter.base());
491 assert(ex == L" -1 234 567,89 EUR");
492 assert(ios.width() == 0);
493 }
494 }
495 }
496