Debian Codegraph @

libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/2.cc

raw
1 // Copyright (C) 2005-2025 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // 27.6.2.6 Unformatted output functions
19 //
20 // _GLIBCXX_RESOLVE_LIB_DEFECTS
21 // DR 60. What is a formatted input function?
22 // basic_ostream::flush() does not behave as an unformatted output function.
23 // But wait ...
24 // 581. flush() not unformatted function
25 // So now basic_ostream::flush() *is* an unformatted output function.
26
27 #include <ostream>
28 #include <testsuite_hooks.h>
29 #include <testsuite_io.h>
30
31 void
32 test01()
33 {
34 std::wostream os(0);
35 VERIFY( os.bad() );
36
37 // Nothing should happen if os.rdbuf() is null. No sentry is constructed.
38 os.flush();
39 VERIFY( os.rdstate() == std::ios_base::badbit ); // no failbit
40
41 os.exceptions(std::ios_base::failbit);
42 os.flush();
43 }
44
45 void test02()
46 {
47 __gnu_test::sync_wstreambuf buf;
48 std::wostream os(&buf);
49
50 __gnu_test::sync_wstreambuf buf_tie;
51 std::wostream os_tie(&buf_tie);
52
53 // A sentry should be constructed so os.tie()->flush() should be called.
54 os.tie(&os_tie);
55
56 os.flush();
57
58 VERIFY( os.good() );
59 VERIFY( buf.sync_called() );
60 VERIFY( buf_tie.sync_called() );
61 }
62
63 void
64 test03()
65 {
66 __gnu_test::sync_wstreambuf buf;
67 std::wostream os(&buf);
68
69 __gnu_test::sync_wstreambuf buf_tie;
70 std::wostream os_tie(&buf_tie);
71
72 os.tie(&os_tie);
73
74 // os.rdbuf()->pubsync() should not be called if !os.good().
75 os.setstate(std::ios_base::eofbit);
76
77 os.flush();
78
79 VERIFY( os.rdstate() & std::ios_base::eofbit );
80 VERIFY( !buf.sync_called() );
81 VERIFY( !buf_tie.sync_called() );
82 }
83
84 int main()
85 {
86 test01();
87 test02();
88 test03();
89 }