]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/1.cc
1 // 1999-11-15 Kevin Ediger <kediger@licor.com>
2 // test the floating point inserters (facet num_put)
4 // Copyright (C) 1999-2019 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
25 #include <testsuite_hooks.h>
53 static _TestCase testcases
[] =
55 // standard output (no formatting applied)
56 { 1.2, 6,0,'.',' ', F
,F
,F
,F
,F
,F
,F
,F
, "1.2" },
57 { 54, 6,0,'.',' ', F
,F
,F
,F
,F
,F
,F
,F
, "54" },
58 { -.012, 6,0,'.',' ', F
,F
,F
,F
,F
,F
,F
,F
, "-0.012" },
59 { -.00000012, 6,0,'.',' ', F
,F
,F
,F
,F
,F
,F
,F
, "-1.2e-07" },
62 { 10.2345, 0,0,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10" },
63 { 10.2345, 0,0,'.',' ', T
,F
,F
,T
,F
,F
,F
,F
, "10." },
64 { 10.2345, 1,0,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10.2" },
65 { 10.2345, 4,0,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10.2345" },
66 { 10.2345, 6,0,'.',' ', T
,F
,T
,F
,F
,F
,F
,F
, "+10.234500" },
67 { -10.2345, 6,0,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "-10.234500" },
68 { -10.2345, 6,0,',',' ', T
,F
,F
,F
,F
,F
,F
,F
, "-10,234500" },
70 // fixed formatting with width
71 { 10.2345, 4,5,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10.2345" },
72 { 10.2345, 4,6,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10.2345" },
73 { 10.2345, 4,7,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10.2345" },
74 { 10.2345, 4,8,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, " 10.2345" },
75 { 10.2345, 4,10,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, " 10.2345" },
76 { 10.2345, 4,10,'.',' ', T
,F
,F
,F
,F
,F
,T
,F
, "10.2345 " },
77 { 10.2345, 4,10,'.',' ', T
,F
,F
,F
,F
,F
,F
,T
, " 10.2345" },
78 { 10.2345, 4,10,'.',' ', T
,F
,F
,F
,F
,T
,F
,F
, " 10.2345" },
79 { -10.2345, 4,10,'.',' ', T
,F
,F
,F
,F
,T
,F
,F
, "- 10.2345" },
80 { -10.2345, 4,10,'.','A', T
,F
,F
,F
,F
,T
,F
,F
, "-AA10.2345" },
81 { 10.2345, 4,10,'.','#', T
,F
,T
,F
,F
,T
,F
,F
, "+##10.2345" },
83 // scientific formatting
84 { 1.23e+12, 1,0,'.',' ', F
,T
,F
,F
,F
,F
,F
,F
, "1.2e+12" },
85 { 1.23e+12, 1,0,'.',' ', F
,T
,F
,F
,T
,F
,F
,F
, "1.2E+12" },
86 { 1.23e+12, 2,0,'.',' ', F
,T
,F
,F
,F
,F
,F
,F
, "1.23e+12" },
87 { 1.23e+12, 3,0,'.',' ', F
,T
,F
,F
,F
,F
,F
,F
, "1.230e+12" },
88 { 1.23e+12, 3,0,'.',' ', F
,T
,T
,F
,F
,F
,F
,F
, "+1.230e+12" },
89 { -1.23e-12, 3,0,'.',' ', F
,T
,F
,F
,F
,F
,F
,F
, "-1.230e-12" },
90 { 1.23e+12, 3,0,',',' ', F
,T
,F
,F
,F
,F
,F
,F
, "1,230e+12" },
93 template<typename _CharT
>
94 class testpunct
: public numpunct
<_CharT
>
97 typedef _CharT char_type
;
98 const char_type dchar
;
101 testpunct(char_type decimal_char
) : numpunct
<_CharT
>(), dchar(decimal_char
)
106 do_decimal_point() const
110 do_thousands_sep() const
118 template<typename _CharT
>
119 void apply_formatting(const _TestCase
& tc
, basic_ostream
<_CharT
> & os
)
121 os
.precision(tc
.precision
);
123 os
.fill(static_cast<_CharT
>(tc
.fill
));
127 os
.setf(ios::scientific
);
129 os
.setf(ios::showpos
);
131 os
.setf(ios::showpoint
);
133 os
.setf(ios::uppercase
);
135 os
.setf(ios::internal
);
145 for (std::size_t j
= 0; j
<sizeof(testcases
)/sizeof(testcases
[0]); j
++)
147 _TestCase
& tc
= testcases
[j
];
148 #ifdef TEST_NUMPUT_VERBOSE
149 cout
<< "expect: " << tc
.result
<< endl
;
151 // test double with char type
153 testpunct
<char>* __tp
= new testpunct
<char>(tc
.decimal
);
155 locale
__loc(os
.getloc(), __tp
);
157 apply_formatting(tc
, os
);
159 #ifdef TEST_NUMPUT_VERBOSE
160 cout
<< j
<< "result 1: " << os
.str() << endl
;
162 VERIFY( os
&& os
.str() == tc
.result
);
164 // test long double with char type
166 testpunct
<char>* __tp
= new testpunct
<char>(tc
.decimal
);
168 locale
__loc(os
.getloc(), __tp
);
170 apply_formatting(tc
, os
);
171 os
<< (long double)tc
.val
;
172 #ifdef TEST_NUMPUT_VERBOSE
173 cout
<< j
<< "result 2: " << os
.str() << endl
;
175 VERIFY( os
&& os
.str() == tc
.result
);