]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/1.cc
3ec7398fe47d80e75574b922301eda5fc141ed08
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>
48 const wchar_t* wresult
;
54 static _TestCase testcases
[] =
56 // standard output (no formatting applied) 1-4
57 { 1.2, 6,0,'.',' ', F
,F
,F
,F
,F
,F
,F
,F
, "1.2",L
"1.2" },
58 { 54, 6,0,'.',' ', F
,F
,F
,F
,F
,F
,F
,F
, "54",L
"54" },
59 { -.012, 6,0,'.',' ', F
,F
,F
,F
,F
,F
,F
,F
, "-0.012",L
"-0.012" },
60 { -.00000012, 6,0,'.',' ', F
,F
,F
,F
,F
,F
,F
,F
, "-1.2e-07",L
"-1.2e-07" },
62 // fixed formatting 5-11
63 { 10.2345, 0,0,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10",L
"10" },
64 { 10.2345, 0,0,'.',' ', T
,F
,F
,T
,F
,F
,F
,F
, "10.",L
"10." },
65 { 10.2345, 1,0,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10.2",L
"10.2" },
66 { 10.2345, 4,0,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10.2345",L
"10.2345" },
67 { 10.2345, 6,0,'.',' ', T
,F
,T
,F
,F
,F
,F
,F
, "+10.234500",L
"+10.234500" },
68 { -10.2345, 6,0,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "-10.234500",L
"-10.234500" },
69 { -10.2345, 6,0,',',' ', T
,F
,F
,F
,F
,F
,F
,F
, "-10,234500",L
"-10,234500" },
71 // fixed formatting with width 12-22
72 { 10.2345, 4,5,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10.2345",L
"10.2345" },
73 { 10.2345, 4,6,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10.2345",L
"10.2345" },
74 { 10.2345, 4,7,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, "10.2345",L
"10.2345" },
75 { 10.2345, 4,8,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, " 10.2345",L
" 10.2345" },
76 { 10.2345, 4,10,'.',' ', T
,F
,F
,F
,F
,F
,F
,F
, " 10.2345",L
" 10.2345" },
77 { 10.2345, 4,10,'.',' ', T
,F
,F
,F
,F
,F
,T
,F
, "10.2345 ",L
"10.2345 " },
78 { 10.2345, 4,10,'.',' ', T
,F
,F
,F
,F
,F
,F
,T
, " 10.2345",L
" 10.2345" },
79 { 10.2345, 4,10,'.',' ', T
,F
,F
,F
,F
,T
,F
,F
, " 10.2345",L
" 10.2345" },
80 { -10.2345, 4,10,'.',' ', T
,F
,F
,F
,F
,T
,F
,F
, "- 10.2345",L
"- 10.2345" },
81 { -10.2345, 4,10,'.','A', T
,F
,F
,F
,F
,T
,F
,F
, "-AA10.2345",L
"-AA10.2345" },
82 { 10.2345, 4,10,'.','#', T
,F
,T
,F
,F
,T
,F
,F
, "+##10.2345",L
"+##10.2345" },
84 // scientific formatting 23-29
85 { 1.23e+12, 1,0,'.',' ', F
,T
,F
,F
,F
,F
,F
,F
, "1.2e+12",L
"1.2e+12" },
86 { 1.23e+12, 1,0,'.',' ', F
,T
,F
,F
,T
,F
,F
,F
, "1.2E+12",L
"1.2E+12" },
87 { 1.23e+12, 2,0,'.',' ', F
,T
,F
,F
,F
,F
,F
,F
, "1.23e+12",L
"1.23e+12" },
88 { 1.23e+12, 3,0,'.',' ', F
,T
,F
,F
,F
,F
,F
,F
, "1.230e+12",L
"1.230e+12" },
89 { 1.23e+12, 3,0,'.',' ', F
,T
,T
,F
,F
,F
,F
,F
, "+1.230e+12",L
"+1.230e+12" },
90 { -1.23e-12, 3,0,'.',' ', F
,T
,F
,F
,F
,F
,F
,F
, "-1.230e-12",L
"-1.230e-12" },
91 { 1.23e+12, 3,0,',',' ', F
,T
,F
,F
,F
,F
,F
,F
, "1,230e+12",L
"1,230e+12" },
94 template<typename _CharT
>
95 class testpunct
: public numpunct
<_CharT
>
98 typedef _CharT char_type
;
99 const char_type dchar
;
102 testpunct(char_type decimal_char
) : numpunct
<_CharT
>(), dchar(decimal_char
)
107 do_decimal_point() const
111 do_thousands_sep() const
119 template<typename _CharT
>
120 void apply_formatting(const _TestCase
& tc
, basic_ostream
<_CharT
> & os
)
122 os
.precision(tc
.precision
);
124 os
.fill(static_cast<_CharT
>(tc
.fill
));
128 os
.setf(ios::scientific
);
130 os
.setf(ios::showpos
);
132 os
.setf(ios::showpoint
);
134 os
.setf(ios::uppercase
);
136 os
.setf(ios::internal
);
146 for (std::size_t j
= 0; j
<sizeof(testcases
)/sizeof(testcases
[0]); j
++)
148 _TestCase
& tc
= testcases
[j
];
149 #ifdef TEST_NUMPUT_VERBOSE
150 cout
<< "expect: " << tc
.result
<< endl
;
152 // test double with wchar_t type
154 testpunct
<wchar_t>* __tp
= new testpunct
<wchar_t>(tc
.decimal
);
156 locale
__loc(os
.getloc(), __tp
);
158 apply_formatting(tc
, os
);
160 VERIFY( os
&& os
.str() == tc
.wresult
);
162 // test long double with wchar_t type
164 testpunct
<wchar_t>* __tp
= new testpunct
<wchar_t>(tc
.decimal
);
166 locale
__loc(os
.getloc(), __tp
);
168 apply_formatting(tc
, os
);
169 os
<< (long double)tc
.val
;
170 VERIFY( os
&& os
.str() == tc
.wresult
);