]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / num_put / put / wchar_t / 2.cc
CommitLineData
5f8d36fe
BK
1// 2001-11-19 Benjamin Kosnik <bkoz@redhat.com>
2
a5544970 3// Copyright (C) 2001-2019 Free Software Foundation, Inc.
5f8d36fe
BK
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
5f8d36fe
BK
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
5f8d36fe
BK
19
20// 22.2.2.2.1 num_put members
21
22#include <locale>
23#include <sstream>
24#include <testsuite_hooks.h>
25
26void test02()
27{
28 using namespace std;
29 typedef ostreambuf_iterator<wchar_t> iterator_type;
30
5f8d36fe
BK
31 // basic construction
32 locale loc_c = locale::classic();
5f8d36fe 33
5f8d36fe
BK
34 // sanity check the data is correct.
35 const wstring empty;
36 wstring result1;
37 wstring result2;
5f8d36fe
BK
38
39 bool b1 = true;
40 bool b0 = false;
5f8d36fe
BK
41 unsigned long ul1 = 1294967294;
42 unsigned long ul2 = 0;
5f8d36fe
BK
43
44 // cache the num_put facet
45 wostringstream oss;
46 oss.imbue(loc_c);
47 const num_put<wchar_t>& np = use_facet<num_put<wchar_t> >(oss.getloc());
48
49 // C
50 // bool, more twisted examples
51 oss.str(empty);
52 oss.width(20);
53 oss.setf(ios_base::right, ios_base::adjustfield);
fea6ecb7 54 np.put(oss.rdbuf(), oss, L'+', b0);
5f8d36fe
BK
55 result1 = oss.str();
56 VERIFY( result1 == L"+++++++++++++++++++0" );
57
58 oss.str(empty);
59 oss.width(20);
60 oss.setf(ios_base::left, ios_base::adjustfield);
61 oss.setf(ios_base::boolalpha);
fea6ecb7 62 np.put(oss.rdbuf(), oss, L'+', b1);
5f8d36fe
BK
63 result2 = oss.str();
64 VERIFY( result2 == L"true++++++++++++++++" );
65
66 // unsigned long, in a locale that does not group
67 oss.imbue(loc_c);
68 oss.str(empty);
69 oss.clear();
fea6ecb7 70 np.put(oss.rdbuf(), oss, L'+', ul1);
5f8d36fe
BK
71 result1 = oss.str();
72 VERIFY( result1 == L"1294967294" );
73
74 oss.str(empty);
75 oss.clear();
76 oss.width(20);
77 oss.setf(ios_base::left, ios_base::adjustfield);
fea6ecb7 78 np.put(oss.rdbuf(), oss, L'+', ul2);
5f8d36fe
BK
79 result1 = oss.str();
80 VERIFY( result1 == L"0+++++++++++++++++++" );
81}
82
83int main()
84{
85 test02();
86 return 0;
87}