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