Debian Codegraph @

libstdc++-v3/testsuite/27_io/basic_istream/ws/char/lwg415.cc

raw symbols SCIP
1 #include <istream>
2
3 // C++11 27.7.2.4 Standard basic_istream manipulators [istream.manip]
4 //
5 // LWG 415. behavior of std::ws
6 // std::ws is an unformatted input function.
7
8 #include <istream>
9 #include <testsuite_hooks.h>
10 #include <testsuite_io.h>
11
12 void
13 test01()
14 {
15 std::istream is(0);
16 VERIFY( is.rdstate() == std::ios_base::badbit );
17
18 is >> std::ws; // sentry should set failbit
19 VERIFY( is.rdstate() & std::ios_base::failbit );
20 }
21
22 void
23 test02()
24 {
25 __gnu_test::sync_streambuf buf;
26 std::istream is(&buf);
27
28 __gnu_test::sync_streambuf buf_tie;
29 std::ostream os_tie(&buf_tie);
30
31 // A sentry should be constructed so is.tie()->flush() should be called.
32 // The standard allows the flush to be deferred because the put area of
33 // is_tie is empty, but libstdc++ doesn't defer it.
34 is.tie(&os_tie);
35
36 is >> std::ws;
37
38 VERIFY( is.eof() );
39 VERIFY( !is.fail() );
40 VERIFY( ! buf.sync_called() );
41 VERIFY( buf_tie.sync_called() );
42 }
43
44 void
45 test03()
46 {
47 __gnu_test::fail_streambuf buf;
48 std::istream is(&buf);
49
50 char c;
51 is >> c >> std::ws;
52 VERIFY( is.rdstate() == std::ios_base::badbit );
53
54 is.clear();
55 is.exceptions(std::ios_base::badbit);
56
57 try
58 {
59 is >> std::ws;
60 VERIFY( false );
61 }
62 catch (const __gnu_test::underflow_error&)
63 {
64 VERIFY( is.rdstate() == std::ios_base::badbit );
65 }
66 catch (...)
67 {
68 VERIFY( false );
69 }
70 }
71
72 int main()
73 {
74 test01();
75 test02();
76 test03();
77 }