]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/narrow_stream_objects.cc
install.html: Document complete list of locales required by test suite.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / narrow_stream_objects.cc
CommitLineData
86b8dde6 1// 2000-08-02 bkoz
b2dad0e3 2
d02475fd 3// Copyright (C) 2000, 2001, 2002 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
8// Free Software Foundation; either version 2, 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 COPYING. If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
21// Include all the headers except for iostream.
22#include <algorithm>
23#include <bitset>
24#include <complex>
25#include <deque>
26#include <exception>
27#include <fstream>
28#include <functional>
29#include <iomanip>
30#include <ios>
31#include <iosfwd>
32#include <istream>
33#include <iterator>
34#include <limits>
35#include <list>
36#include <locale>
37#include <map>
38#include <memory>
39#include <new>
40#include <numeric>
41#include <ostream>
42#include <queue>
43#include <set>
44#include <sstream>
45#include <stack>
46#include <stdexcept>
47#include <streambuf>
48#include <string>
49#include <typeinfo>
50#include <utility>
51#include <valarray>
52#include <vector>
53#include <cassert>
54#include <cctype>
55#include <cerrno>
56#include <cfloat>
57#include <ciso646>
58#include <climits>
59#include <clocale>
60#include <cmath>
61#include <csetjmp>
62#include <csignal>
63#include <cstdarg>
64#include <cstddef>
65#include <cstdio>
66#include <cstdlib>
67#include <cstring>
68#include <ctime>
f45f9aed 69#include <testsuite_hooks.h>
b2dad0e3
BK
70
71// Include iostream last, just to make is as difficult as possible to
72// properly initialize the standard iostream objects.
73#include <iostream>
74
75// Make sure all the standard streams are defined.
aa1b2f7d
BV
76int
77test01()
b2dad0e3
BK
78{
79 bool test = true;
80
81 char array1[20];
82 typedef std::ios::traits_type ctraits_type;
83 ctraits_type::int_type i = 15;
84 ctraits_type::copy(array1, "testing istream", i);
85 array1[i] = '\0';
86 std::cout << "testing cout" << std::endl;
87 std::cerr << "testing cerr" << std::endl;
aa1b2f7d 88 VERIFY( std::cerr.flags() & std::ios_base::unitbuf );
b2dad0e3
BK
89 std::clog << "testing clog" << std::endl;
90 // std::cin >> array1; // requires somebody to type something in.
aa1b2f7d 91 VERIFY( std::cin.tie() == &std::cout );
b2dad0e3 92
aa1b2f7d 93 return 0;
b2dad0e3
BK
94}
95
39003c99
BK
96// libstdc++/2523
97void test02()
98{
ee2f20b9 99 using namespace std;
39003c99
BK
100 int i;
101 cin >> i;
102 cout << "i == " << i << endl;
103}
104
105// libstdc++/2523
106void test03()
107{
ee2f20b9 108 using namespace std;
39003c99
BK
109 ios_base::sync_with_stdio(false);
110
111 int i;
112 cin >> i;
113 cout << "i == " << i << endl;
114}
b2dad0e3 115
9385d9cb
LR
116// Interactive test, to be exercised as follows:
117// assign stderr to stdout in shell command line,
118// pipe stdout to cat process and/or redirect stdout to file.
a2554733
DS
119// a.out >& output
120// "hello fine world\n" should be written to stdout, and output, in
121// proper order. This is a version of the scott snyder test taken
122// from: http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00108.html
9385d9cb
LR
123void test04()
124{
125 using namespace std;
126
127 cout << "hello ";
a2554733 128 cout.flush();
9385d9cb 129 cerr << "fine ";
a2554733 130 cerr.flush();
9385d9cb 131 cout << "world" << endl;
a2554733 132 cout.flush();
9385d9cb
LR
133}
134
135// Interactive test, to be exercised as follows:
136// run test under truss(1) or strace(1). Look at
137// size and pattern of write system calls.
138// Should be 2 or 3 write(1,[...]) calls when run interactively
139// depending upon buffering mode enforced.
140void test05()
141{
a2554733 142 std::cout << "hello" << ' ' << "world" << std::endl;
9385d9cb
LR
143 std::cout << "Enter your name: ";
144 std::string s;
145 std::cin >> s;
146 std::cout << "hello " << s << std::endl;
147}
148
d02475fd
BK
149// libstdc++/5280
150// Interactive test: input "1234^D^D" for i should terminate for EOF.
151void test06()
152{
153 using namespace std;
154 int i;
155 cin >> i;
156 if (!cin.good())
157 {
158 cerr << endl;
159 cerr << "i == " << i << endl;
160 cerr << "cin.rdstate() == " << cin.rdstate() << endl;
161 cerr << "cin.bad() == " << cin.bad() << endl;
162 cerr << "cin.fail() == " << cin.fail() << endl;
163 cerr << "cin.eof() == " << cin.eof() << endl;
164 }
165 else
166 cerr << "i == " << i << endl;
167}
168
2fd819ef
BK
169// libstdc++/6548
170void test07()
171{
172 bool test = true;
a2554733 173 std::cout << "Enter 'test':";
2fd819ef
BK
174 std::string s;
175 std::getline(std::cin, s, '\n');
176 VERIFY( s == "test" );
177}
178
bf6f276b
PC
179// libstdc++/6648
180// Interactive tests: each one (run alone) must terminate upon a single '\n'.
181void test08()
182{
183 bool test = true;
184 char buff[2048];
185 std::cout << "Enter name: ";
186 std::cin.getline(buff, 2048);
187}
188
189void test09()
190{
191 bool test = true;
a2554733 192 std::cout << "Enter favorite beach: ";
bf6f276b
PC
193 std::cin.ignore(2048, '\n');
194}
195
a2554733
DS
196// http://gcc.gnu.org/ml/libstdc++/2002-08/msg00060.html
197// Should only have to hit enter once.
198void
199test10()
200{
201 using namespace std;
202 cout << "Press ENTER once\n";
203 cin.ignore(1);
204 cout << "_M_gcount: "<< cin.gcount() << endl;
205}
206
95dca20c
PC
207// libstdc++/7744
208void test11()
209{
210 std::ios::sync_with_stdio(false);
211
212 std::cout
213 << "\n:: f2() ::\n"
214 << "Type in the characters 'abc' and press <ENTER>: ";
215 std::cin.peek();
216
217 std::cout
218 << "The number of unread characters should be 4 (a, b, c, \\n): "
219 << std::cin.rdbuf()->in_avail()
220 << '\n';
221}
222
aa1b2f7d
BV
223int
224main()
b2dad0e3
BK
225{
226 test01();
39003c99
BK
227
228 // test02();
229 // test03();
9385d9cb
LR
230 // test04();
231 // test05();
d02475fd 232 // test06();
2fd819ef 233 // test07();
bf6f276b
PC
234 // test08();
235 // test09();
a2554733 236 // test10();
95dca20c 237 // test11();
b2dad0e3
BK
238 return 0;
239}