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