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