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