2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / manipulators / basefield / char / 1.cc
blobf16eb1a9c6c8c8d1120031b384b59ad02712da25
1 // 981027 ncm work with libstdc++v3
3 // Copyright (C) 1997, 1998, 1999, 2002 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 2, or (at your option)
9 // any later version.
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 #include <sstream>
31 #include <locale>
32 #include <iomanip>
33 #include <testsuite_hooks.h>
35 struct MyNP : std::numpunct<char>
37 std::string do_grouping() const;
38 char do_thousands_sep() const;
41 std::string MyNP::do_grouping() const { std::string s("\3"); return s; }
42 char MyNP::do_thousands_sep() const { return ' '; }
45 void test01()
47 bool test __attribute__((unused)) = true;
49 const char lit[] = "0123 456\n: 01 234 567:\n:0123 456 :\n"
50 ": 012 345:\n: 01 234:\n:0726 746 425:\n"
51 ":04 553 207 :\n: 0361 100:\n: 0173:\n"
52 "0x12 345 678\n|0x000012 345 678|\n|0x12 345 6780000|\n"
53 "|00000x12 345 678|\n|0x000012 345 678|\n";
55 std::ostringstream oss;
56 oss.imbue(std::locale(std::locale(), new MyNP));
58 // Octals
59 oss << std::oct << std::showbase;
60 oss << 0123456l << std::endl;
62 oss << ":" << std::setw(11);
63 oss << 01234567l << ":" << std::endl;
65 oss << ":" << std::setw(11) << std::left;
66 oss << 0123456l << ":" << std::endl;
68 oss << ":" << std::setw(11) << std::right;
69 oss << 012345l << ":" << std::endl;
71 oss << ":" << std::setw(11) << std::internal;
72 oss << 01234l << ":" << std::endl;
74 oss << ":" << std::setw(11);
75 oss << 123456789l << ":" << std::endl;
77 oss << ":" << std::setw(11) << std::left;
78 oss << 1234567l << ":" << std::endl;
80 oss << ":" << std::setw(11) << std::right;
81 oss << 123456l << ":" << std::endl;
83 oss << ":" << std::setw(11) << std::internal;
84 oss << 123l << ":" << std::endl;
86 // Hexadecimals
87 oss << std::hex << std::setfill('0');
88 oss << 0x12345678l << std::endl;
90 oss << "|" << std::setw(16);
91 oss << 0x12345678l << "|" << std::endl;
93 oss << "|" << std::setw(16) << std::left;
94 oss << 0x12345678l << "|" << std::endl;
96 oss << "|" << std::setw(16) << std::right;
97 oss << 0x12345678l << "|" << std::endl;
99 oss << "|" << std::setw(16) << std::internal;
100 oss << 0x12345678l << "|" << std::endl;
102 VERIFY( oss.good() );
103 VERIFY( oss.str() == lit );
105 int
106 main()
108 test01();
109 return 0;
112 // Projected output:
114 0123 456
115 : 01 234 567:
116 :0123 456 :
117 : 012 345:
118 : 01 234:
119 :0726 746 425:
120 :04 553 207 :
121 : 0361 100:
122 : 0173:
123 0x12 345 678
124 |0x000012 345 678|
125 |0x12 345 6780000|
126 |00000x12 345 678|
127 |0x000012 345 678|