]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/manipulators/basefield/char/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / manipulators / basefield / char / 1.cc
CommitLineData
b2dad0e3
BK
1// 981027 ncm work with libstdc++v3
2
8d9254fc 3// Copyright (C) 1997-2020 Free Software Foundation, Inc.
b2dad0e3
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)
b2dad0e3
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/>.
b2dad0e3 19
b2dad0e3 20
b2dad0e3
BK
21#include <sstream>
22#include <locale>
23#include <iomanip>
fe413112 24#include <testsuite_hooks.h>
b2dad0e3
BK
25
26struct MyNP : std::numpunct<char>
27{
28 std::string do_grouping() const;
0be27b59 29 char do_thousands_sep() const;
b2dad0e3
BK
30};
31
0be27b59
PC
32std::string
33MyNP::do_grouping() const
34{
35 std::string s("\3");
36 return s;
37}
b2dad0e3 38
0be27b59
PC
39char
40MyNP::do_thousands_sep() const
41{ return ' '; }
23cac885
BK
42
43void test01()
b2dad0e3 44{
0be27b59
PC
45 const char lit[] = "0123 456\n"
46 ": 01 234 567:\n"
47 ":0123 456 :\n"
48 ": 012 345:\n"
49 ": 01 234:\n"
50 ":0726 746 425:\n"
51 ":04 553 207 :\n"
52 ": 0361 100:\n"
53 ": 0173:\n"
54 "0x12 345 678\n"
55 "|0x000012 345 678|\n"
56 "|0x12 345 6780000|\n"
57 "|00000x12 345 678|\n"
58 "|0x000012 345 678|\n";
2d13abcf 59
04fc1394
BK
60 std::ostringstream oss;
61 oss.imbue(std::locale(std::locale(), new MyNP));
658499e7
PC
62
63 // Octals
04fc1394 64 oss << std::oct << std::showbase;
bded68b1 65 oss << 0123456l << std::endl;
04fc1394
BK
66
67 oss << ":" << std::setw(11);
bded68b1 68 oss << 01234567l << ":" << std::endl;
04fc1394 69
bded68b1
PC
70 oss << ":" << std::setw(11) << std::left;
71 oss << 0123456l << ":" << std::endl;
04fc1394 72
bded68b1
PC
73 oss << ":" << std::setw(11) << std::right;
74 oss << 012345l << ":" << std::endl;
04fc1394 75
bded68b1
PC
76 oss << ":" << std::setw(11) << std::internal;
77 oss << 01234l << ":" << std::endl;
04fc1394 78
2d13abcf 79 oss << ":" << std::setw(11);
658499e7 80 oss << 123456789l << ":" << std::endl;
2d13abcf
PC
81
82 oss << ":" << std::setw(11) << std::left;
658499e7 83 oss << 1234567l << ":" << std::endl;
2d13abcf
PC
84
85 oss << ":" << std::setw(11) << std::right;
658499e7 86 oss << 123456l << ":" << std::endl;
2d13abcf
PC
87
88 oss << ":" << std::setw(11) << std::internal;
658499e7 89 oss << 123l << ":" << std::endl;
2d13abcf 90
658499e7
PC
91 // Hexadecimals
92 oss << std::hex << std::setfill('0');
04fc1394
BK
93 oss << 0x12345678l << std::endl;
94
658499e7
PC
95 oss << "|" << std::setw(16);
96 oss << 0x12345678l << "|" << std::endl;
97
98 oss << "|" << std::setw(16) << std::left;
99 oss << 0x12345678l << "|" << std::endl;
100
101 oss << "|" << std::setw(16) << std::right;
102 oss << 0x12345678l << "|" << std::endl;
103
104 oss << "|" << std::setw(16) << std::internal;
105 oss << 0x12345678l << "|" << std::endl;
106
04fc1394
BK
107 VERIFY( oss.good() );
108 VERIFY( oss.str() == lit );
b2dad0e3 109}
0be27b59 110
aa1b2f7d 111int
04fc1394
BK
112main()
113{
b2dad0e3
BK
114 test01();
115 return 0;
116}