| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <ostream> |
| 10 | |
| 11 | // template <class charT, class traits = char_traits<charT> > |
| 12 | // class basic_ostream; |
| 13 | |
| 14 | // template <class charT, class traits> |
| 15 | // basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os); |
| 16 | |
| 17 | #include <ostream> |
| 18 | #include <cassert> |
| 19 | |
| 20 | #include "test_macros.h" |
| 21 | |
| 22 | int sync_called = 0; |
| 23 | |
| 24 | template <class CharT> |
| 25 | class testbuf |
| 26 | : public std::basic_streambuf<CharT> |
| 27 | { |
| 28 | public: |
| 29 | testbuf() |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | protected: |
| 34 | |
| 35 | virtual int |
| 36 | sync() |
| 37 | { |
| 38 | ++sync_called; |
| 39 | return 0; |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | int main(int, char**) |
| 44 | { |
| 45 | { |
| 46 | testbuf<char> sb; |
| 47 | std::ostream os(&sb); |
| 48 | std::flush(os); |
| 49 | assert(sync_called == 1); |
| 50 | assert(os.good()); |
| 51 | } |
| 52 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 53 | { |
| 54 | testbuf<wchar_t> sb; |
| 55 | std::wostream os(&sb); |
| 56 | std::flush(os); |
| 57 | assert(sync_called == 2); |
| 58 | assert(os.good()); |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |