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: testbuf()29 testbuf() 30 { 31 } 32 33 protected: 34 35 virtual int sync()36 sync() 37 { 38 ++sync_called; 39 return 0; 40 } 41 }; 42 main(int,char **)43int main(int, char**) 44 { 45 { 46 testbuf<char> sb; 47 std::ostream os(&sb); 48 flush(os); 49 assert(sync_called == 1); 50 assert(os.good()); 51 } 52 { 53 testbuf<wchar_t> sb; 54 std::wostream os(&sb); 55 flush(os); 56 assert(sync_called == 2); 57 assert(os.good()); 58 } 59 60 return 0; 61 } 62