Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
22.locale.num.put.cpp
Go to the documentation of this file.
1
29#ifdef __GNUG__
30 // prevent gcc -Wshadow warnings for convenience types
31# define ushort __rw_ushort
32# define uint __rw_uint
33# define ulong __rw_ulong
34# include <sys/types.h>
35# undef ushort
36# undef uint
37# undef ulong
38#endif // __GNUG__
39
40#include <ios>
41#include <locale>
42
43#include <cerrno> // for ERANGE, errno
44#include <cfloat> // for floating limits macros
45#include <climits> // for integral limits macros
46#include <clocale> // for LC_NUMERIC, setlocale()
47#include <cstdio> // for sprintf()
48#include <cstring> // for strcmp(), strlen()
49
50#include <rw_any.h> // for TOSTR()
51#include <rw_cmdopt.h> // for rw_enabled
52#include <rw_driver.h> // for rw_test
53#include <rw_locale.h> // for rw_locales
54#include <rw_valcmp.h> // for rw_equal
55
56
58// set by the command line option handler in response to:
59static int rw_opt_enable_num_get = 0; // --enable-num_get
60static int rw_opt_no_errno = 0; // --no-errno
61static int rw_opt_no_grouping = 0; // --no-grouping
62static int rw_opt_no_widen = 0; // --no-widen
63
64
66// replacement ctype facet
67template <class charT>
68struct Ctype: std::ctype<charT>
69{
70 typedef std::ctype<charT> Base;
71
72 typedef typename Base::char_type char_type;
73
74 static int n_widen_;
75
76 Ctype (): Base (0, 0, 1) { }
77
78 virtual char_type do_widen (char c) const {
79 ++n_widen_;
80
81 switch (c) {
82 case '0': c = '9'; break;
83 case '1': c = '8'; break;
84 case '2': c = '7'; break;
85 case '3': c = '6'; break;
86 case '4': c = '5'; break;
87 case '5': c = '4'; break;
88 case '6': c = '3'; break;
89 case '7': c = '2'; break;
90 case '8': c = '1'; break;
91 case '9': c = '0'; break;
92 default: break;
93 }
94
95 return char_type (c);
96 }
97
98 virtual const char_type*
99 do_widen (const char *lo, const char *hi, char_type *dst) const {
100 return Base::do_widen (lo, hi, dst);
101 }
102};
103
104template <class charT>
106
107
108
110// replacement numpunct facet
111
112template <class charT>
113struct Punct: std::numpunct<charT>
114{
115 typedef typename std::numpunct<charT>::char_type char_type;
116 typedef typename std::numpunct<charT>::string_type string_type;
117
120 static const char *grouping_;
121 static const char_type *truename_;
122 static const char_type *falsename_;
123
124 static int n_objs_; // number of facet objects in existence
125 static int n_thousands_sep_; // number of calls to do_thousands_sep()
126
127 Punct (std::size_t ref = 0)
128 : std::numpunct<charT>(ref) {
129 ++n_objs_;
130 }
131
133 --n_objs_;
134 }
135
136 virtual char_type do_decimal_point () const {
137 return decimal_point_;
138 }
139
140 virtual std::string do_grouping () const {
141 return grouping_;
142 }
143
144 virtual char_type do_thousands_sep () const {
146 return thousands_sep_;
147 }
148
149 virtual string_type do_truename () const {
151 }
152
153 virtual string_type do_falsename () const {
155 }
156};
157
158template <class charT>
159const char* Punct<charT>::grouping_ = "";
160
161template <class charT>
163
164template <class charT>
166
167template <class charT>
169
170template <class charT>
172
173template <class charT>
175
176template <class charT>
178
179
180
182template <class charT>
183struct Ios: std::basic_ios<charT>
184{
185 Ios () { this->init (0); }
186};
187
188
189template <class charT>
190struct NumGet: std::num_get<charT, const charT*> { NumGet () { } };
191
192
193template <class charT>
194struct NumPut: std::num_put<charT, charT*>
195{
196 typedef std::num_put<charT, charT*> Base;
197 typedef typename Base::char_type char_type;
198 typedef typename Base::iter_type iter_type;
199
200 enum {
204 };
205
206 static int ncalls_ [13];
207
208 NumPut (std::size_t ref = 0): Base (ref) { }
209
210#ifndef _RWSTD_NO_BOOL
211
212 virtual iter_type
213 do_put (iter_type it, std::ios_base &f, char_type fill, bool v) const {
214 ++ncalls_ [test_bool];
215 return Base::do_put (it, f, fill, v);
216 }
217
218#endif // _RWSTD_NO_BOOL
219
220 virtual iter_type
221 do_put (iter_type it, std::ios_base &f, char_type fill, long v) const {
222 ++ncalls_ [test_long];
223 return Base::do_put (it, f, fill, v);
224 }
225
226 virtual iter_type
227 do_put (iter_type it, std::ios_base &f, char_type fill,
228 unsigned long v) const {
230 return Base::do_put (it, f, fill, v);
231 }
232
233#ifdef _RWSTD_LONG_LONG
234
235 // provided as an extension unless _RWSTD_NO_LONG_LONG is #defined
236 virtual iter_type
237 do_put (iter_type it, std::ios_base &f, char_type fill,
238 unsigned _RWSTD_LONG_LONG v) const {
240 return Base::do_put (it, f, fill, v);
241 }
242
243 // provided as an extension unless _RWSTD_NO_LONG_LONG is #defined
244 virtual iter_type
245 do_put (iter_type it, std::ios_base &f, char_type fill,
246 _RWSTD_LONG_LONG v) const {
248 return Base::do_put (it, f, fill, v);
249 }
250
251#endif // _RWSTD_LONG_LONG
252
253 virtual iter_type
254 do_put (iter_type it, std::ios_base &f, char_type fill, double v) const {
256 return Base::do_put (it, f, fill, v);
257 }
258
259#ifndef _RWSTD_NO_LONG_DOUBLE
260
261 virtual iter_type
262 do_put (iter_type it, std::ios_base &f, char_type fill,
263 long double v) const {
265 return Base::do_put (it, f, fill, v);
266 }
267
268#endif // _RWSTD_NO_LONG_DOUBLE
269
270 virtual iter_type
271 do_put (iter_type it, std::ios_base &f, char_type fill,
272 const void *v) const {
274 return Base::do_put (it, f, fill, v);
275 }
276};
277
278
279// explicit initialization of the static array below used
280// to work around a SunPro 5.4 bug (PR #27293)
281template <class charT>
282/* static */ int NumPut<charT>::ncalls_ [13] = { 0 };
283
284
286template <class charT, class T>
287void do_test (charT /* dummy */,
288 const char *cname, // charT name
289 const char *tname, // T name
290 int lineno, // line number
291 T val, // value to format
292 int flags, // ios flags
293 std::streamsize prec, // precision
294 std::streamsize width, // field width
295 char fill, // fill character
296 const char *grouping, // grouping string
297 const char *str, // expected output
298 int err_expect = -1, // expected iostate
299 T val_expect = T () /* expected num_get result */)
300{
301 if (!rw_enabled (lineno)) {
302 rw_note (0, __FILE__, __LINE__, "test on line %d disabled", lineno);
303 return;
304 }
305
306 // create a distinct punctuation facet for each iteration to make sure
307 // any data cached in between successive calls to the facet's public
308 // member functions are flushed
309 const Punct<charT> pun (1);
310
311 Ios<charT> ios;
312 NumPut<charT> np;
313
314 ios.imbue (std::locale (ios.getloc (), (const std::numpunct<charT>*)&pun));
315
316 ios.flags (std::ios_base::fmtflags (flags));
317 ios.precision (prec);
318 ios.width (width);
319 pun.grouping_ = grouping;
320
321#if defined (_RWSTD_LDBL_MAX_10_EXP)
322
323 charT buf [_RWSTD_LDBL_MAX_10_EXP + 2] = { 0 };
324
325#else // if !defined (_RWSTD_LDBL_MAX_10_EXP)
326
327 charT buf [4096] = { 0 };
328
329#endif // _RWSTD_LDBL_MAX_10_EXP
330
331 // cast the narrow fill character to unsigned char before
332 // converting it to charT to avoid potential sign extension
333 typedef unsigned char UChar;
334 const charT wfill = charT (UChar (fill));
335
336 const charT* const bufend = np.put (buf, ios, wfill, val);
337
338 // verify 22.2.2.2.2, p21
339 if (ios.width ()) {
340
341 static int width_fail = 0;
342
343 // fail at most once for each specialization
344 rw_assert (!width_fail++, 0, lineno,
345 "line %d: num_put<%s>::put (..., %s = %s) "
346 "failed to reset width from %d; width() = %d",
347 __LINE__, cname, tname, TOSTR (val),
348 TOSTR (buf), width, ios.width ());
349 }
350
351
353 if (str) {
354
355 char cbuf [sizeof buf / sizeof *buf] = { '\0' };
356
357 if ('%' == *str) {
358 std::sprintf (cbuf, str, val);
359 str = cbuf;
360
361#ifdef _WIN32
362
363 std::size_t len = std::strlen (str);
364
365 if ( ('e' == cbuf [len - 5] || 'E' == cbuf [len - 5])
366 && ('-' == cbuf [len - 4] || '+' == cbuf [len - 4])
367 && ('0' == cbuf [len - 3])) {
368 cbuf [len - 3] = cbuf [len - 2];
369 cbuf [len - 2] = cbuf [len - 1];
370 cbuf [len - 1] = cbuf [len];
371 }
372
373#endif // _WIN32
374 }
375
376 // compare output produced by num_put with that produced by printf()
377 rw_assert (0 == rw_strncmp (buf, str), 0, lineno,
378 "line %d: num_put<%s>::put (..., %s = %s) "
379 "wrote %{*Ac}, expected %{*Ac}, "
380 "flags = %{If}, precision = %d"
381 "%{?}, grouping = \"%#s\"%{;}",
382 __LINE__, cname, tname, TOSTR (val),
383 sizeof *buf, buf, sizeof *str, str,
384 flags, prec,
385 grouping && *grouping, grouping);
386 }
387
388
390#ifndef NO_NUM_GET
391
392 if (!rw_opt_enable_num_get)
393 return;
394
395 // skip negative precision (extension requiring special treatment)
396 if (prec < 0)
397 return;
398
399 const charT *next = buf;
400
401 // skip leading fill characters (if any)
402 for ( ; *next == fill; ++next);
403
404 // find the first non-fill character if it exists
405 const charT *last = next;
406 for ( ; *last && *last != fill; ++last);
407 for ( ; *last && *last == fill; ++last);
408
409 // do not perform extraction if there are any fill characters
410 // in the middle of output (they serve as punctuators and break
411 // up the input sequence)
412 if (next != last && *last)
413 return;
414
415 // do not perform extraction if the fill character is the minus
416 // sign, the plus sign, the thousands separator, the decimal point,
417 // or a digit
418 if ( '-' == fill
419 || '+' == fill
420 || pun.thousands_sep_ == fill
421 || pun.decimal_point_ == fill
422 || (fill >= '0' && fill <= '9'))
423 return;
424
425 // do not perform extraction if there is no data to extract
426 // (unless this is an extraction-only test)
427 if (!*next && str)
428 return;
429
430 NumGet<charT> ng;
431
432 T x = T ();
433
434 std::ios_base::iostate err = std::ios_base::goodbit;
435
436 if (-1 == err_expect) {
437
438 // lwg issue 17: special treatment for bool:
439
440 // The in iterator is always left pointing one position beyond
441 // the last character successfully matched. If val is set, then
442 // err is set to str.goodbit; or to str.eofbit if, when seeking
443 // another character to match, it is found that (in==end). If
444 // val is not set, then err is set to str.failbit; or to
445 // (str.failbit|str.eofbit) if the reason for the failure was
446 // that (in==end). [Example: for targets true:"a" and false:"abb",
447 // the input sequence "a" yields val==true and err==str.eofbit;
448 // the input sequence "abc" yields err=str.failbit, with in ending
449 // at the 'c' element. For targets true:"1" and false:"0", the
450 // input sequence "1" yields val==true and err=str.goodbit. For
451 // empty targets (""), any input sequence yields err==str.failbit.
452 // --end example]
453
454 err_expect = T (1) == T (2) && flags & std::ios::boolalpha
455 ? std::ios::goodbit
456 : last == bufend && last [-1] != fill
457 ? std::ios::eofbit : std::ios::goodbit;
458
459 val_expect = val;
460 }
461
462 last = ng.get (next, bufend, ios, err, x);
463
464 // verify the state
465 rw_assert (err == err_expect, 0, lineno,
466 "line %d: num_get<%s>::get (%s, ..., %s&) "
467 "flags = %{If}, "
468 "%{?}grouping = \"%#s\", %{;}"
469 "iostate = %{Is}, expected %{Is}",
470 __LINE__, cname,
471 TOSTR (next), tname,
472 flags,
473 grouping && *grouping, grouping,
474 err, err_expect);
475
476 // verify the parsed value
477 rw_assert (rw_equal (x, val_expect), 0, lineno,
478 "line %d: num_get<%s>::get (%s, ..., %s&) got %s, "
479 "expected %s, flags = %{If}, "
480 "%{?}grouping = \"%#s\", %{;}",
481 __LINE__, cname,
482 TOSTR (next), tname,
483 TOSTR (x), TOSTR (val_expect),
484 flags,
485 grouping && *grouping, grouping);
486
487#else
488
489 _RWSTD_UNUSED (bufend);
490 _RWSTD_UNUSED (err_expect);
491 _RWSTD_UNUSED (val_expect);
492
493#endif // NO_NUM_GET
494
495}
496
497
499template <class charT>
500struct Streambuf: std::basic_streambuf<charT, std::char_traits<charT> > { };
501
502template <class charT>
503void direct_use_test (charT, const char *cname)
504{
505 _RWSTD_UNUSED (cname);
506
507 // verify that num_put objects can be used directly w/o first
508 // having been installed in a locale object; the behavior of
509 // such facets is unspecified (but not undefined)
510
511 Ios<charT> ios;
512
513 const std::num_put<charT> np;
514
516
517#define DIRECT_USE_TEST(T) \
518 np.put (std::ostreambuf_iterator<charT>(&sb), ios, charT (), (T)0)
519
520#ifndef _RWSTD_NO_BOOL
521
522 DIRECT_USE_TEST (bool);
523
524#endif // _RWSTD_NO_BOOL
525
526 DIRECT_USE_TEST (unsigned long);
527 DIRECT_USE_TEST (long);
528 DIRECT_USE_TEST (double);
529
530#ifndef _RWSTD_NO_LONG_DOUBLE
531
532 DIRECT_USE_TEST (long double);
533
534#endif
535
536 DIRECT_USE_TEST (void*);
537}
538
539
542// for convenience
543#define boolalpha std::ios_base::boolalpha
544#define dec std::ios_base::dec
545#define fixed std::ios_base::fixed
546#define hex std::ios_base::hex
547#define internal std::ios_base::internal
548#define left std::ios_base::left
549#define oct std::ios_base::oct
550#define right std::ios_base::right
551#define scientific std::ios_base::scientific
552#define showbase std::ios_base::showbase
553#define showpoint std::ios_base::showpoint
554#define showpos std::ios_base::showpos
555#define skipws std::ios_base::skipws
556#define unitbuf std::ios_base::unitbuf
557#define uppercase std::ios_base::uppercase
558#define bin std::ios_base::bin
559#define adjustfield std::ios_base::adjustfield
560#define basefield std::ios_base::basefield
561#define floatfield std::ios_base::floatfield
562#define nolock std::ios_base::nolock
563#define nolockbuf std::ios_base::nolockbuf
564
565#define Bad std::ios_base::badbit
566#define Eof std::ios_base::eofbit
567#define Fail std::ios_base::failbit
568#define Good std::ios_base::goodbit
569
570
571template <class charT>
572void bool_test (charT, const char *cname)
573{
574#ifndef _RWSTD_NO_BOOL
575
576 rw_info (0, 0, __LINE__, "std::num_put<%s>::put (..., bool)", cname);
577
578 const char* const tname = "bool";
579
580 static const charT boolnames[][4] = {
581 { 'y', 'e', 's', '\0' }, { 'n', 'o', '.', '\0' },
582
583 // unusual strings to try to trip up the formatting algorithm
584 { '+', '1', '\0' }, { '-', '2', '\0' },
585 { '-', '+', '1', '\0' }, { '+', '-', '0', '\0' },
586 { '\001', '\0' }, { '\0' }
587 };
588
590 Punct<charT>::truename_ = boolnames [0];
591 Punct<charT>::falsename_ = boolnames [1];
592
593// set line number to __LINE__ and perform test so that
594// assertion output will point to the failed TEST line
595#define TEST do_test
596#define T charT (), cname, tname, __LINE__
597
598
599 TEST (T, false, 0, 0, 0, ' ', "", "0");
600 TEST (T, true, 0, 0, 0, ' ', "", "1");
601
602 TEST (T, false, 0, 0, 0, ' ', "", "%d");
603 TEST (T, true, 0, 0, 0, ' ', "", "%d");
604
605 TEST (T, false, showpos, 0, 0, ' ', "", "%+d");
606 TEST (T, true, showpos, 0, 0, ' ', "", "%+d");
607
608 TEST (T, false, oct, 0, 0, ' ', "", "%o");
609 TEST (T, true, oct, 0, 0, ' ', "", "%o");
610
611 TEST (T, false, dec, 0, 0, ' ', "", "%d");
612 TEST (T, true, dec, 0, 0, ' ', "", "%d");
613
614 TEST (T, false, hex, 0, 0, ' ', "", "%x");
615 TEST (T, true, hex, 0, 0, ' ', "", "%x");
616
617 rw_info (0, 0, __LINE__, "std::ios::boolalpha");
618
619 TEST (T, false, boolalpha, 0, 0, ' ', "", "no.");
620 TEST (T, true, boolalpha, 0, 0, ' ', "", "yes");
621
622 // left justified boolalpha
623 TEST (T, false, boolalpha | left, 0, 6, ' ', "", "no. ");
624 TEST (T, true, boolalpha | left, 0, 6, ' ', "", "yes ");
625
626 // right justified boolalpha
627 TEST (T, false, boolalpha | right, 0, 6, ' ', "", " no.");
628 TEST (T, true, boolalpha | right, 0, 6, ' ', "", " yes");
629
630 // implied right justified boolalpha (internal bit set)
631 TEST (T, false, boolalpha | internal, 0, 4, ' ', "", " no.");
632 TEST (T, true, boolalpha | internal, 0, 4, ' ', "", " yes");
633
634
635 Punct<charT>::truename_ = boolnames [2];
636 Punct<charT>::falsename_ = boolnames [3];
637
638 TEST (T, false, boolalpha, 0, 1, ' ', "", "-2");
639 TEST (T, true, boolalpha, 0, 1, ' ', "", "+1");
640
641 TEST (T, false, boolalpha | internal, 0, 4, ' ', "", " -2");
642 TEST (T, true, boolalpha | internal, 0, 4, ' ', "", " +1");
643
644
645 Punct<charT>::truename_ = boolnames [4];
646 Punct<charT>::falsename_ = boolnames [5];
647
648 TEST (T, false, boolalpha, 0, 1, ' ', "", "+-0");
649 TEST (T, true, boolalpha, 0, 1, ' ', "", "-+1");
650
651 TEST (T, false, boolalpha | internal, 0, 4, ' ', "", " +-0");
652 TEST (T, true, boolalpha | internal, 0, 4, ' ', "", " -+1");
653
654
655 Punct<charT>::truename_ = boolnames [6];
656 Punct<charT>::falsename_ = boolnames [7];
657
658 TEST (T, false, boolalpha, 0, 0, ' ', "", "");
659 TEST (T, true, boolalpha, 0, 0, ' ', "", "\001");
660
661 TEST (T, false, boolalpha, 0, 1, ' ', "", " ");
662 TEST (T, true, boolalpha, 0, 1, ' ', "", "\001");
663
664 TEST (T, false, boolalpha, 0, 1, ',', "", ",");
665 TEST (T, true, boolalpha, 0, 1, ',', "", "\001");
666
667 TEST (T, false, boolalpha | internal, 0,4, ',', "", ",,,,");
668 TEST (T, true, boolalpha | internal, 0,4, ',', "", ",,,\001");
669
670#endif // _RWSTD_NO_BOOL
671
672}
673
674
676template <class charT>
677void long_test (charT, const char *cname)
678{
679 const char* const tname = "long";
680
681 rw_info (0, 0, __LINE__, "std::num_put<%s>::put (..., %s)", cname, tname);
682
683// working around a VAC++/AIX bug where LONG_{MIN,MAX} are
684// of type int rather than long as required (see PR #28798)
685#undef LONG_MIN
686#define LONG_MIN _RWSTD_LONG_MIN
687
688#undef LONG_MAX
689#define LONG_MAX _RWSTD_LONG_MAX
690
691#undef GET_FAIL
692#define GET_FAIL (Eof | Fail), LONG_MAX
693
695 // implicit decimal output
696 rw_info (0, 0, __LINE__, "std::ios::fmtflags ()");
697
698 TEST (T, 0L, 0, 0, 0, ' ', "", "%ld");
699 TEST (T, 1L, 0, 0, 0, ' ', "", "%ld");
700 TEST (T, 2L, 0, 0, 0, ' ', "", "%ld");
701 TEST (T, -3L, 0, 0, 0, ' ', "", "%ld");
702 TEST (T, 12L, 0, 0, 0, ' ', "", "%ld");
703 TEST (T, -13L, 0, 0, 0, ' ', "", "%ld");
704 TEST (T, 345L, 0, 0, 0, ' ', "", "%ld");
705 TEST (T, -456L, 0, 0, 0, ' ', "", "%ld");
706 TEST (T, 6789L, 0, 0, 0, ' ', "", "%ld");
707 TEST (T, -7890L, 0, 0, 0, ' ', "", "%ld");
708 TEST (T, 98765L, 0, 0, 0, ' ', "", "%ld");
709 TEST (T, -98766L, 0, 0, 0, ' ', "", "%ld");
710 TEST (T, LONG_MAX, 0, 0, 0, ' ', "", "%ld");
711 TEST (T, LONG_MIN, 0, 0, 0, ' ', "", "%ld");
712
714 // explicit decimal ouptut
715 rw_info (0, 0, __LINE__, "std::ios::dec");
716
717 TEST (T, 0L, dec, 0, 0, ' ', "", "%ld");
718 TEST (T, 1L, dec, 0, 0, ' ', "", "%ld");
719 TEST (T, 2L, dec, 0, 0, ' ', "", "%ld");
720 TEST (T, 12L, dec, 0, 0, ' ', "", "%ld");
721 TEST (T, 345L, dec, 0, 0, ' ', "", "%ld");
722 TEST (T, 6789L, dec, 0, 0, ' ', "", "%ld");
723 TEST (T, 98765L, dec, 0, 0, ' ', "", "%ld");
724 TEST (T, LONG_MAX, dec, 0, 0, ' ', "", "%ld");
725
726 TEST (T, ~0L, dec, 0, 0, ' ', "", "%ld");
727 TEST (T, -1L, dec, 0, 0, ' ', "", "%ld");
728 TEST (T, -2L, dec, 0, 0, ' ', "", "%ld");
729 TEST (T, -12L, dec, 0, 0, ' ', "", "%ld");
730 TEST (T, -345L, dec, 0, 0, ' ', "", "%ld");
731 TEST (T, -6789L, dec, 0, 0, ' ', "", "%ld");
732 TEST (T, -98765L, dec, 0, 0, ' ', "", "%ld");
733 TEST (T, LONG_MIN, dec, 0, 0, ' ', "", "%ld");
734
735 rw_info (0, 0, __LINE__, "std::ios::dec | std::ios::showbase");
736
737 TEST (T, 0L, dec | showbase, 0, 0, ' ', "", "%#ld");
738 TEST (T, 1234L, dec | showbase, 0, 0, ' ', "", "%#ld");
739 TEST (T, -1235L, dec | showbase, 0, 0, ' ', "", "%#ld");
740 TEST (T, LONG_MAX, dec | showbase, 0, 0, ' ', "", "%#ld");
741 TEST (T, LONG_MIN, dec | showbase, 0, 0, ' ', "", "%#ld");
742
743 rw_info (0, 0, __LINE__, "std::ios::dec | std::ios::showpos");
744
745 TEST (T, 0L, dec | showpos, 0, 0, ' ', "", "%+ld");
746 TEST (T, 1236L, dec | showpos, 0, 0, ' ', "", "%+ld");
747 TEST (T, -1237L, dec | showpos, 0, 0, ' ', "", "%+ld");
748 TEST (T, LONG_MAX, dec | showpos, 0, 0, ' ', "", "%+ld");
749 TEST (T, LONG_MIN, dec | showpos, 0, 0, ' ', "", "%+ld");
750
751 rw_info (0, 0, __LINE__,
752 "std::ios::dec | std::ios::showbase | std::ios::showpos");
753
754 TEST (T, 0L, dec | showbase | showpos, 0, 0, ' ', "", "%#+ld");
755 TEST (T, 1238L, dec | showbase | showpos, 0, 0, ' ', "", "%#+ld");
756 TEST (T, -1239L, dec | showbase | showpos, 0, 0, ' ', "", "%#+ld");
757 TEST (T, LONG_MAX, dec | showbase | showpos, 0, 0, ' ', "", "%#+ld");
758 TEST (T, LONG_MIN, dec | showbase | showpos, 0, 0, ' ', "", "%#+ld");
759
760 // left justfication
761 rw_info (0, 0, __LINE__, "std::ios::dec | std::ios::left");
762
763 TEST (T, 0L, dec | left, 0, 10, ' ', "", "%-10ld");
764 TEST (T, 1L, dec | left, 0, 10, ' ', "", "%-10ld");
765 TEST (T, 12L, dec | left, 0, 10, ' ', "", "%-10ld");
766 TEST (T, 123L, dec | left, 0, 10, ' ', "", "%-10ld");
767 TEST (T, 1234L, dec | left, 0, 10, ' ', "", "%-10ld");
768 TEST (T, 12345L, dec | left, 0, 10, ' ', "", "%-10ld");
769 TEST (T, 123456L, dec | left, 0, 10, ' ', "", "%-10ld");
770 TEST (T, 1234567L, dec | left, 0, 10, ' ', "", "%-10ld");
771 TEST (T, 12345678L, dec | left, 0, 10, ' ', "", "%-10ld");
772 TEST (T, 123456789L, dec | left, 0, 10, ' ', "", "%-10ld");
773
774 // left justfication, signed dec
775 TEST (T, -1L, dec | left, 0, 10, ' ', "", "-1 ");
776 TEST (T, -12L, dec | left, 0, 10, ' ', "", "-12 ");
777 TEST (T, -123L, dec | left, 0, 10, ' ', "", "-123 ");
778 TEST (T, -1234L, dec | left, 0, 10, ' ', "", "-1234 ");
779 TEST (T, -12345L, dec | left, 0, 10, ' ', "", "-12345 ");
780 TEST (T, -123456L, dec | left, 0, 10, ' ', "", "-123456 ");
781 TEST (T, -1234567L, dec | left, 0, 10, ' ', "", "-1234567 ");
782 TEST (T, -12345678L, dec | left, 0, 10, ' ', "", "-12345678 ");
783 TEST (T, -123456789L, dec | left, 0, 10, ' ', "", "-123456789");
784
785 // left justification with fill char
786 TEST (T, -1L, dec | left, 0, 10, '#', "", "-1########");
787 TEST (T, -12L, dec | left, 0, 10, '@', "", "-12@@@@@@@");
788 TEST (T, -123L, dec | left, 0, 10, '*', "", "-123******");
789 TEST (T, -1234L, dec | left, 0, 10, '=', "", "-1234=====");
790 TEST (T, -12345L, dec | left, 0, 10, '.', "", "-12345....");
791 TEST (T, -123456L, dec | left, 0, 10, ',', "", "-123456,,,");
792 TEST (T, -1234567L, dec | left, 0, 10, '-', "", "-1234567--");
793 TEST (T, -12345678L, dec | left, 0, 10, '+', "", "-12345678+");
794 TEST (T, -123456789L, dec | left, 0, 10, ';', "", "-123456789");
795
796 // left justfication with grouping
797 TEST (T, 1L, dec | left, 0, 14, ' ', "\2", "1 ");
798 TEST (T, 12L, dec | left, 0, 14, ' ', "\2", "12 ");
799 TEST (T, 123L, dec | left, 0, 14, ' ', "\2", "1,23 ");
800 TEST (T, 1234L, dec | left, 0, 14, ' ', "\2", "12,34 ");
801 TEST (T, 12345L, dec | left, 0, 14, ' ', "\2", "1,23,45 ");
802 TEST (T, 123456L, dec | left, 0, 14, ' ', "\2", "12,34,56 ");
803 TEST (T, 1234567L, dec | left, 0, 14, ' ', "\2", "1,23,45,67 ");
804 TEST (T, 12345678L, dec | left, 0, 14, ' ', "\2", "12,34,56,78 ");
805 TEST (T, 123456789L, dec | left, 0, 14, ' ', "\2", "1,23,45,67,89 ");
806 TEST (T, 123456789L, dec | left, 0, 14, ',', "\2", "1,23,45,67,89,");
807
808 TEST (T, 1L, dec | left, 0, 14, ' ', "\2\1\3", "1 ");
809 TEST (T, 12L, dec | left, 0, 14, ' ', "\2\1\3", "12 ");
810 TEST (T, 123L, dec | left, 0, 14, ' ', "\2\1\3", "1,23 ");
811 TEST (T, 1234L, dec | left, 0, 14, ' ', "\2\1\3", "1,2,34 ");
812 TEST (T, 12345L, dec | left, 0, 14, ' ', "\2\1\3", "12,3,45 ");
813 TEST (T, 123456L, dec | left, 0, 14, ' ', "\2\1\3", "123,4,56 ");
814 TEST (T, 1234567L, dec | left, 0, 14, ' ', "\2\1\3", "1,234,5,67 ");
815 TEST (T, 12345678L, dec | left, 0, 14, ' ', "\2\1\3", "12,345,6,78 ");
816 TEST (T, 123456789L, dec | left, 0, 14, ' ', "\2\1\3", "123,456,7,89 ");
817 TEST (T, 123456789L, dec | left, 0, 14, '0', "\2\1\3", "123,456,7,8900");
818
819 TEST (T, -1L, dec | left, 0, 14, ' ', "\1\2\3", "-1 ");
820 TEST (T, -12L, dec | left, 0, 14, ' ', "\1\2\3", "-1,2 ");
821 TEST (T, -123L, dec | left, 0, 14, ' ', "\1\2\3", "-12,3 ");
822 TEST (T, -1234L, dec | left, 0, 14, ' ', "\1\2\3", "-1,23,4 ");
823 TEST (T, -12345L, dec | left, 0, 14, ' ', "\1\2\3", "-12,34,5 ");
824 TEST (T, -123456L, dec | left, 0, 14, ' ', "\1\2\3", "-123,45,6 ");
825 TEST (T, -1234567L, dec | left, 0, 14, ' ', "\1\2\3", "-1,234,56,7 ");
826 TEST (T, -12345678L, dec | left, 0, 14, ' ', "\1\2\3", "-12,345,67,8 ");
827 TEST (T, -123456789L, dec | left, 0, 14, ' ', "\1\2\3", "-123,456,78,9 ");
828 TEST (T, -123456789L, dec | left, 0, 14, ' ', "\3\1\2", "-1,23,45,6,789");
829
830 TEST (T, -123456780L, dec | left, 0, 14, ' ', "\x1", "-1,2,3,4,5,6,7,8,0");
831
832 TEST (T, -123456781L, dec | left, 0, 14, ' ', "\x2", "-1,23,45,67,81");
833 TEST (T, -123456782L, dec | left, 0, 14, ' ', "\x3", "-123,456,782 ");
834 TEST (T, -123456783L, dec | left, 0, 14, ' ', "\x4", "-1,2345,6783 ");
835 TEST (T, -123456784L, dec | left, 0, 14, ' ', "\x5", "-1234,56784 ");
836 TEST (T, -123456785L, dec | left, 0, 14, ' ', "\x6", "-123,456785 ");
837 TEST (T, -123456786L, dec | left, 0, 14, ' ', "\x7", "-12,3456786 ");
838 TEST (T, -123456787L, dec | left, 0, 14, ' ', "\x8", "-1,23456787 ");
839 TEST (T, -123456788L, dec | left, 0, 14, ' ', "\x9", "-123456788 ");
840
841#ifndef _RWSTD_NO_EXT_BIN_IO
842
843 rw_info (0, 0, __LINE__, "std::ios::dec | std::ios::bin [extension]");
844
845 TEST (T, 33333333L, bin | dec, 0, 0, ' ', "", "%ld");
846
847#endif // _RWSTD_NO_EXT_BIN_IO
848
850 // explicit octal ouptut
851 rw_info (0, 0, __LINE__, "std::ios::oct");
852
853 TEST (T, 0L, oct, 0, 0, ' ', "", "%lo");
854 TEST (T, 1L, oct, 0, 0, ' ', "", "%lo");
855 TEST (T, 2L, oct, 0, 0, ' ', "", "%lo");
856 TEST (T, 12L, oct, 0, 0, ' ', "", "%lo");
857 TEST (T, 345L, oct, 0, 0, ' ', "", "%lo");
858 TEST (T, 6789L, oct, 0, 0, ' ', "", "%lo");
859 TEST (T, 98765L, oct, 0, 0, ' ', "", "%lo");
860 TEST (T, LONG_MAX, oct, 0, 0, ' ', "", "%lo");
861
862 TEST (T, LONG_MAX - 1, oct, 0, 0, ' ', "", "%lo");
863
864 // negative values formatted as oct cause overflow on input (lwg issue 23)
865 TEST (T, ~0L, oct, 0, 0, ' ', "", "%lo", GET_FAIL);
866 TEST (T, -1L, oct, 0, 0, ' ', "", "%lo", GET_FAIL);
867 TEST (T, -2L, oct, 0, 0, ' ', "", "%lo", GET_FAIL);
868 TEST (T, -12L, oct, 0, 0, ' ', "", "%lo", GET_FAIL);
869 TEST (T, -345L, oct, 0, 0, ' ', "", "%lo", GET_FAIL);
870 TEST (T, -6789L, oct, 0, 0, ' ', "", "%lo", GET_FAIL);
871 TEST (T, -98765L, oct, 0, 0, ' ', "", "%lo", GET_FAIL);
872 TEST (T, LONG_MIN, oct, 0, 0, ' ', "", "%lo", GET_FAIL);
873
874 rw_info (0, 0, __LINE__, "std::ios::oct | std::ios::dec");
875
876 TEST (T, 13579L, oct | dec, 0, 0, ' ', "", "%ld");
877
878 rw_info (0, 0, __LINE__, "std::ios::oct | std::ios::showbase");
879
880 TEST (T, 0L, oct | showbase, 0, 0, ' ', "", "%#lo");
881 TEST (T, 2345L, oct | showbase, 0, 0, ' ', "", "%#lo");
882 TEST (T, -2346L, oct | showbase, 0, 0, ' ', "", "%#lo", GET_FAIL);
883 TEST (T, LONG_MAX, oct | showbase, 0, 0, ' ', "", "%#+lo");
884 TEST (T, LONG_MIN, oct | showbase, 0, 0, ' ', "", "%#+lo", GET_FAIL);
885
886 rw_info (0, 0, __LINE__, "std::ios::oct | std::ios::showpos");
887
888 TEST (T, 0L, oct | showpos, 0, 0, ' ', "", "%+lo");
889 TEST (T, 2347L, oct | showpos, 0, 0, ' ', "", "%+lo");
890 TEST (T, -2348L, oct | showpos, 0, 0, ' ', "", "%+lo", GET_FAIL);
891
892 TEST (T, LONG_MAX, oct | showpos, 0, 0, ' ', "", "%+lo");
893 TEST (T, LONG_MIN, oct | showpos, 0, 0, ' ', "", "%+lo", GET_FAIL);
894
895 rw_info (0, 0, __LINE__,
896 "std::ios::oct | std::ios::showbase | std::ios::showpos");
897
898 TEST (T, 0L, oct | showbase | showpos, 0, 0, ' ', "", "%#+lo");
899 TEST (T, 2349L, oct | showbase | showpos, 0, 0, ' ', "", "%#+lo");
900 TEST (T, -2350L, oct | showbase | showpos, 0, 0, ' ', "", "%#+lo",
901 GET_FAIL);
902
903 TEST (T, LONG_MAX, oct | showbase | showpos, 0, 0, ' ', "", "%#+lo");
904 TEST (T, LONG_MIN, oct | showbase | showpos, 0, 0, ' ', "", "%#+lo",
905 GET_FAIL);
906
907#ifndef _RWSTD_NO_EXT_BIN_IO
908
909 rw_info (0, 0, __LINE__, "std::ios::oct | std::ios::bin [extension]");
910
911 TEST (T, 22222222L, bin | oct, 0, 0, ' ', "", "%ld");
912
913#endif // _RWSTD_NO_EXT_BIN_IO
914
916 // explicit hexadecimal ouptut
917 rw_info (0, 0, __LINE__, "std::ios::hex");
918
919 TEST (T, 0L, hex, 0, 0, ' ', "", "%lx");
920 TEST (T, 1L, hex, 0, 0, ' ', "", "%lx");
921 TEST (T, 2L, hex, 0, 0, ' ', "", "%lx");
922 TEST (T, 12L, hex, 0, 0, ' ', "", "%lx");
923 TEST (T, 345L, hex, 0, 0, ' ', "", "%lx");
924 TEST (T, 6789L, hex, 0, 0, ' ', "", "%lx");
925 TEST (T, 98765L, hex, 0, 0, ' ', "", "%lx");
926 TEST (T, LONG_MAX, hex, 0, 0, ' ', "", "%lx");
927 TEST (T, LONG_MAX - 1, hex, 0, 0, ' ', "", "%lx");
928 TEST (T, LONG_MAX - 2, hex, 0, 0, ' ', "", "%lx");
929
930 // negative values formatted as hex cause overflow on input (lwg issue 23)
931 TEST (T, ~0L, hex, 0, 0, ' ', "", "%lx", GET_FAIL);
932 TEST (T, -1L, hex, 0, 0, ' ', "", "%lx", GET_FAIL);
933 TEST (T, -2L, hex, 0, 0, ' ', "", "%lx", GET_FAIL);
934 TEST (T, -12L, hex, 0, 0, ' ', "", "%lx", GET_FAIL);
935 TEST (T, -345L, hex, 0, 0, ' ', "", "%lx", GET_FAIL);
936 TEST (T, -6789L, hex, 0, 0, ' ', "", "%lx", GET_FAIL);
937 TEST (T, -98765L, hex, 0, 0, ' ', "", "%lx", GET_FAIL);
938 TEST (T, LONG_MIN, hex, 0, 0, ' ', "", "%lx", GET_FAIL);
939
940 rw_info (0, 0, __LINE__, "std::ios::hex | std::ios::uppercase");
941
942 TEST (T, 0L, hex | uppercase, 0, 0, ' ', "", "%lX");
943 TEST (T, 1L, hex | uppercase, 0, 0, ' ', "", "%lX");
944 TEST (T, 0XABCDL, hex | uppercase, 0, 0, ' ', "", "%lX");
945 TEST (T, 0XBCDEL, hex | uppercase, 0, 0, ' ', "", "%lX");
946 TEST (T, 0XCDEFL, hex | uppercase, 0, 0, ' ', "", "%lX");
947
948 rw_info (0, 0, __LINE__, "std::ios::hex | std::ios::showbase");
949
950 TEST (T, 0L, hex | showbase, 0, 0, ' ', "", "%#lx");
951 TEST (T, 1L, hex | showbase, 0, 0, ' ', "", "%#lx");
952 TEST (T, 0xdef1L, hex | showbase, 0, 0, ' ', "", "%#lx");
953
954 rw_info (0, 0, __LINE__,
955 "std::ios::hex | std::ios::uppercase | std::ios::showbase");
956
957 TEST (T, 0L, hex | uppercase | showbase, 0, 0, ' ', "", "%#lX");
958 TEST (T, 1L, hex | uppercase | showbase, 0, 0, ' ', "", "%#lX");
959 TEST (T, 0XEF02L, hex | uppercase | showbase, 0, 0, ' ', "", "%#lX");
960
961 rw_info (0, 0, __LINE__, "std::ios::hex | std::ios::oct");
962
963 TEST (T, 0L, oct | hex, 0, 0, ' ', "", "%ld");
964 TEST (T, 97531L, oct | hex, 0, 0, ' ', "", "%ld");
965
966 rw_info (0, 0, __LINE__, "std::ios::hex | std::ios::dec");
967
968 TEST (T, 86420L, dec | hex, 0, 0, ' ', "", "%ld");
969
970 rw_info (0, 0, __LINE__, "std::ios::hex | std::ios::dec | std::ios::oct");
971
972 TEST (T, 11111111L, oct | dec | hex, 0, 0, ' ', "", "%ld");
973
974#ifndef _RWSTD_NO_EXT_BIN_IO
975
976 rw_info (0, 0, __LINE__, "std::ios::hex | std::ios::bin [extension]");
977
978 TEST (T, 44444444L, bin | hex, 0, 0, ' ', "", "%ld");
979
980 rw_info (0, 0, __LINE__, "std::ios::hex | std::ios::dec | "
981 "std::ios::oct | std::ios::bin [extension]");
982
983 TEST (T, 55555555L, bin | oct | dec | hex, 0, 0, ' ', "", "%ld");
984
985#endif // _RWSTD_NO_EXT_BIN_IO
986
987
989 // extension: fixed and negative precision
990
991 rw_info (0, 0, __LINE__,
992 "std::ios::fixed with negative precision [extension]");
993
994 TEST (T, 987654321L, 0, -1, 0, ' ', "", "987654321");
995 TEST (T, 987654322L, fixed, 0, 0, ' ', "", "987654322");
996 TEST (T, 987654323L, fixed, -1, 0, ' ', "", "98765432*3");
997 TEST (T, -987654323L, fixed, -1, 0, ' ', "", "-98765432*3");
998 TEST (T, 987654324L, fixed, -2, 0, ' ', "", "9876543*24");
999 TEST (T, -987654324L, fixed, -2, 0, ' ', "", "-9876543*24");
1000 TEST (T, 987654325L, fixed, -3, 0, ' ', "", "987654*325");
1001 TEST (T, -987654325L, fixed, -3, 0, ' ', "", "-987654*325");
1002 TEST (T, 987654326L, fixed, -4, 0, ' ', "", "98765*4326");
1003 TEST (T, -987654326L, fixed, -4, 0, ' ', "", "-98765*4326");
1004 TEST (T, 987654327L, fixed, -5, 0, ' ', "", "9876*54327");
1005 TEST (T, -987654327L, fixed, -5, 0, ' ', "", "-9876*54327");
1006 TEST (T, 987654328L, fixed, -6, 0, ' ', "", "987*654328");
1007 TEST (T, -987654328L, fixed, -6, 0, ' ', "", "-987*654328");
1008 TEST (T, 987654329L, fixed, -7, 0, ' ', "", "98*7654329");
1009 TEST (T, -987654329L, fixed, -7, 0, ' ', "", "-98*7654329");
1010 TEST (T, 987654330L, fixed, -8, 0, ' ', "", "9*87654330");
1011 TEST (T, -987654330L, fixed, -8, 0, ' ', "", "-9*87654330");
1012 TEST (T, 987654331L, fixed, -9, 0, ' ', "", "0*987654331");
1013 TEST (T, -987654331L, fixed, -9, 0, ' ', "", "-0*987654331");
1014 TEST (T, 987654332L, fixed, -10, 0, ' ', "", "0*0987654332");
1015 TEST (T, -987654332L, fixed, -10, 0, ' ', "", "-0*0987654332");
1016 TEST (T, 987654333L, fixed, -11, 0, ' ', "", "0*00987654333");
1017 TEST (T, -987654333L, fixed, -11, 0, ' ', "", "-0*00987654333");
1018 TEST (T, 0L, fixed, -12, 0, ' ', "", "0*000000000000");
1019
1021
1022// second group is the last group (i.e., prevent repetition)
1023#if CHAR_MAX == UCHAR_MAX
1024# define GROUPING "\2\1\xff"
1025#else
1026# define GROUPING "\2\1\x7f"
1027#endif
1028
1029 TEST (T, 123456789L, dec | left, 0, 0, ' ', GROUPING, "123456,7,89");
1030 TEST (T, -123456789L, dec | left, 0, 0, ' ', GROUPING, "-123456,7,89");
1031
1032#undef GROUPING
1033
1034#if CHAR_MAX == UCHAR_MAX
1035# define GROUPING "\2\3\xff"
1036#else
1037# define GROUPING "\2\3\x7f"
1038#endif
1039
1040 TEST (T, 123456789L, dec | left, 0, 0, ' ', GROUPING, "1234,567,89");
1041 TEST (T, -123456789L, dec | left, 0, 0, ' ', GROUPING, "-1234,567,89");
1042
1043 TEST (T, 0x12345678L, hex | showbase, 0, 0, ' ', GROUPING, "0x123,456,78");
1044
1046 // right justfication
1047 rw_info (0, 0, __LINE__, "std::ios::right");
1048
1049 TEST (T, 1L, dec | right, 0, 10, ' ', "", " 1");
1050 TEST (T, 12L, dec | right, 0, 10, ' ', "", " 12");
1051 TEST (T, 123L, dec | right, 0, 10, ' ', "", " 123");
1052 TEST (T, 1234L, dec | right, 0, 10, ' ', "", " 1234");
1053 TEST (T, 12345L, dec | right, 0, 10, ' ', "", " 12345");
1054 TEST (T, 123456L, dec | right, 0, 10, ' ', "", " 123456");
1055 TEST (T, 1234567L, dec | right, 0, 10, ' ', "", " 1234567");
1056 TEST (T, 12345678L, dec | right, 0, 10, ' ', "", " 12345678");
1057 TEST (T, 123456789L, dec | right, 0, 10, ' ', "", " 123456789");
1058 TEST (T, 123456789L, dec | right, 0, 10, '0', "", "0123456789");
1059 TEST (T, 123456789L, dec | right, 0, 10, '+', "", "+123456789");
1060 TEST (T, 123456789L, dec | right, 0, 10, '-', "", "-123456789");
1061
1062 // right justification, oct
1063 TEST (T, 0L, oct | right, 0, 10, ' ', "", " 0");
1064 TEST (T, 01L, oct | right, 0, 10, ' ', "", " 1");
1065 TEST (T, 012L, oct | right, 0, 10, ' ', "", " 12");
1066 TEST (T, 0123L, oct | right, 0, 10, ' ', "", " 123");
1067 TEST (T, 01234L, oct | right, 0, 10, ' ', "", " 1234");
1068 TEST (T, 012345L, oct | right, 0, 10, ' ', "", " 12345");
1069 TEST (T, 0123456L, oct | right, 0, 10, ' ', "", " 123456");
1070 TEST (T, 01234567L, oct | right, 0, 10, ' ', "", " 1234567");
1071 TEST (T, 012345670L, oct | right, 0, 10, ' ', "", " 12345670");
1072 TEST (T, 012345670L, oct | right, 0, 10, '1', "", "1112345670");
1073
1074 // right justification with grouping
1075 TEST (T, 0L, oct | right, 0, 10, ' ', "\2", " 0");
1076 TEST (T, 01L, oct | right, 0, 10, ' ', "\2", " 1");
1077 TEST (T, 012L, oct | right, 0, 10, ' ', "\2", " 12");
1078 TEST (T, 0123L, oct | right, 0, 10, ' ', "\2", " 1,23");
1079 TEST (T, 01234L, oct | right, 0, 10, ' ', "\2", " 12,34");
1080 TEST (T, 012345L, oct | right, 0, 10, ' ', "\2", " 1,23,45");
1081 TEST (T, 0123456L, oct | right, 0, 10, ' ', "\2", " 12,34,56");
1082 TEST (T, 01234567L, oct | right, 0, 10, ' ', "\2", "1,23,45,67");
1083 TEST (T, 012345670L, oct | right, 0, 10, ' ', "\2", "12,34,56,70");
1084
1085#undef FLAGS
1086#define flags hex | showbase | internal
1087#define FLAGS flags | uppercase
1088
1089 // internal justfication, hex
1090 rw_info (0, 0, __LINE__, "std::ios::internal");
1091 TEST (T, 0X1L, FLAGS, 0, 10, ' ', "", "0X 1");
1092 TEST (T, 0x12L, flags, 0, 10, ' ', "", "0x 12");
1093 TEST (T, 0X123L, FLAGS, 0, 10, ' ', "", "0X 123");
1094 TEST (T, 0x1234L, flags, 0, 10, ' ', "", "0x 1234");
1095 TEST (T, 0X12345L, FLAGS, 0, 10, ' ', "", "0X 12345");
1096 TEST (T, 0x123abcL, flags, 0, 10, ' ', "", "0x 123abc");
1097 TEST (T, 0x123abcL, flags, 0, 10, '0', "", "0x00123abc");
1098 TEST (T, 0X1234ABCL, FLAGS, 0, 10, ' ', "", "0X 1234ABC");
1099 TEST (T, 0X12345678L, FLAGS, 0, 10, ' ', "", "0X12345678");
1100 TEST (T, 0X12345678L, FLAGS, 0, 10, '0', "", "0X12345678");
1101
1102 // internal justfication, hex, grouping
1103 TEST (T, 0X1L, FLAGS, 0, 10, ' ', "\1\2", "0X 1");
1104 TEST (T, 0x12L, flags, 0, 10, ' ', "\1\2", "0x 1,2");
1105 TEST (T, 0X123L, FLAGS, 0, 10, ' ', "\1\2", "0X 12,3");
1106 TEST (T, 0x1234L, flags, 0, 10, ' ', "\1\2", "0x 1,23,4");
1107 TEST (T, 0X12345L, FLAGS, 0, 10, ' ', "\1\2", "0X 12,34,5");
1108 TEST (T, 0X12345L, FLAGS, 0, 10, ',', "\1\2", "0X,12,34,5");
1109 TEST (T, 0x123abcL, flags, 0, 10, ' ', "\1\2", "0x1,23,ab,c");
1110 TEST (T, 0X1234ABCL, FLAGS, 0, 10, ' ', "\1\2", "0X12,34,AB,C");
1111 TEST (T, 0X12345678L, FLAGS, 0, 10, ' ', "\1\2", "0X1,23,45,67,8");
1112 TEST (T, 0X12345678L, FLAGS, 0, 10, '0', "\1\2", "0X1,23,45,67,8");
1113
1114#undef flags
1115#undef FLAGS
1116#define FLAGS dec | showpos | internal
1117
1118 // internal justfication, signed dec
1119 TEST (T, 0L, FLAGS, 0, 10, ' ', "", "+ 0");
1120 TEST (T, -1L, FLAGS, 0, 10, ' ', "", "- 1");
1121 TEST (T, +12L, FLAGS, 0, 10, ' ', "", "+ 12");
1122 TEST (T, -123L, FLAGS, 0, 10, ' ', "", "- 123");
1123 TEST (T, +1234L, FLAGS, 0, 10, ' ', "", "+ 1234");
1124 TEST (T, -12345L, FLAGS, 0, 10, ' ', "", "- 12345");
1125 TEST (T, +123456L, FLAGS, 0, 10, ' ', "", "+ 123456");
1126 TEST (T, -1234567L, FLAGS, 0, 10, ' ', "", "- 1234567");
1127 TEST (T, +12345678L, FLAGS, 0, 10, ' ', "", "+ 12345678");
1128 TEST (T, -123456789L, FLAGS, 0, 10, '0', "", "-123456789");
1129
1130 TEST (T, +1L, FLAGS, 0, 10, '-', "", "+--------1");
1131 TEST (T, -12L, FLAGS, 0, 10, '-', "", "--------12");
1132 TEST (T, +123L, FLAGS, 0, 10, '+', "", "+++++++123");
1133 TEST (T, -1234L, FLAGS, 0, 10, '+', "", "-+++++1234");
1134 TEST (T, +12345L, FLAGS, 0, 10, '0', "", "+000012345");
1135 TEST (T, -123456L, FLAGS, 0, 10, '1', "", "-111123456");
1136 TEST (T, +1234567L, FLAGS, 0, 10, '2', "", "+221234567");
1137 TEST (T, -12345678L, FLAGS, 0, 10, '3', "", "-312345678");
1138 TEST (T, +123456789L, FLAGS, 0, 10, '4', "", "+123456789");
1139
1140#ifndef _RWSTD_NO_EXT_BIN_IO
1141
1142 // bin
1143 rw_info (0, 0, __LINE__, "std::ios::bin [extension]");
1144
1145 TEST (T, 0L, bin, 0, 16, '.', "\4", "...............0");
1146 TEST (T, 1L, bin, 0, 16, '.', "\4", "...............1");
1147 TEST (T, 2L, bin, 0, 16, '.', "\4", "..............10");
1148 TEST (T, 3L, bin, 0, 16, '.', "\4", "..............11");
1149 TEST (T, 4L, bin, 0, 16, '.', "\4", ".............100");
1150 TEST (T, 5L, bin, 0, 16, '.', "\4", ".............101");
1151 TEST (T, 6L, bin, 0, 16, '.', "\4", ".............110");
1152 TEST (T, 7L, bin, 0, 16, '.', "\4", ".............111");
1153 TEST (T, 8L, bin, 0, 16, '.', "\4", "............1000");
1154 TEST (T, 9L, bin, 0, 16, '.', "\4", "............1001");
1155 TEST (T, 0x0aL, bin, 0, 16, '.', "\4", "............1010");
1156 TEST (T, 0x0bL, bin, 0, 16, '.', "\4", "............1011");
1157 TEST (T, 0x0cL, bin, 0, 16, '.', "\4", "............1100");
1158 TEST (T, 0x0dL, bin, 0, 16, '.', "\4", "............1101");
1159 TEST (T, 0x0eL, bin, 0, 16, '.', "\4", "............1110");
1160 TEST (T, 0x0fL, bin, 0, 16, '.', "\4", "............1111");
1161
1162 TEST (T, 0xf0L, bin, 0, 16, '.', "\4", ".......1111,0000");
1163 TEST (T, 0xf1L, bin, 0, 16, '.', "\4", ".......1111,0001");
1164 TEST (T, 0xf2L, bin, 0, 16, '.', "\4", ".......1111,0010");
1165 TEST (T, 0xf3L, bin, 0, 16, '.', "\4", ".......1111,0011");
1166 TEST (T, 0xf4L, bin, 0, 16, '.', "\4", ".......1111,0100");
1167 TEST (T, 0xf5L, bin, 0, 16, '.', "\4", ".......1111,0101");
1168
1169 TEST (T, 0x12345678L, bin, 0, 0, '.', "\4",
1170 "1,0010,0011,0100,0101,0110,0111,1000");
1171
1172 TEST (T, 0xfedcba98L, bin, 0, 0, '\0', "\010",
1173 "11111110,11011100,10111010,10011000");
1174
1175#endif // _RWSTD_NO_EXT_BIN_IO
1176
1177 // locale 3.0 extension
1178
1179#define BASE(n) int (unsigned (n) << _RWSTD_IOS_BASEOFF)
1180
1181 // bases 0 and 10 are both base 10
1182 // base 1 is roman (values 1 through 4999)
1183 // bases 2 through 36 are what they are
1184 // anything else is unspecified
1185
1186 rw_info (0, 0, __LINE__, "base 1 (Roman), and 2 through 36 [extension]");
1187
1188 TEST (T, 1234L, BASE ( 0), 0, 0, '\0', "", "1234");
1189 TEST (T, 1234L, BASE ( 1), 0, 0, '\0', "", "mccxxxiv");
1190 TEST (T, 0x1234L, BASE ( 2), 0, 0, '\0', "", "1001000110100");
1191
1192 TEST (T, 01234L, oct | BASE ( 8), 0, 0, '\0', "", "1234");
1193 TEST (T, 1234L, dec | BASE (10), 0, 0, '\0', "", "1234");
1194 TEST (T, 0x1234L, hex | BASE (16), 0, 0, '\0', "", "1234");
1195
1196 TEST (T, 1234L, BASE ( 2), 0, 0, '\0', "", "10011010010");
1197 TEST (T, 1234L, BASE ( 3), 0, 0, '\0', "", "1200201");
1198 TEST (T, 1234L, BASE ( 4), 0, 0, '\0', "", "103102");
1199 TEST (T, 1234L, BASE ( 5), 0, 0, '\0', "", "14414");
1200 TEST (T, 1234L, BASE ( 6), 0, 0, '\0', "", "5414");
1201 TEST (T, 1234L, BASE ( 7), 0, 0, '\0', "", "3412");
1202 TEST (T, 1234L, BASE ( 9), 0, 0, '\0', "", "1621");
1203
1204 TEST (T, 1234L, dec | BASE (10), 0, 0, '\0', "", "1234");
1205
1206 TEST (T, 1234L, BASE (11), 0, 0, '\0', "", "a22");
1207 TEST (T, 1234L, BASE (12), 0, 0, '\0', "", "86a");
1208 TEST (T, 1234L, BASE (13), 0, 0, '\0', "", "73c");
1209 TEST (T, 1234L, BASE (14), 0, 0, '\0', "", "642");
1210 TEST (T, 1234L, BASE (15), 0, 0, '\0', "", "574");
1211
1212 TEST (T, 1234L, hex | BASE (16), 0, 0, '\0', "", "4d2");
1213
1214 TEST (T, 1234L, BASE (17), 0, 0, '\0', "", "44a");
1215 TEST (T, 1234L, BASE (18), 0, 0, '\0', "", "3ea");
1216 TEST (T, 1234L, BASE (19), 0, 0, '\0', "", "37i");
1217 TEST (T, 1234L, BASE (20), 0, 0, '\0', "", "31e");
1218 TEST (T, 1234L, BASE (21), 0, 0, '\0', "", "2gg");
1219 TEST (T, 1234L, BASE (22), 0, 0, '\0', "", "2c2");
1220 TEST (T, 1234L, BASE (23), 0, 0, '\0', "", "27f");
1221 TEST (T, 1234L, BASE (24), 0, 0, '\0', "", "23a");
1222 TEST (T, 1234L, BASE (25), 0, 0, '\0', "", "1o9");
1223 TEST (T, 1234L, BASE (26), 0, 0, '\0', "", "1lc");
1224 TEST (T, 1234L, BASE (27), 0, 0, '\0', "", "1ij");
1225 TEST (T, 1234L, BASE (28), 0, 0, '\0', "", "1g2");
1226 TEST (T, 1234L, BASE (29), 0, 0, '\0', "", "1dg");
1227 TEST (T, 1234L, BASE (30), 0, 0, '\0', "", "1b4");
1228 TEST (T, 1234L, BASE (31), 0, 0, '\0', "", "18p");
1229 TEST (T, 1234L, BASE (32), 0, 0, '\0', "", "16i");
1230 TEST (T, 1234L, BASE (33), 0, 0, '\0', "", "14d");
1231 TEST (T, 1234L, BASE (34), 0, 0, '\0', "", "12a");
1232 TEST (T, 1234L, BASE (35), 0, 0, '\0', "", "109");
1233 TEST (T, 1234L, BASE (36), 0, 0, '\0', "", "ya");
1234
1235 // effect of non-empty grouping is unspecified
1236 TEST (T, 0L, BASE (1), 0, 0, '\0', "", "0");
1237 TEST (T, 1L, BASE (1), 0, 0, '\0', "", "i");
1238 TEST (T, 2L, BASE (1), 0, 0, '\0', "", "ii");
1239 TEST (T, 3L, BASE (1), 0, 0, '\0', "", "iii");
1240 TEST (T, 4L, BASE (1), 0, 0, '\0', "", "iv");
1241 TEST (T, 5L, BASE (1), 0, 0, '\0', "", "v");
1242 TEST (T, 6L, BASE (1), 0, 0, '\0', "", "vi");
1243 TEST (T, 7L, BASE (1), 0, 0, '\0', "", "vii");
1244 TEST (T, 8L, BASE (1), 0, 0, '\0', "", "viii");
1245 TEST (T, 9L, BASE (1), 0, 0, '\0', "", "ix");
1246 TEST (T, 10L, BASE (1), 0, 0, '\0', "", "x");
1247 TEST (T, 50L, BASE (1), 0, 0, '\0', "", "l");
1248 TEST (T, 100L, BASE (1), 0, 0, '\0', "", "c");
1249 TEST (T, 500L, BASE (1), 0, 0, '\0', "", "d");
1250 TEST (T, 1000L, BASE (1), 0, 0, '\0', "", "m");
1251 TEST (T, 49L, BASE (1), 0, 0, '\0', "", "xlix");
1252 TEST (T, 88L, BASE (1), 0, 0, '\0', "", "lxxxviii");
1253 TEST (T, 99L, BASE (1), 0, 0, '\0', "", "xcix");
1254 TEST (T, 1999L, BASE (1), 0, 0, '\0', "", "mcmxcix");
1255 TEST (T, 2000L, BASE (1), 0, 0, '\0', "", "mm");
1256 TEST (T, 2001L, BASE (1), 0, 0, '\0', "", "mmi");
1257 TEST (T, 4999L, BASE (1), 0, 0, '\0', "", "mmmmcmxcix");
1258 TEST (T, 5000L, BASE (1), 0, 0, '\0', "", "5000");
1259
1260 TEST (T, 1492L, BASE (1), 0, 10, '*', "", "***mcdxcii");
1261
1262 TEST (T, 1776L, BASE (1) | uppercase, 0, 0, '\0', "", "MDCCLXXVI");
1263}
1264
1265
1266
1268template <class charT>
1269void ulong_test (charT, const char *cname)
1270{
1271 const char* const tname = "unsigned long";
1272
1273 rw_info (0, 0, __LINE__, "std::num_put<%s>::put (..., %s)", cname, tname);
1274
1275 typedef unsigned long ULong;
1276
1278 rw_info (0, 0, __LINE__, "std::ios::dec");
1279
1280 TEST (T, 0UL, dec, 0, 0, ' ', "", "%lu");
1281 TEST (T, ULong (LONG_MAX), dec, 0, 0, ' ', "", "%lu");
1282
1283 rw_info (0, 0, __LINE__, "std::ios::dec | std::ios::shopos");
1284
1285 TEST (T, 0UL, dec | showpos, 0, 0, ' ', "", "%+lu");
1286 TEST (T, 1UL, dec | showpos, 0, 0, ' ', "", "%+lu");
1287 TEST (T, ULong (LONG_MAX), dec | showpos, 0, 0, ' ', "", "%+lu");
1288
1290 rw_info (0, 0, __LINE__, "std::ios::oct");
1291
1292 TEST (T, ULong (CHAR_MAX), oct, 0, 0, ' ', "", "%lo");
1293 TEST (T, ULong (UCHAR_MAX), oct, 0, 0, ' ', "", "%lo");
1294 TEST (T, ULong (SCHAR_MAX), oct, 0, 0, ' ', "", "%lo");
1295 TEST (T, ULong (SHRT_MAX), oct, 0, 0, ' ', "", "%lo");
1296 TEST (T, ULong (USHRT_MAX), oct, 0, 0, ' ', "", "%lo");
1297 TEST (T, ULong (INT_MAX), oct, 0, 0, ' ', "", "%lo");
1298 TEST (T, ULong (UINT_MAX), oct, 0, 0, ' ', "", "%lo");
1299 TEST (T, ULong (LONG_MAX), oct, 0, 0, ' ', "", "%lo");
1300
1301 TEST (T, ULong (CHAR_MIN), oct, 0, 0, ' ', "", "%lo");
1302 TEST (T, ULong (SCHAR_MIN), oct, 0, 0, ' ', "", "%lo");
1303 TEST (T, ULong (SHRT_MIN), oct, 0, 0, ' ', "", "%lo");
1304 TEST (T, ULong (INT_MIN), oct, 0, 0, ' ', "", "%lo");
1305 TEST (T, ULong (LONG_MIN), oct, 0, 0, ' ', "", "%lo");
1306
1307 // no overflow
1308 TEST (T, 1UL, oct, 0, 0, ' ', "", "%lo");
1309 TEST (T, ~0UL, oct, 0, 0, ' ', "", "%lo");
1310 TEST (T, ULong (ULONG_MAX), oct, 0, 0, ' ', "", "%lo");
1311
1313 rw_info (0, 0, __LINE__, "std::ios::hex");
1314
1315 TEST (T, ULong (CHAR_MAX), hex, 0, 0, ' ', "", "%lx");
1316 TEST (T, ULong (UCHAR_MAX), hex, 0, 0, ' ', "", "%lx");
1317 TEST (T, ULong (SCHAR_MAX), hex, 0, 0, ' ', "", "%lx");
1318 TEST (T, ULong (SHRT_MAX), hex, 0, 0, ' ', "", "%lx");
1319 TEST (T, ULong (USHRT_MAX), hex, 0, 0, ' ', "", "%lx");
1320 TEST (T, ULong (INT_MAX), hex, 0, 0, ' ', "", "%lx");
1321 TEST (T, ULong (UINT_MAX), hex, 0, 0, ' ', "", "%lx");
1322 TEST (T, ULong (LONG_MAX), hex, 0, 0, ' ', "", "%lx");
1323
1324 TEST (T, ULong (CHAR_MIN), hex, 0, 0, ' ', "", "%lx");
1325 TEST (T, ULong (SCHAR_MIN), hex, 0, 0, ' ', "", "%lx");
1326 TEST (T, ULong (SHRT_MIN), hex, 0, 0, ' ', "", "%lx");
1327 TEST (T, ULong (INT_MIN), hex, 0, 0, ' ', "", "%lx");
1328 TEST (T, ULong (LONG_MIN), hex, 0, 0, ' ', "", "%lx");
1329
1330 TEST (T, 1UL, hex, 0, 0, ' ', "", "%lx");
1331 TEST (T, ~0UL, hex, 0, 0, ' ', "", "%lx");
1332 TEST (T, ULong (ULONG_MAX), hex, 0, 0, ' ', "", "%lx");
1333}
1334
1335
1336
1338template <class charT>
1339void llong_test (charT, const char *cname)
1340{
1341 const char* const tname = "long long";
1342
1343 rw_info (0, 0, 0, "std::num_put<%s>::put (..., %s)", cname, tname);
1344
1345#ifndef _RWSTD_NO_LONG_LONG
1346
1347# define STDIO_FMAT "%" _RWSTD_LLONG_PRINTF_PREFIX "d"
1348
1349# ifndef _MSC_VER
1350# define LL(number) number ## LL
1351# else // if defined (_MSC_VER)
1352 // MSVC 7.0 doesn't recognize the LL suffix
1353# define LL(number) number ## I64
1354# endif // _MSC_VER
1355
1356 TEST (T, LL (0), dec, 0, 0, ' ', "", STDIO_FMAT);
1357 TEST (T, LL (1), dec, 0, 0, ' ', "", STDIO_FMAT);
1358 TEST (T, LL (21), dec, 0, 0, ' ', "", STDIO_FMAT);
1359 TEST (T, LL (321), dec, 0, 0, ' ', "", STDIO_FMAT);
1360 TEST (T, LL (4321), dec, 0, 0, ' ', "", STDIO_FMAT);
1361 TEST (T, LL (54321), dec, 0, 0, ' ', "", STDIO_FMAT);
1362 TEST (T, LL (654321), dec, 0, 0, ' ', "", STDIO_FMAT);
1363 TEST (T, LL (7654321), dec, 0, 0, ' ', "", STDIO_FMAT);
1364 TEST (T, LL (87654321), dec, 0, 0, ' ', "", STDIO_FMAT);
1365 TEST (T, LL (987654321), dec, 0, 0, ' ', "", STDIO_FMAT);
1366
1367 TEST (T, ~LL (0), dec, 0, 0, ' ', "", STDIO_FMAT);
1368 TEST (T, -LL (1), dec, 0, 0, ' ', "", STDIO_FMAT);
1369 TEST (T, -LL (21), dec, 0, 0, ' ', "", STDIO_FMAT);
1370 TEST (T, -LL (321), dec, 0, 0, ' ', "", STDIO_FMAT);
1371 TEST (T, -LL (4321), dec, 0, 0, ' ', "", STDIO_FMAT);
1372 TEST (T, -LL (54321), dec, 0, 0, ' ', "", STDIO_FMAT);
1373 TEST (T, -LL (654321), dec, 0, 0, ' ', "", STDIO_FMAT);
1374 TEST (T, -LL (7654321), dec, 0, 0, ' ', "", STDIO_FMAT);
1375 TEST (T, -LL (87654321), dec, 0, 0, ' ', "", STDIO_FMAT);
1376 TEST (T, -LL (987654321), dec, 0, 0, ' ', "", STDIO_FMAT);
1377
1378# undef FLAGS
1379# define FLAGS hex | showbase | internal
1380
1381# undef OPTS
1382# define OPTS FLAGS, 0, 20, ' ', "\1\2\3\4\1\2\3\4"
1383
1384 // internal justfication, hex format, grouping
1385 TEST (T, LL (0), OPTS, " 0");
1386 TEST (T, LL (0x1), OPTS, "0x 1");
1387 TEST (T, LL (0x12), OPTS, "0x 1,2");
1388 TEST (T, LL (0x123), OPTS, "0x 12,3");
1389 TEST (T, LL (0x1234), OPTS, "0x 1,23,4");
1390 TEST (T, LL (0x12345), OPTS, "0x 12,34,5");
1391 TEST (T, LL (0x123456), OPTS, "0x 123,45,6");
1392 TEST (T, LL (0x1234567), OPTS, "0x 1,234,56,7");
1393 TEST (T, LL (0x12345678), OPTS, "0x 12,345,67,8");
1394 TEST (T, LL (0x123456789), OPTS, "0x 123,456,78,9");
1395 TEST (T, LL (0x123456789a), OPTS, "0x 1234,567,89,a");
1396 TEST (T, LL (0x123456789ab), OPTS, "0x 1,2345,678,9a,b");
1397 TEST (T, LL (0x123456789abc), OPTS, "0x 1,2,3456,789,ab,c");
1398 TEST (T, LL (0x123456789abcd), OPTS, "0x12,3,4567,89a,bc,d");
1399 TEST (T, LL (0x123456789abcde), OPTS, "0x1,23,4,5678,9ab,cd,e");
1400 TEST (T, LL (0x123456789abcdef), OPTS, "0x12,34,5,6789,abc,de,f");
1401 TEST (T, LL (0x123456789abcdef0), OPTS, "0x123,45,6,789a,bcd,ef,0");
1402
1403#else // if defined (_RWSTD_NO_LONG_LONG)
1404
1405 rw_note (0, 0, __LINE__, "num_put<%s>::put (..., %s) not exercised, "
1406 "macro _RWSTD_NO_LONG_LONG #defined",
1407 cname, tname);
1408
1409#endif // _RWSTD_LONG_LONG
1410}
1411
1412
1413
1415template <class charT>
1416void ullong_test (charT, const char *cname)
1417{
1418 const char* const tname = "unsigned long long";
1419
1420 rw_info (0, 0, 0, "std::num_put<%s>::put (..., %s)", cname, tname);
1421
1422#ifndef _RWSTD_NO_LONG_LONG
1423
1424 rw_warn (0, 0, __LINE__, "num_put<%s>::put (..., %s) not exercised",
1425 cname, tname);
1426
1427#else // if defined (_RWSTD_NO_LONG_LONG)
1428
1429 rw_note (0, 0, __LINE__, "num_put<%s>::put (..., %s) not exercised, "
1430 "macro _RWSTD_NO_LONG_LONG #defined",
1431 cname, tname);
1432
1433#endif // _RWSTD_NO_LONG_LONG
1434}
1435
1436
1438// use a volatile variable to fool optimizers into not issuing
1439// warnings about division by zero
1440volatile double zero;
1441
1442
1443template <class charT, class floatT>
1444void inf_nan_test (charT, floatT, const char *cname, const char *tname)
1445{
1446 rw_info (0, 0, 0, "std::num_put<%s>::put (..., %s) formatting "
1447 "infinities", cname, tname);
1448
1449 // compute infinity
1450 const floatT inf = 1 / zero;
1451
1453 // exercise the formatting of positive and negative infinities
1454
1455 // +-- value to format
1456 // | +-- fmtflags
1457 // | | +-- precision
1458 // | | | +-- field width
1459 // | | | | +-- fill character
1460 // | | | | | +-- grouping
1461 // | | | | | | +-- expected output
1462 // | | | | | | |
1463 // V V V V V V V
1464 TEST (T, inf, 0, 0, 0, ' ', "", "inf");
1465 TEST (T, inf, showpos, 0, 0, ' ', "", "+inf");
1466 TEST (T, inf, uppercase, 0, 0, ' ', "", "INF");
1467 TEST (T, inf, showpos | uppercase, 0, 0, ' ', "", "+INF");
1468
1469 TEST (T, -inf, 0, 0, 0, ' ', "", "-inf");
1470 TEST (T, -inf, showpos, 0, 0, ' ', "", "-inf");
1471 TEST (T, -inf, uppercase, 0, 0, ' ', "", "-INF");
1472 TEST (T, -inf, showpos | uppercase, 0, 0, ' ', "", "-INF");
1473
1474 TEST (T, inf, 0, 1, 0, ' ', "", "inf");
1475 TEST (T, inf, showpos, 1, 0, ' ', "", "+inf");
1476 TEST (T, inf, uppercase, 1, 0, ' ', "", "INF");
1477 TEST (T, inf, showpos | uppercase, 1, 0, ' ', "", "+INF");
1478
1479 TEST (T, -inf, 0, 1, 0, ' ', "", "-inf");
1480 TEST (T, -inf, showpos, 1, 0, ' ', "", "-inf");
1481 TEST (T, -inf, uppercase, 1, 0, ' ', "", "-INF");
1482 TEST (T, -inf, showpos | uppercase, 1, 0, ' ', "", "-INF");
1483
1484 TEST (T, inf, 0, 3, 0, ' ', "", "inf");
1485 TEST (T, inf, showpos, 3, 0, ' ', "", "+inf");
1486 TEST (T, inf, uppercase, 3, 0, ' ', "", "INF");
1487 TEST (T, inf, showpos | uppercase, 3, 0, ' ', "", "+INF");
1488
1489 TEST (T, -inf, 0, 3, 0, ' ', "", "-inf");
1490 TEST (T, -inf, showpos, 3, 0, ' ', "", "-inf");
1491 TEST (T, -inf, uppercase, 3, 0, ' ', "", "-INF");
1492 TEST (T, -inf, showpos | uppercase, 3, 0, ' ', "", "-INF");
1493
1494 TEST (T, inf, 0, 4, 0, ' ', "", "inf");
1495 TEST (T, inf, showpos, 4, 0, ' ', "", "+inf");
1496 TEST (T, inf, uppercase, 4, 0, ' ', "", "INF");
1497 TEST (T, inf, showpos | uppercase, 4, 0, ' ', "", "+INF");
1498
1499 TEST (T, -inf, 0, 4, 0, ' ', "", "-inf");
1500 TEST (T, -inf, showpos, 4, 0, ' ', "", "-inf");
1501 TEST (T, -inf, uppercase, 4, 0, ' ', "", "-INF");
1502 TEST (T, -inf, showpos | uppercase, 4, 0, ' ', "", "-INF");
1503
1504 TEST (T, inf, 0, 9, 0, ' ', "", "inf");
1505 TEST (T, inf, showpos, 9, 0, ' ', "", "+inf");
1506 TEST (T, inf, uppercase, 9, 0, ' ', "", "INF");
1507 TEST (T, inf, showpos | uppercase, 9, 0, ' ', "", "+INF");
1508
1509 TEST (T, -inf, 0, 9, 0, ' ', "", "-inf");
1510 TEST (T, -inf, showpos, 9, 0, ' ', "", "-inf");
1511 TEST (T, -inf, uppercase, 9, 0, ' ', "", "-INF");
1512 TEST (T, -inf, showpos | uppercase, 9, 0, ' ', "", "-INF");
1513
1514 TEST (T, inf, 0, 0, 1, ' ', "", "inf");
1515 TEST (T, inf, showpos, 0, 1, ' ', "", "+inf");
1516 TEST (T, inf, uppercase, 0, 1, ' ', "", "INF");
1517 TEST (T, inf, showpos | uppercase, 0, 1, ' ', "", "+INF");
1518
1519 TEST (T, -inf, 0, 0, 1, ' ', "", "-inf");
1520 TEST (T, -inf, showpos, 0, 1, ' ', "", "-inf");
1521 TEST (T, -inf, uppercase, 0, 1, ' ', "", "-INF");
1522 TEST (T, -inf, showpos | uppercase, 0, 1, ' ', "", "-INF");
1523
1524 TEST (T, inf, 0, 0, 3, ' ', "", "inf");
1525 TEST (T, inf, showpos, 0, 3, ' ', "", "+inf");
1526 TEST (T, inf, uppercase, 0, 3, ' ', "", "INF");
1527 TEST (T, inf, showpos | uppercase, 0, 3, ' ', "", "+INF");
1528
1529 TEST (T, -inf, 0, 0, 3, ' ', "", "-inf");
1530 TEST (T, -inf, showpos, 0, 3, ' ', "", "-inf");
1531 TEST (T, -inf, uppercase, 0, 3, ' ', "", "-INF");
1532 TEST (T, -inf, showpos | uppercase, 0, 3, ' ', "", "-INF");
1533
1534 TEST (T, inf, 0, 0, 4, ' ', "", " inf");
1535 TEST (T, inf, showpos, 0, 4, ' ', "", "+inf");
1536 TEST (T, inf, uppercase, 0, 4, ' ', "", " INF");
1537 TEST (T, inf, showpos | uppercase, 0, 4, ' ', "", "+INF");
1538
1539 TEST (T, -inf, 0, 0, 4, ' ', "", "-inf");
1540 TEST (T, -inf, showpos, 0, 4, ' ', "", "-inf");
1541 TEST (T, -inf, uppercase, 0, 4, ' ', "", "-INF");
1542 TEST (T, -inf, showpos | uppercase, 0, 4, ' ', "", "-INF");
1543
1544 TEST (T, inf, 0, 0, 8, ' ', "", " inf");
1545 TEST (T, inf, showpos, 0, 8, ' ', "", " +inf");
1546 TEST (T, inf, uppercase, 0, 8, ' ', "", " INF");
1547 TEST (T, inf, showpos | uppercase, 0, 8, ' ', "", " +INF");
1548
1549 TEST (T, -inf, 0, 0, 8, ' ', "", " -inf");
1550 TEST (T, -inf, showpos, 0, 8, ' ', "", " -inf");
1551 TEST (T, -inf, uppercase, 0, 8, ' ', "", " -INF");
1552 TEST (T, -inf, showpos | uppercase, 0, 8, ' ', "", " -INF");
1553
1554 TEST (T, inf, left, 0, 9, ' ', "", "inf ");
1555 TEST (T, inf, left | showpos, 0, 9, ' ', "", "+inf ");
1556 TEST (T, inf, left | uppercase, 0, 9, ' ', "", "INF ");
1557 TEST (T, inf, left | showpos | uppercase, 0, 9, ' ', "", "+INF ");
1558
1559 TEST (T, -inf, left, 0, 9, ' ', "", "-inf ");
1560 TEST (T, -inf, left | showpos, 0, 9, ' ', "", "-inf ");
1561 TEST (T, -inf, left | uppercase, 0, 9, ' ', "", "-INF ");
1562 TEST (T, -inf, left | showpos | uppercase, 0, 9, ' ', "", "-INF ");
1563
1564 TEST (T, inf, right, 0, 9, ' ', "", " inf");
1565 TEST (T, inf, right | showpos, 0, 9, ' ', "", " +inf");
1566 TEST (T, inf, right | uppercase, 0, 9, ' ', "", " INF");
1567 TEST (T, inf, right | showpos | uppercase, 0, 9, ' ', "", " +INF");
1568
1569 TEST (T, -inf, right, 0, 9, ' ', "", " -inf");
1570 TEST (T, -inf, right | showpos, 0, 9, ' ', "", " -inf");
1571 TEST (T, -inf, right | uppercase, 0, 9, ' ', "", " -INF");
1572 TEST (T, -inf, right | showpos | uppercase, 0, 9, ' ', "", " -INF");
1573
1575 // exercise the formatting of positive and negative (quiet) NaNs
1576
1577 rw_info (0, 0, 0, "std::num_put<%s>::put (..., %s) formatting "
1578 "NaN's", cname, tname);
1579
1580 // compute a quiet NaN
1581#if 0
1582
1583 // temporarily disabled (NAN format is platform specific
1584 // and subject to bugs -- see for example STDCXX-464)
1585
1586 const floatT nan = 0 / zero;
1587
1588 TEST (T, nan, 0, 0, 0, ' ', "", "nan");
1589 TEST (T, nan, showpos, 0, 0, ' ', "", "+nan");
1590 TEST (T, nan, uppercase, 0, 0, ' ', "", "NAN");
1591 TEST (T, nan, showpos | uppercase, 0, 0, ' ', "", "+NAN");
1592
1593 TEST (T, -nan, 0, 0, 0, ' ', "", "-nan");
1594 TEST (T, -nan, showpos, 0, 0, ' ', "", "-nan");
1595 TEST (T, -nan, uppercase, 0, 0, ' ', "", "-NAN");
1596 TEST (T, -nan, showpos | uppercase, 0, 0, ' ', "", "-NAN");
1597
1598 TEST (T, nan, 0, 1, 0, ' ', "", "nan");
1599 TEST (T, nan, showpos, 1, 0, ' ', "", "+nan");
1600 TEST (T, nan, uppercase, 1, 0, ' ', "", "NAN");
1601 TEST (T, nan, showpos | uppercase, 1, 0, ' ', "", "+NAN");
1602
1603 TEST (T, -nan, 0, 1, 0, ' ', "", "-nan");
1604 TEST (T, -nan, showpos, 1, 0, ' ', "", "-nan");
1605 TEST (T, -nan, uppercase, 1, 0, ' ', "", "-NAN");
1606 TEST (T, -nan, showpos | uppercase, 1, 0, ' ', "", "-NAN");
1607
1608 TEST (T, nan, 0, 3, 0, ' ', "", "nan");
1609 TEST (T, nan, showpos, 3, 0, ' ', "", "+nan");
1610 TEST (T, nan, uppercase, 3, 0, ' ', "", "NAN");
1611 TEST (T, nan, showpos | uppercase, 3, 0, ' ', "", "+NAN");
1612
1613 TEST (T, -nan, 0, 3, 0, ' ', "", "-nan");
1614 TEST (T, -nan, showpos, 3, 0, ' ', "", "-nan");
1615 TEST (T, -nan, uppercase, 3, 0, ' ', "", "-NAN");
1616 TEST (T, -nan, showpos | uppercase, 3, 0, ' ', "", "-NAN");
1617
1618 TEST (T, nan, 0, 4, 0, ' ', "", "nan");
1619 TEST (T, nan, showpos, 4, 0, ' ', "", "+nan");
1620 TEST (T, nan, uppercase, 4, 0, ' ', "", "NAN");
1621 TEST (T, nan, showpos | uppercase, 4, 0, ' ', "", "+NAN");
1622
1623 TEST (T, -nan, 0, 4, 0, ' ', "", "-nan");
1624 TEST (T, -nan, showpos, 4, 0, ' ', "", "-nan");
1625 TEST (T, -nan, uppercase, 4, 0, ' ', "", "-NAN");
1626 TEST (T, -nan, showpos | uppercase, 4, 0, ' ', "", "-NAN");
1627
1628 TEST (T, nan, 0, 9, 0, ' ', "", "nan");
1629 TEST (T, nan, showpos, 9, 0, ' ', "", "+nan");
1630 TEST (T, nan, uppercase, 9, 0, ' ', "", "NAN");
1631 TEST (T, nan, showpos | uppercase, 9, 0, ' ', "", "+NAN");
1632
1633 TEST (T, -nan, 0, 9, 0, ' ', "", "-nan");
1634 TEST (T, -nan, showpos, 9, 0, ' ', "", "-nan");
1635 TEST (T, -nan, uppercase, 9, 0, ' ', "", "-NAN");
1636 TEST (T, -nan, showpos | uppercase, 9, 0, ' ', "", "-NAN");
1637
1638 TEST (T, nan, 0, 0, 1, ' ', "", "nan");
1639 TEST (T, nan, showpos, 0, 1, ' ', "", "+nan");
1640 TEST (T, nan, uppercase, 0, 1, ' ', "", "NAN");
1641 TEST (T, nan, showpos | uppercase, 0, 1, ' ', "", "+NAN");
1642
1643 TEST (T, -nan, 0, 0, 1, ' ', "", "-nan");
1644 TEST (T, -nan, showpos, 0, 1, ' ', "", "-nan");
1645 TEST (T, -nan, uppercase, 0, 1, ' ', "", "-NAN");
1646 TEST (T, -nan, showpos | uppercase, 0, 1, ' ', "", "-NAN");
1647
1648 TEST (T, nan, 0, 0, 3, ' ', "", "nan");
1649 TEST (T, nan, showpos, 0, 3, ' ', "", "+nan");
1650 TEST (T, nan, uppercase, 0, 3, ' ', "", "NAN");
1651 TEST (T, nan, showpos | uppercase, 0, 3, ' ', "", "+NAN");
1652
1653 TEST (T, -nan, 0, 0, 3, ' ', "", "-nan");
1654 TEST (T, -nan, showpos, 0, 3, ' ', "", "-nan");
1655 TEST (T, -nan, uppercase, 0, 3, ' ', "", "-NAN");
1656 TEST (T, -nan, showpos | uppercase, 0, 3, ' ', "", "-NAN");
1657
1658 TEST (T, nan, 0, 0, 4, ' ', "", " nan");
1659 TEST (T, nan, showpos, 0, 4, ' ', "", "+nan");
1660 TEST (T, nan, uppercase, 0, 4, ' ', "", " NAN");
1661 TEST (T, nan, showpos | uppercase, 0, 4, ' ', "", "+NAN");
1662
1663 TEST (T, -nan, 0, 0, 4, ' ', "", "-nan");
1664 TEST (T, -nan, showpos, 0, 4, ' ', "", "-nan");
1665 TEST (T, -nan, uppercase, 0, 4, ' ', "", "-NAN");
1666 TEST (T, -nan, showpos | uppercase, 0, 4, ' ', "", "-NAN");
1667
1668 TEST (T, nan, 0, 0, 5, ' ', "", " nan");
1669 TEST (T, nan, showpos, 0, 5, ' ', "", " +nan");
1670 TEST (T, nan, uppercase, 0, 5, ' ', "", " NAN");
1671 TEST (T, nan, showpos | uppercase, 0, 5, ' ', "", " +NAN");
1672
1673 TEST (T, -nan, 0, 0, 5, ' ', "", " -nan");
1674 TEST (T, -nan, showpos, 0, 5, ' ', "", " -nan");
1675 TEST (T, -nan, uppercase, 0, 5, ' ', "", " -NAN");
1676 TEST (T, -nan, showpos | uppercase, 0, 5, ' ', "", " -NAN");
1677
1678 TEST (T, nan, 0, 0, 8, ' ', "", " nan");
1679 TEST (T, nan, showpos, 0, 8, ' ', "", " +nan");
1680 TEST (T, nan, uppercase, 0, 8, ' ', "", " NAN");
1681 TEST (T, nan, showpos | uppercase, 0, 8, ' ', "", " +NAN");
1682
1683 TEST (T, -nan, 0, 0, 8, ' ', "", " -nan");
1684 TEST (T, -nan, showpos, 0, 8, ' ', "", " -nan");
1685 TEST (T, -nan, uppercase, 0, 8, ' ', "", " -NAN");
1686 TEST (T, -nan, showpos | uppercase, 0, 8, ' ', "", " -NAN");
1687
1688 TEST (T, nan, left, 0, 9, ' ', "", "nan ");
1689 TEST (T, nan, left | showpos, 0, 9, ' ', "", "+nan ");
1690 TEST (T, nan, left | uppercase, 0, 9, ' ', "", "NAN ");
1691 TEST (T, nan, left | showpos | uppercase, 0, 9, ' ', "", "+NAN ");
1692
1693 TEST (T, -nan, left, 0, 9, ' ', "", "-nan ");
1694 TEST (T, -nan, left | showpos, 0, 9, ' ', "", "-nan ");
1695 TEST (T, -nan, left | uppercase, 0, 9, ' ', "", "-NAN ");
1696 TEST (T, -nan, left | showpos | uppercase, 0, 9, ' ', "", "-NAN ");
1697
1698 TEST (T, nan, right, 0, 9, ' ', "", " nan");
1699 TEST (T, nan, right | showpos, 0, 9, ' ', "", " +nan");
1700 TEST (T, nan, right | uppercase, 0, 9, ' ', "", " NAN");
1701 TEST (T, nan, right | showpos | uppercase, 0, 9, ' ', "", " +NAN");
1702
1703 TEST (T, -nan, right, 0, 9, ' ', "", " -nan");
1704 TEST (T, -nan, right | showpos, 0, 9, ' ', "", " -nan");
1705 TEST (T, -nan, right | uppercase, 0, 9, ' ', "", " -NAN");
1706 TEST (T, -nan, right | showpos | uppercase, 0, 9, ' ', "", " -NAN");
1707
1708#else
1709
1710 rw_info (0, 0, 0, "std::num_put<%s>::put (..., %s) formatting "
1711 "NaN's disabled due to platform bugs", cname, tname);
1712
1713#endif // 0/1
1714
1715}
1716
1717
1719template <class charT>
1720void dbl_test (charT, const char *cname)
1721{
1722 const char* const tname = "double";
1723
1724 rw_info (0, 0, 0, "std::num_put<%s>::put (..., %s)", cname, tname);
1725
1727
1728 TEST (T, 0.0, 0, 0, 0, ' ', "", "%.0g");
1729 TEST (T, -0.0, 0, 0, 0, ' ', "", "%.0g");
1730 TEST (T, 1.0, 0, 0, 0, ' ', "", "%.0g");
1731 TEST (T, 1.0, 0, 0, 0, ' ', "", "1");
1732 TEST (T, -1.0, 0, 0, 0, ' ', "", "%.0g");
1733 TEST (T, -1.0, 0, 0, 0, ' ', "", "-1");
1734 TEST (T, 1.1, 0, 0, 0, ' ', "", "%.0g");
1735 TEST (T, 1.1, 0, 0, 0, ' ', "", "1");
1736 TEST (T, -1.1, 0, 0, 0, ' ', "", "%.0g");
1737 TEST (T, -1.1, 0, 0, 0, ' ', "", "-1");
1738
1739
1740 // exercise formatting of very large numbers in a fixed notation
1741 // using '+' as the fill character to disable num_get tests
1742 TEST (T, 1.0e+128, fixed, 0, 0, '+', "", "%.0f", Eof);
1743 TEST (T, 1.0e+256, fixed, 0, 0, '+', "", "%.0f", Eof);
1744
1745
1746#undef CAT
1747#undef CONCAT
1748
1749#define CAT(a, b) CONCAT (a, b)
1750#define CONCAT(a, b) a ## b
1751
1752 const double d = CAT (1.0e+, _RWSTD_DBL_MAX_10_EXP);
1753
1754 TEST (T, d, fixed, 0, 0, '+', "", "%.0f", Eof);
1755
1756
1757 {
1758 char stdiofmt [8];
1759 const std::streamsize prec = std::streamsize (DBL_DIG + 3);
1760 std::sprintf (stdiofmt, "%%.%dg", int (prec));
1761
1762 TEST (T, DBL_MIN, 0, prec, 0, ' ', "", stdiofmt);
1763 TEST (T, DBL_MAX, 0, prec, 0, ' ', "", stdiofmt);
1764 }
1765
1766 if (1) {
1767 // verify that the global LC_NUMERIC setting has no impact on the facet
1768 for (const char *name = rw_locales (LC_NUMERIC, 0); name && *name;
1769 name += std::strlen (name) + 1) {
1770
1771 // find the first locale whose decimal_point character
1772 // is different than in the classic C locale (i.e., than '.')
1773 if (0 == std::setlocale (LC_NUMERIC, name))
1774 continue;
1775
1776 const std::lconv* const conv = std::localeconv ();
1777
1778 if (!conv)
1779 continue;
1780
1781 if (conv->decimal_point && '.' != *conv->decimal_point)
1782 break;
1783 }
1784
1787
1788 TEST (T, 12345.678900, fixed, 6, 0, ' ', "\000", "12345*678900");
1789 TEST (T, 123456.78900, fixed, 5, 0, ' ', "\002", "12/34/56*78900");
1790 TEST (T, 1234567.8900, fixed, 4, 0, ' ', "\003", "1/234/567*8900");
1791
1793
1794 TEST (T, 12345678.900, fixed, 3, 0, ' ', "\004", "1234/5678.900");
1795
1796 // reset the global locale
1797 std::setlocale (LC_NUMERIC, "C");
1798 }
1799
1800 inf_nan_test (charT (), double (), cname, tname);
1801}
1802
1803
1805template <class charT>
1806void ldbl_test (charT, const char *cname)
1807{
1808#ifndef _RWSTD_NO_LONG_DOUBLE
1809
1810 const char* const tname = "long double";
1811
1812 rw_info (0, 0, 0, "std::num_put<%s>::put (..., %s) "
1813 "[sizeof (long double) = %u]",
1814 cname, tname, sizeof (long double));
1815
1816 typedef long double LDbl;
1817
1819
1820 TEST (T, 0.0L, 0, 0, 0, ' ', "", "%.0Lg");
1821 TEST (T, 1.0L, 0, 0, 0, ' ', "", "%.0Lg");
1822 TEST (T, 2.1L, 0, 0, 0, ' ', "", "%.0Lg");
1823 TEST (T, -3.2L, 0, 0, 0, ' ', "", "%.0Lg");
1824 TEST (T, -4.3L, 0, 0, 0, ' ', "", "%.0Lg");
1825
1826 TEST (T, 1.0e+10L, 0, 0, 0, ' ', "", "%.0Lg");
1827 TEST (T, 2.0e+20L, 0, 0, 0, ' ', "", "%.0Lg");
1828 TEST (T, 4.0e+30L, 0, 0, 0, ' ', "", "%.0Lg");
1829
1830 TEST (T, 1.0e-10L, 0, 0, 0, ' ', "", "%.0Lg");
1831 TEST (T, 2.0e-20L, 0, 0, 0, ' ', "", "%.0Lg");
1832 TEST (T, 4.0e-30L, 0, 0, 0, ' ', "", "%.0Lg");
1833
1834 TEST (T, LDbl (CHAR_MAX), 0, 0, 0, ' ', "", "%.0Lg");
1835 TEST (T, LDbl (UCHAR_MAX), 0, 0, 0, ' ', "", "%.0Lg");
1836 TEST (T, LDbl (SCHAR_MAX), 0, 0, 0, ' ', "", "%.0Lg");
1837 TEST (T, LDbl (SHRT_MAX), 0, 0, 0, ' ', "", "%.0Lg");
1838 TEST (T, LDbl (USHRT_MAX), 0, 0, 0, ' ', "", "%.0Lg");
1839
1840 // specify greater precision than the default 6 for large numbers
1841 TEST (T, LDbl (INT_MAX), 0, 32, 0, ' ', "", "%.32Lg");
1842 TEST (T, LDbl (UINT_MAX), 0, 32, 0, ' ', "", "%.32Lg");
1843
1844 TEST (T, LDbl (LONG_MAX), 0, 32, 0, ' ', "", "%.32Lg");
1845 TEST (T, LDbl (ULONG_MAX), 0, 32, 0, ' ', "", "%.32Lg");
1846
1847 TEST (T, LDbl (FLT_MIN), 0, 32, 0, ' ', "", "%.32Lg");
1848 TEST (T, LDbl (FLT_MAX), 0, 32, 0, ' ', "", "%.32Lg");
1849 TEST (T, LDbl (DBL_MIN), 0, 32, 0, ' ', "", "%.32Lg");
1850 TEST (T, LDbl (DBL_MAX), 0, 32, 0, ' ', "", "%.32Lg");
1851
1852 {
1853 char stdiofmt [8];
1854 const std::streamsize prec = std::streamsize (LDBL_DIG + 3);
1855 std::sprintf (stdiofmt, "%%.%d" _RWSTD_LDBL_PRINTF_PREFIX "g",
1856 int (prec));
1857
1858 TEST (T, LDbl (LDBL_MIN), 0, prec, 0, ' ', "", stdiofmt);
1859 TEST (T, LDbl (LDBL_MAX), 0, prec, 0, ' ', "", stdiofmt);
1860 }
1861
1862 const long double Pi = 3.14159265358979323846L;
1863
1864 // some test cases below that use precision in conjuction with
1865 // scientific in the libc format specifier in order to exercise
1866 // the proposed resolution of lwg issue 231
1867 TEST (T, Pi, 0, 32, 0, ' ', "", "%.32Lg");
1868 TEST (T, Pi, fixed, 0, 0, ' ', "", "%.0Lf", Eof, 3.0L);
1869 TEST (T, Pi, scientific, 0, 0, ' ', "", "%.0Le", Eof, 3.0L);
1870 TEST (T, Pi, fixed, 0, 0, ' ', "", "3", Eof, 3.0L);
1871 TEST (T, Pi, scientific, 0, 0, ' ', "", "3e+00", Eof, 3.0L);
1872
1873 TEST (T, Pi, uppercase, 32, 0, ' ', "", "%.32LG");
1874 TEST (T, Pi, uppercase | fixed, 0, 0, ' ', "", "%.0Lf", Eof, 3.0L);
1875 TEST (T, Pi, uppercase | scientific, 0, 0, ' ', "", "%.0LE", Eof, 3.0L);
1876 TEST (T, Pi, uppercase | scientific, 0, 0, ' ', "", "3E+00", Eof, 3.0L);
1877
1878#define Showpos(f) (showpos | f)
1879
1880 TEST (T, Pi, Showpos (0), 32, 0, ' ', "", "%+.32Lg");
1881 TEST (T, Pi, Showpos (fixed), 0, 0, ' ', "", "%+.0Lf", Eof, 3.0L);
1882 TEST (T, Pi, Showpos (scientific), 0, 0, ' ', "", "%+.0Le", Eof, 3.0L);
1883 TEST (T, Pi, Showpos (fixed), 0, 0, ' ', "", "+3", Eof, 3.0L);
1884 TEST (T, Pi, Showpos (scientific), 0, 0, ' ', "", "+3e+00", Eof, 3.0L);
1885
1886#define SHOWPOS(f) (showpos | uppercase | f)
1887
1888 TEST (T, Pi, SHOWPOS (0), 32, 0, ' ', "", "%+.32LG");
1889 TEST (T, Pi, SHOWPOS (fixed), 0, 0, ' ', "", "%+.0Lf", Eof, 3.0L);
1890 TEST (T, Pi, SHOWPOS (scientific), 0, 0, ' ', "", "%+.0LE", Eof, 3.0L);
1891 TEST (T, Pi, SHOWPOS (fixed), 0, 0, ' ', "", "+3", Eof, 3.0L);
1892 TEST (T, Pi, SHOWPOS (scientific), 0, 0, ' ', "", "+3E+00", Eof, 3.0L);
1893
1894#define Showpoint(f) (showpoint | f)
1895
1896 TEST (T, Pi, Showpoint (0), 32, 0, ' ', "", "%#.32Lg");
1897 TEST (T, Pi, Showpoint (fixed), 0, 0, ' ', "", "%#.0Lf", Eof, 3.0L);
1898 TEST (T, Pi, Showpoint (scientific), 0, 0, ' ', "", "%#.0Le", Eof, 3.0L);
1899 TEST (T, Pi, Showpoint (fixed), 0, 0, ' ', "", "3.", Eof, 3.0L);
1900 TEST (T, Pi, Showpoint (scientific), 0, 0, ' ', "", "3.e+00", Eof, 3.0L);
1901
1902#define SHOWPOINT(f) (showpoint | uppercase | f)
1903
1904 TEST (T, Pi, SHOWPOINT (0), 32, 0, ' ', "", "%#.32LG");
1905 TEST (T, Pi, SHOWPOINT (fixed), 0, 0, ' ', "", "%#.0Lf", Eof, 3.0L);
1906 TEST (T, Pi, SHOWPOINT (scientific), 0, 0, ' ', "", "%#.0LE", Eof, 3.0L);
1907 TEST (T, Pi, SHOWPOINT (scientific), 0, 0, ' ', "", "3.E+00", Eof, 3.0L);
1908
1909#define Showall(f) (showpoint | showpos | f)
1910
1911 TEST (T, Pi, Showall (0), 32, 0, ' ', "", "%#+.32Lg");
1912 TEST (T, Pi, Showall (fixed), 0, 0, ' ', "", "%#+.0Lf", Eof, 3.0L);
1913 TEST (T, Pi, Showall (scientific), 0, 0, ' ', "", "%#+.0Le", Eof, 3.0L);
1914 TEST (T, Pi, Showall (fixed), 0, 0, ' ', "", "+3.", Eof, 3.0L);
1915 TEST (T, Pi, Showall (scientific), 0, 0, ' ', "", "+3.e+00", Eof, 3.0L);
1916
1917#define SHOWALL(f) (showpoint | showpos | uppercase | f)
1918
1919 TEST (T, Pi, SHOWALL (0), 32, 0, ' ', "", "%#+.32LG");
1920 TEST (T, Pi, SHOWALL (fixed), 0, 0, ' ', "", "%#+.0Lf", Eof, 3.0L);
1921 TEST (T, Pi, SHOWALL (scientific), 0, 0, ' ', "", "%#+.0LE", Eof, 3.0L);
1922 TEST (T, Pi, SHOWALL (scientific), 0, 0, ' ', "", "+3.E+00", Eof, 3.0L);
1923
1924 // with {g,G}, precision indicates the number of significant digits
1925 // the precision == 0 should have the same effect as precision == 1
1926 TEST (T, Pi, 0, 0, 0, ' ', "", "%.0Lg", Eof, 3.0L);
1927 TEST (T, Pi, 0, 1, 0, ' ', "", "%.1Lg", Eof, 3.0L);
1928 TEST (T, Pi, 0, 2, 0, ' ', "", "%.2Lg", Eof, 3.1L);
1929 TEST (T, Pi, 0, 3, 0, ' ', "", "%.3Lg", Eof, 3.14L);
1930 TEST (T, Pi, 0, 10, 0, ' ', "", "%.10Lg", Eof, 3.141592654L);
1931
1932 // C89 and C99 both specify that (only if specified using the asterisk)
1933 // negative precision is treated the same as no precision at all; verify
1934 // that num_put handles negative precision gracefully (i.e., ignores it)
1935 TEST (T, Pi, 0, -1, 0, ' ', "", "%Lg");
1936 TEST (T, Pi, 0, -9, 0, ' ', "", "%Lg");
1937
1938 // with {e,E,f,F}, precision indicates the number of fractional digits
1939 TEST (T, Pi, fixed, 1, 0, ' ', "", "%.1Lf", Eof, 3.1L);
1940 TEST (T, Pi, fixed, 2, 0, ' ', "", "%.2Lf", Eof, 3.14L);
1941 TEST (T, Pi, fixed, 3, 0, ' ', "", "%.3Lf", Eof, 3.142L);
1942 TEST (T, Pi, fixed, 10, 0, ' ', "", "%.10Lf", Eof, 3.1415926536L);
1943
1944
1945 // exercise formatting of very large numbers in a fixed notation
1946 // using '-' as the fill character to disable num_get tests
1947 TEST (T, 2.0e+128L, fixed, 0, 0, '-', "", "%.0Lf", Eof);
1948 TEST (T, 3.0e+256L, fixed, 0, 0, '-', "", "%.0Lf", Eof);
1949 TEST (T, 4.0e+300L, fixed, 0, 0, '-', "", "%.0Lf", Eof);
1950
1951 // extension: fixed format and negative precision
1952 TEST (T, Pi, fixed, -2, 0, ' ', "", "0.03");
1953 TEST (T, Pi, fixed, -8, 0, ' ', "", "0.00000003");
1954
1955#undef CAT
1956#undef CONCAT
1957
1958#define CAT(a, b) CONCAT (a, b)
1959#define CONCAT(a, b) a ## b
1960
1961 const long double ld = CAT (CAT (1.0e+, _RWSTD_LDBL_MAX_10_EXP), L);
1962
1963 TEST (T, ld, fixed, 0, 0, '-', "", "%.0Lf", Eof);
1964
1965 TEST (T, Pi, scientific, 2, 0, ' ', "", "%.2Le", Eof, 3.14L);
1966 TEST (T, Pi, scientific, 4, 0, ' ', "", "%.4Le", Eof, 3.1416L);
1967 TEST (T, Pi, scientific, 6, 0, ' ', "", "%.6Le", Eof, 3.141593L);
1968 TEST (T, Pi, scientific, 12, 0, ' ', "", "%.12Le", Eof, 3.14159265359L);
1969 TEST (T, Pi, scientific, -3, 0, ' ', "", "%Le");
1970 TEST (T, Pi, scientific, -7, 0, ' ', "", "%Le");
1971
1972 inf_nan_test (charT (), (long double)0, cname, tname);
1973
1974#endif // _RWSTD_NO_LONG_DOUBLE
1975}
1976
1977
1978
1980template <class charT>
1981void pvoid_test (charT, const char *cname)
1982{
1983 const char* const tname = "const void*";
1984
1985 rw_info (0, 0, 0, "std::num_put<%s>::put (..., %s)", cname, tname);
1986
1987 typedef void* PVoid;
1988
1989 int foo = 0;
1990 int bar = 0;
1991
1992 // use "0" rather than "%p" for null pointers to avoid
1993 // having to deal with GNU libc's "(nil)" format
1994 TEST (T, PVoid ( 0), 0, 0, 0, ' ', "", "0");
1995 TEST (T, PVoid ( 1), 0, 0, 0, ' ', "", "%p");
1996 TEST (T, PVoid ( &foo), 0, 0, 0, ' ', "", "%p");
1997 TEST (T, PVoid ( &bar), 0, 0, 0, ' ', "", "%p");
1998 TEST (T, PVoid ( ~0L), 0, 0, 0, ' ', "", "%p");
1999
2000 // 22.2.2.2.2, p16 and lwg issue 282: grouping and thousands_sep
2001 // is only used in arithmetic types
2002 TEST (T, PVoid ( 0), 0, 0, 0, ' ', "\1", "0");
2003 TEST (T, PVoid ( 1), 0, 0, 0, ' ', "\1", "%p");
2004 TEST (T, PVoid ( &foo), 0, 0, 0, ' ', "\1\1", "%p");
2005 TEST (T, PVoid ( &bar), 0, 0, 0, ' ', "\1\2", "%p");
2006 TEST (T, PVoid ( ~0L), 0, 0, 0, ' ', "\1\3", "%p");
2007
2008 TEST (T, PVoid ( SHRT_MAX), 0, 0, 0, ' ', "", "%p");
2009 TEST (T, PVoid ( SHRT_MIN), 0, 0, 0, ' ', "", "%p");
2010 TEST (T, PVoid (USHRT_MAX), 0, 0, 0, ' ', "", "%p");
2011 TEST (T, PVoid ( INT_MAX), 0, 0, 0, ' ', "", "%p");
2012 TEST (T, PVoid ( INT_MIN), 0, 0, 0, ' ', "", "%p");
2013 TEST (T, PVoid ( UINT_MAX), 0, 0, 0, ' ', "", "%p");
2014 TEST (T, PVoid ( LONG_MAX), 0, 0, 0, ' ', "", "%p");
2015 TEST (T, PVoid ( LONG_MIN), 0, 0, 0, ' ', "", "%p");
2016 TEST (T, PVoid (ULONG_MAX), 0, 0, 0, ' ', "", "%p");
2017
2018#ifdef _RWSTD_LLONG_MAX
2019# if _RWSTD_LLONG_SIZE <= _RWSTD_PTR_SIZE
2020
2021 TEST (T, PVoid (_RWSTD_LLONG_MAX), 0, 0, 0, ' ', "", "%p");
2022 TEST (T, PVoid (_RWSTD_ULLONG_MAX), 0, 0, 0, ' ', "", "%p");
2023
2024# endif // LLONG_MAX
2025#endif // _RWSTD_LLONG_MAX
2026
2027}
2028
2029
2030
2032template <class charT>
2033void errno_test (charT, const char *cname)
2034{
2035 const char* const tname = "long";
2036
2037 rw_info (0, 0, 0,
2038 "std::num_put<%s>::put (..., %s) and errno", cname, tname);
2039
2040 // verify that errno doesn't change after, or adversely affect
2041 // successful insertion; and that the insertion doesn't change
2042 // the value of errno
2043
2044 errno = -1;
2045 TEST (T, 12345L, 0, 0, 0, ' ', "", "12345");
2046 rw_assert (-1 == errno, 0, __LINE__,
2047 "errno unexpectedly changed from %d to %{#m} (%m)", -1);
2048
2049 errno = 0;
2050 TEST (T, 12346L, 0, 0, 0, ' ', "", "12346");
2051 rw_assert (0 == errno, 0, __LINE__,
2052 "errno unexpectedly changed from %d to %{#m} (%m)", -0);
2053
2054 errno = 1;
2055 TEST (T, 12347L, 0, 0, 0, ' ', "", "12347");
2056 rw_assert (1 == errno, 0, __LINE__,
2057 "errno unexpectedly changed from %d to %{#m} (%m)", 1);
2058
2059 errno = 2;
2060 TEST (T, 12348L, 0, 0, 0, ' ', "", "12348");
2061 rw_assert (2 == errno, 0, __LINE__,
2062 "errno unexpectedly changed from %d to %{#m} (%m)", 2);
2063
2064 errno = 3;
2065 TEST (T, 12349L, 0, 0, 0, ' ', "", "12349");
2066 rw_assert (3 == errno, 0, __LINE__,
2067 "errno unexpectedly changed from %d to %{#m} (%m)", 3);
2068
2069 errno = 4;
2070 TEST (T, 12350L, 0, 0, 0, ' ', "", "12350");
2071 rw_assert (4 == errno, 0, __LINE__,
2072 "errno unexpectedly changed from %d to %{#m} (%m)", 4);
2073
2074 errno = ERANGE;
2075 TEST (T, 12351L, 0, 0, 0, ' ', "", "12351");
2076 rw_assert (ERANGE == errno, 0, __LINE__,
2077 "errno unexpectedly changed from %{#m} to %{#m} (%m)", ERANGE);
2078
2079 errno = Bad;
2080 TEST (T, 12352L, 0, 0, 0, ' ', "", "12352");
2081 rw_assert (Bad == errno, 0, __LINE__,
2082 "errno unexpectedly changed from %d to %{#m} (%m)", Bad);
2083
2084 errno = Eof;
2085 TEST (T, 12353L, 0, 0, 0, ' ', "", "12353");
2086 rw_assert (Eof == errno, 0, __LINE__,
2087 "errno unexpectedly changed from %d to %{#m} (%m)", Eof);
2088
2089 errno = Fail;
2090 TEST (T, 12354L, 0, 0, 0, ' ', "", "12354");
2091 rw_assert (Fail == errno, 0, __LINE__,
2092 "errno unexpectedly changed from %d to %{#m} (%m)", Fail);
2093
2094 errno = 0;
2095}
2096
2097
2098
2100// verify that std::ctype<>::widen() is called at least once
2101// for every distinct narow character (not for fill characters)
2102// note that an implementation is allowed to cache the results
2103// of facet virtual functions() called with the same arguments
2104// (including the implicit this pointer), so the numbers here
2105// are minimum required values but not exact or maximums
2107{
2108 rw_info (0, 0, 0,
2109 "std::num_put<char>::put (..., long) calls ctype<char>::widen()");
2110
2111 static const struct {
2112 long val;
2113 std::streamsize width;
2114 int flags;
2115 int n_widen;
2116 const char *str;
2117 } data[] = {
2118 { 0, 0, 0, 1, "9" },
2119 { 1, 0, 0, 1, "8" },
2120 { 11, 0, 0, 1, "88" },
2121 { 12, 0, 0, 2, "87" },
2122 { 123, 0, 0, 3, "876" },
2123 { 111, 0, 0, 1, "888" },
2124 { -1234, 0, 0, 5, "-8765" },
2125 { 12121, 0, 0, 2, "87878" },
2126 { 12345, 0, showpos, 6, "+87654" },
2127 { 0123456, 0, oct | showbase, 7, "9876543" },
2128 { 0x234567, 0, hex | showbase, 8, "9x765432" },
2129 { 0x2345678, 10, hex | showbase, 9, " 9x7654321" },
2130 { 9, 5, showpos | internal, 2, "+ 0" }
2131 };
2132
2133 for (unsigned i = 0; i != sizeof data / sizeof *data; ++i) {
2134
2135 const Ctype<char> ctp;
2136
2137 // construct and initialize a basic_ios-derived object
2138 Ios<char> ios;
2139
2140 // construct a num_put-derived facet to exercise
2141 const NumPut<char> np;
2142
2143 // imbue a stream object with a custom locale
2144 // containing the replacement ctype facet
2145 ios.imbue (std::locale (ios.getloc (), (const std::ctype<char>*)&ctp));
2146
2147 ios.flags (std::ios_base::fmtflags (data [i].flags));
2148 ios.width (data [i].width);
2149
2150 char buf [40];
2151
2152 // reset function call counter
2154
2155 *np.put (buf, ios, ' ', data [i].val) = '\0';
2156
2157 rw_assert (data [i].n_widen <= Ctype<char>::n_widen_, 0, __LINE__,
2158 "%d. num_put<char>::do_put (..., %d) called "
2159 "ctype<char>::do_widen() %d times, %d expected; "
2160 "flags = %{If}, width = %d", i, data [i].val,
2161 Ctype<char>::n_widen_, data [i].n_widen,
2162 data [i].flags, data [i].width);
2163
2164 rw_assert (0 == rw_strncmp (buf, data [i].str), 0, __LINE__,
2165 "%d. num_put<char>::do_put (..., %d) produced %s, "
2166 "expected \"%{#*s}\"; "
2167 "flags = %{If}, width = %d",
2168 i, data [i].val, buf,
2169 int (sizeof data [i].str [0]), data [i].str,
2170 data [i].flags, data [i].width);
2171 }
2172}
2173
2174
2175
2177// verify that std::numpunct<>::grouping() is called and used correctly
2179{
2180 // construct a "replacement" numpunct-derived facet
2181 const Punct<char> pun (1);
2182
2183 // construct and initialize a basic_ios-derived object
2184 Ios<char> ios;
2185
2186 // construct a num_put-derived facet to exercise
2187 const NumPut<char> np;
2188
2189 // imbue a stream object with a custom locale
2190 // containing the replacement punctuation facet
2191 ios.imbue (std::locale (ios.getloc (), (const std::numpunct<char>*)&pun));
2192
2193 rw_assert (1 == Punct<char>::n_objs_, 0, __LINE__,
2194 "%d facets exist, 1 expected", Punct<char>::n_objs_);
2195
2196 // decimal output, no special formatting
2197 ios.setf (std::ios::fmtflags ());
2198
2199 char buf [40];
2200
2201 // group after every digit
2203
2204 // reset the do_thousands_sep()-call counter
2206
2207 *np.put (buf, ios, '\0', 123456789L) = '\0';
2208
2209 // verify that the number was formatted correctly
2210 rw_assert (0 == std::strcmp (buf, "1,2,3,4,5,6,7,8,9"), 0, __LINE__,
2211 "num_put<char>::do_put (..., 123456789) produced \"%s\", "
2212 "expected \"%s\"", buf, "1,2,3,4,5,6,7,8,9");
2213
2214 // verify that do_thousands_sep() was called at least once
2215 rw_assert (0 < Punct<char>::n_thousands_sep_, 0, __LINE__,
2216 "num_put<char>::do_put (..., 123456789) failed to call "
2217 "numpunct<char>::do_thousands_sep()");
2218
2219 // repeat test to verify that distinct instances
2220 // of the same facet do not cache each other's data
2221 {
2222 // nested scope works around a SunPro bug (PR #27543)
2223 ios.imbue (std::locale (ios.getloc (),
2224 (const std::numpunct<char>*)new Punct<char>(0)));
2225 }
2226
2227 rw_assert (2 == Punct<char>::n_objs_, 0, __LINE__,
2228 "%d facets exist, 2 expected", Punct<char>::n_objs_);
2229
2230 // now group after every other digit
2232
2233 // reset the do_thousands_sep()-call counter
2235
2236 *np.put (buf, ios, '\0', 123456790L) = '\0';
2237
2238 // again verify that the number was formatted correctly
2239 rw_assert (0 == std::strcmp (buf, "1,23,45,67,90"), 0, __LINE__,
2240 "num_put<char>::do_put (..., 123456790) produced \"%s\", "
2241 "expected \"%s\"", buf, "1,23,45,67,90");
2242
2243 // verify that do_thousands_sep() was called at least once
2244 // (i.e., that there is no unwarranted caching going on)
2245 rw_assert (0 < Punct<char>::n_thousands_sep_, 0, __LINE__,
2246 "num_put<char>::do_put (..., 123456790) failed to call "
2247 "numpunct<char>::do_thousands_sep()");
2248
2249 // replace imbued locale with a copy of the classic locale
2250 // and remove the previously installed locale containing
2251 // the user-defined facet; this must destroy the dynamically
2252 // created facet leaving only the local facet on the stack
2253 {
2254 // nested scope works around a SunPro bug (PR #27543)
2255 ios.imbue (std::locale::classic ());
2256 }
2257
2258 rw_assert (1 == Punct<char>::n_objs_, 0, __LINE__,
2259 "%d facets exist, 1 expected", Punct<char>::n_objs_);
2260}
2261
2262
2264template <class charT>
2265void numput_virtuals_test (charT, const char *cname)
2266{
2267 const NumPut<charT> put (1);
2268 const std::num_put<charT, charT*> &np = put;
2269
2270 Ios<charT> ios;
2271
2272 ios.flags (std::ios_base::fmtflags ());
2273
2274#define Abs(i) ((i) < 0 ? (-i) : (i))
2275
2276#define ASSERT(T, N, T2, tname, t2name) \
2277 do { \
2278 /* number of expected calls to the do_put() member */ \
2279 const int expect = N + put.ncalls_ [put.test_ ## T]; \
2280 const int expect_2 = !N + put.ncalls_ [put.test_ ## T2]; \
2281 charT buf [80]; \
2282 const charT* const end = np.put (buf, ios, charT (), (T)0); \
2283 rw_assert (end == buf + 1, 0, __LINE__, \
2284 "line %d: num_put<%s>::put (..., %s = 0) " \
2285 "return value", __LINE__, cname, tname); \
2286 const int ncalls = put.ncalls_ [put.test_ ## T]; \
2287 const int ncalls_2 = put.ncalls_ [put.test_ ## T2]; \
2288 rw_assert (expect == ncalls, 0, __LINE__, \
2289 "line %d: num_put<%s>::put (..., %s) called " \
2290 "do_put(..., %s) %d times, expected %d", \
2291 __LINE__, cname, tname, \
2292 tname, Abs (ncalls - expect - N), N); \
2293 /* make sure extensions, if any, are implemented in */ \
2294 /* terms of and call the standard virtual functions */ \
2295 /* bogus addressof operator prevents warnings about */ \
2296 /* unreachable code when T is the same as T2 */ \
2297 if (put.test_ ## T != put.test_ ## T2) \
2298 rw_assert (expect_2 == ncalls_2, 0, __LINE__, \
2299 "line %d: num_put<%s>::put (..., %s) called " \
2300 "do_put(..., %s) %d times, expected %d", \
2301 __LINE__, cname, tname, \
2302 t2name, Abs (expect_2 - ncalls_2 - !N), !N); \
2303 } while (0)
2304
2305 typedef unsigned short ushort;
2306 typedef unsigned int uint;
2307 typedef unsigned long ulong;
2308
2309 // verify that each public member function calls each corresponding
2310 // implementation do_xxx() member functions exactly once
2311
2312 // in the case of extensions, verify that each extended public member
2313 // function calls the appropriate implementation standard do_xxx()
2314 // member function
2315
2316#ifndef _RWSTD_NO_BOOL
2317 ASSERT (bool, 1, bool, "bool", "bool");
2318#endif // _RWSTD_NO_BOOL
2319
2320 ASSERT (long, 1, long, "long", "long");
2321 ASSERT (ulong, 1, ulong, "unsigned long", "unsigned long");
2322
2323#if defined (_RWSTD_LONG_LONG) && !defined (_RWSTD_NO_EXT_NUM_PUT)
2324
2325 typedef _RWSTD_LONG_LONG llong;
2326 typedef unsigned _RWSTD_LONG_LONG ullong;
2327
2328 ASSERT (llong, 1, llong, "long long", "long long");
2329 ASSERT (ullong, 1, ullong, "unsigned long long", "unsigned long long");
2330
2331#endif // _RWSTD_LONG_LONG && !_RWSTD_NO_EXT_NUM_PUT
2332
2333 ASSERT (double, 1, double, "double", "double");
2334
2335#ifndef _RWSTD_NO_LONG_DOUBLE
2336
2337 typedef long double ldouble;
2338
2339 ASSERT (ldouble, 1, ldouble, "long double", "long double");
2340
2341#endif // _RWSTD_NO_LONG_DOUBLE
2342
2343 typedef const void* pvoid;
2344 ASSERT (pvoid, 1, pvoid, "const void*", "const void*");
2345}
2346
2347
2349template <class charT>
2350void run_tests (charT, const char *cname)
2351{
2352 numput_virtuals_test (charT (), cname);
2353
2354 direct_use_test (charT (), cname);
2355
2356#undef TEST
2357#define TEST(T, tname) \
2358 if (rw_enabled (#T)) \
2359 T ## _test (charT (), cname); \
2360 else \
2361 rw_note (0, __FILE__, __LINE__, "%s test disabled", \
2362 tname && *tname ? tname : #T)
2363
2364#ifndef _RWSTD_NO_BOOL
2365
2366 TEST (bool, "");
2367
2368#endif // _RWSTD_NO_BOOL
2369
2370
2371 // NOTE: there is no num_put::put(..., short)
2372 // TEST (shrt, "short");
2373 // TEST (ushrt, "unsigned short");
2374
2375 // NOTE: there is no num_put::put(..., int)
2376 // TEST (int, "");
2377 // TEST (uint, "unsigned int");
2378
2379 TEST (long, "");
2380 TEST (ulong, "unsigned long");
2381
2382#ifndef _RWSTD_NO_LONG_LONG
2383
2384 TEST (llong, "long long");
2385 TEST (ullong, "unsigned long long");
2386
2387#endif // _RWSTD_NO_LONG_LONG
2388
2389 // NOTE: there is no num_put::put(..., float)
2390 // TEST (flt, "float");
2391
2392 TEST (dbl, "dbouble");
2393
2394#ifndef _RWSTD_NO_LONG_DOUBLE
2395
2396 TEST (ldbl, "long double");
2397
2398#endif // _RWSTD_NO_LONG_DOUBLE
2399
2400 TEST (pvoid, "void*");
2401
2402 if (rw_opt_no_errno)
2403 rw_note (0, __FILE__, __LINE__, "errno test disabled");
2404 else
2405 errno_test (charT (), cname);
2406}
2407
2408
2410static int
2411run_test (int, char*[])
2412{
2413 if (rw_opt_no_widen) {
2414 rw_note (0, 0, 0, "widen test disabled");
2415 }
2416 else {
2417 widen_test ();
2418 }
2419
2420 if (rw_opt_no_grouping) {
2421 rw_note (0, 0, 0, "grouping test disabled");
2422 }
2423 else {
2424 grouping_test ();
2425 }
2426
2427 if (rw_enabled ("char"))
2428 run_tests (char (), "char");
2429 else
2430 rw_note (0, __FILE__, __LINE__, "char test disabled");
2431
2432#ifndef _RWSTD_NO_WCHAR_T
2433
2434 if (rw_enabled ("wchar_t"))
2435 run_tests (wchar_t (), "wchar_t");
2436 else
2437 rw_note (0, __FILE__, __LINE__, "wchar_t test disabled");
2438
2439#endif // _RWSTD_NO_WCHAR_T
2440
2441 return 0;
2442}
2443
2444
2446int main (int argc, char *argv[])
2447{
2448 return rw_test (argc, argv, __FILE__,
2449 "lib.locale.num.put",
2450 0 /* no comment */, run_test,
2451 "|-enable-num_get# "
2452 "|-no-errno# "
2453 "|-no-grouping# "
2454 "|-no-widen# ",
2455 &rw_opt_enable_num_get,
2456 &rw_opt_no_errno,
2457 &rw_opt_no_grouping,
2458 &rw_opt_no_widen);
2459}
#define i
Definition 17.names.cpp:126
#define d
Definition 17.names.cpp:115
#define e
Definition 17.names.cpp:118
#define v
Definition 17.names.cpp:138
#define last
Definition 17.names.cpp:487
#define sb
Definition 17.names.cpp:542
#define x
Definition 17.names.cpp:140
#define f
Definition 17.names.cpp:119
#define lineno
Definition 17.names.cpp:491
#define buf
Definition 17.names.cpp:452
#define c
Definition 17.names.cpp:111
#define charT
Definition 17.names.cpp:456
#define len
Definition 17.names.cpp:488
#define val
Definition 17.names.cpp:570
const char *const data[]
volatile double zero
#define T
#define BASE(n)
#define showbase
void ldbl_test(charT, const char *cname)
#define OPTS
#define ASSERT(T, N, T2, tname, t2name)
#define scientific
#define Showpos(f)
#define uppercase
void dbl_test(charT, const char *cname)
void numput_virtuals_test(charT, const char *cname)
#define DIRECT_USE_TEST(T)
#define left
#define LONG_MAX
void grouping_test()
#define SHOWALL(f)
#define SHOWPOS(f)
void ulong_test(charT, const char *cname)
#define FLAGS
void errno_test(charT, const char *cname)
#define Showall(f)
#define dec
#define Showpoint(f)
#define oct
#define hex
#define CAT(a, b)
#define bin
void bool_test(charT, const char *cname)
void llong_test(charT, const char *cname)
#define Fail
void run_tests(charT, const char *cname)
void widen_test()
void ullong_test(charT, const char *cname)
#define SHOWPOINT(f)
#define TEST
#define flags
void direct_use_test(charT, const char *cname)
#define STDIO_FMAT
#define LL(number)
#define boolalpha
#define Bad
#define GROUPING
#define internal
void pvoid_test(charT, const char *cname)
#define right
#define LONG_MIN
#define Eof
void long_test(charT, const char *cname)
#define showpos
#define fixed
void inf_nan_test(charT, floatT, const char *cname, const char *tname)
#define GET_FAIL
void do_test(int line, const char *src, std::size_t resoff, ForwardIterator dummy_iter, const T *, const char *predname)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
@ LDbl
@ PVoid
#define main
#define ERANGE
#define LDBL_MIN
Definition _cfloat.h:67
#define LDBL_DIG
Definition _cfloat.h:60
#define FLT_MAX
Definition _cfloat.h:46
#define FLT_MIN
Definition _cfloat.h:47
#define DBL_DIG
Definition _cfloat.h:50
#define DBL_MIN
Definition _cfloat.h:57
#define LDBL_MAX
Definition _cfloat.h:66
#define DBL_MAX
Definition _cfloat.h:56
#define LC_NUMERIC
#define _RWSTD_LONG_LONG
#define _RWSTD_LDBL_PRINTF_PREFIX
Definition _config.h:381
#define _RWSTD_UNUSED(arg)
Definition _defs.h:972
const char * name
Definition codecvt1.cpp:72
std::mbstate_t init
Definition codecvt1.cpp:80
const char * str
Definition exec.cpp:170
unsigned long ULong
Definition fmt_defs.h:43
#define SHRT_MAX
Definition limits.h:64
#define INT_MIN
Definition limits.h:80
#define UCHAR_MAX
Definition limits.h:60
#define ULONG_MAX
Definition limits.h:96
#define CHAR_MIN
Definition limits.h:48
#define USHRT_MAX
Definition limits.h:72
#define CHAR_MAX
Definition limits.h:44
#define SCHAR_MAX
Definition limits.h:52
#define INT_MAX
Definition limits.h:76
#define SCHAR_MIN
Definition limits.h:56
#define UINT_MAX
Definition limits.h:84
#define SHRT_MIN
Definition limits.h:68
Definition json.h:5363
#define TOSTR(x)
Definition rw_any.h:148
_TEST_EXPORT int rw_enabled(const char *name)
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
Definition driver.cpp:1681
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
Definition driver.cpp:1664
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
Definition driver.cpp:1647
_TEST_EXPORT char * rw_locales(int=_UNUSED_CAT, const char *=0, bool=true)
Definition locale.cpp:368
int rw_equal(T x, T y)
Definition rw_valcmp.h:153
_TEST_EXPORT int rw_strncmp(const char *, const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX, int=CMP_NULTERM)
unsigned char UChar
Definition collate.cpp:122
Base::char_type char_type
static int n_widen_
std::ctype< charT > Base
virtual const char_type * do_widen(const char *lo, const char *hi, char_type *dst) const
virtual char_type do_widen(char c) const
iter_type get(iter_type, iter_type, std::ios_base &, std::ios_base::iostate &,...) const
virtual iter_type do_put(iter_type it, std::ios_base &f, char_type fill, bool v) const
std::num_put< charT, charT * > Base
virtual iter_type do_put(iter_type it, std::ios_base &f, char_type fill, long v) const
virtual iter_type do_put(iter_type it, std::ios_base &f, char_type fill, double v) const
virtual iter_type do_put(iter_type it, std::ios_base &f, char_type fill, long double v) const
static int ncalls_[13]
virtual iter_type do_put(iter_type it, std::ios_base &f, char_type fill, unsigned long v) const
NumPut(std::size_t ref=0)
virtual iter_type do_put(iter_type it, std::ios_base &f, char_type fill, const void *v) const
Base::char_type char_type
Base::iter_type iter_type
static const char_type * truename_
static const char_type * falsename_
Punct(std::size_t ref=0)
static char_type decimal_point_
std::numpunct< charT >::char_type char_type
virtual string_type do_truename() const
static int n_thousands_sep_
static int n_objs_
static const char * grouping_
static char_type thousands_sep_
std::numpunct< charT >::string_type string_type
virtual string_type do_falsename() const
virtual char_type do_decimal_point() const
virtual std::string do_grouping() const
virtual char_type do_thousands_sep() const
Base::char_type char_type
Base::string_type string_type