]>
Commit | Line | Data |
---|---|---|
b9e8095b | 1 | // 981027 ncm work with libstdc++v3 |
2 | ||
fbd26352 | 3 | // Copyright (C) 1997-2019 Free Software Foundation, Inc. |
b9e8095b | 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 | |
6bc9506f | 8 | // Free Software Foundation; either version 3, or (at your option) |
b9e8095b | 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 | |
6bc9506f | 17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
b9e8095b | 19 | |
b9e8095b | 20 | |
b9e8095b | 21 | #include <sstream> |
22 | #include <locale> | |
23 | #include <iomanip> | |
0194306c | 24 | #include <testsuite_hooks.h> |
b9e8095b | 25 | |
26 | struct MyNP : std::numpunct<char> | |
27 | { | |
28 | std::string do_grouping() const; | |
d1d78ccb | 29 | char do_thousands_sep() const; |
b9e8095b | 30 | }; |
31 | ||
d1d78ccb | 32 | std::string |
33 | MyNP::do_grouping() const | |
34 | { | |
35 | std::string s("\3"); | |
36 | return s; | |
37 | } | |
b9e8095b | 38 | |
d1d78ccb | 39 | char |
40 | MyNP::do_thousands_sep() const | |
41 | { return ' '; } | |
a2febbfb | 42 | |
43 | void test01() | |
b9e8095b | 44 | { |
d1d78ccb | 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"; | |
8ed36d83 | 59 | |
4a330102 | 60 | std::ostringstream oss; |
61 | oss.imbue(std::locale(std::locale(), new MyNP)); | |
f64a4e44 | 62 | |
63 | // Octals | |
4a330102 | 64 | oss << std::oct << std::showbase; |
8de4c915 | 65 | oss << 0123456l << std::endl; |
4a330102 | 66 | |
67 | oss << ":" << std::setw(11); | |
8de4c915 | 68 | oss << 01234567l << ":" << std::endl; |
4a330102 | 69 | |
8de4c915 | 70 | oss << ":" << std::setw(11) << std::left; |
71 | oss << 0123456l << ":" << std::endl; | |
4a330102 | 72 | |
8de4c915 | 73 | oss << ":" << std::setw(11) << std::right; |
74 | oss << 012345l << ":" << std::endl; | |
4a330102 | 75 | |
8de4c915 | 76 | oss << ":" << std::setw(11) << std::internal; |
77 | oss << 01234l << ":" << std::endl; | |
4a330102 | 78 | |
8ed36d83 | 79 | oss << ":" << std::setw(11); |
f64a4e44 | 80 | oss << 123456789l << ":" << std::endl; |
8ed36d83 | 81 | |
82 | oss << ":" << std::setw(11) << std::left; | |
f64a4e44 | 83 | oss << 1234567l << ":" << std::endl; |
8ed36d83 | 84 | |
85 | oss << ":" << std::setw(11) << std::right; | |
f64a4e44 | 86 | oss << 123456l << ":" << std::endl; |
8ed36d83 | 87 | |
88 | oss << ":" << std::setw(11) << std::internal; | |
f64a4e44 | 89 | oss << 123l << ":" << std::endl; |
8ed36d83 | 90 | |
f64a4e44 | 91 | // Hexadecimals |
92 | oss << std::hex << std::setfill('0'); | |
4a330102 | 93 | oss << 0x12345678l << std::endl; |
94 | ||
f64a4e44 | 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 | ||
4a330102 | 107 | VERIFY( oss.good() ); |
108 | VERIFY( oss.str() == lit ); | |
b9e8095b | 109 | } |
d1d78ccb | 110 | |
43a8c05a | 111 | int |
4a330102 | 112 | main() |
113 | { | |
b9e8095b | 114 | test01(); |
115 | return 0; | |
116 | } |