]>
Commit | Line | Data |
---|---|---|
a945c346 | 1 | // Copyright (C) 2005-2024 Free Software Foundation, Inc. |
ba4b172f PC |
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 | |
748086b7 | 6 | // Free Software Foundation; either version 3, or (at your option) |
ba4b172f PC |
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 | |
748086b7 JJ |
15 | // with this library; see the file COPYING3. If not see |
16 | // <http://www.gnu.org/licenses/>. | |
ba4b172f PC |
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. | |
f8c5b542 JW |
23 | // But wait ... |
24 | // 581. flush() not unformatted function | |
25 | // So now basic_ostream::flush() *is* an unformatted output function. | |
ba4b172f PC |
26 | |
27 | #include <ostream> | |
28 | #include <testsuite_hooks.h> | |
29 | #include <testsuite_io.h> | |
30 | ||
f8c5b542 JW |
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 | ||
ba4b172f PC |
45 | void test02() |
46 | { | |
ba4b172f PC |
47 | __gnu_test::sync_wstreambuf buf; |
48 | std::wostream os(&buf); | |
f8c5b542 | 49 | |
ba4b172f PC |
50 | __gnu_test::sync_wstreambuf buf_tie; |
51 | std::wostream os_tie(&buf_tie); | |
52 | ||
f8c5b542 | 53 | // A sentry should be constructed so os.tie()->flush() should be called. |
ba4b172f | 54 | os.tie(&os_tie); |
f8c5b542 | 55 | |
ba4b172f PC |
56 | os.flush(); |
57 | ||
58 | VERIFY( os.good() ); | |
59 | VERIFY( buf.sync_called() ); | |
f8c5b542 JW |
60 | VERIFY( buf_tie.sync_called() ); |
61 | } | |
ba4b172f | 62 | |
f8c5b542 JW |
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(). | |
ba4b172f PC |
75 | os.setstate(std::ios_base::eofbit); |
76 | ||
77 | os.flush(); | |
78 | ||
f8c5b542 JW |
79 | VERIFY( os.rdstate() & std::ios_base::eofbit ); |
80 | VERIFY( !buf.sync_called() ); | |
ba4b172f PC |
81 | VERIFY( !buf_tie.sync_called() ); |
82 | } | |
83 | ||
84 | int main() | |
85 | { | |
f8c5b542 | 86 | test01(); |
ba4b172f | 87 | test02(); |
f8c5b542 | 88 | test03(); |
ba4b172f | 89 | } |