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 // void swap(basic_ostream& rhs); 15 16 #include <ostream> 17 #include <cassert> 18 19 #include "test_macros.h" 20 21 template <class CharT> 22 struct testbuf 23 : public std::basic_streambuf<CharT> 24 { testbuftestbuf25 testbuf() {} 26 }; 27 28 template <class CharT> 29 struct test_ostream 30 : public std::basic_ostream<CharT> 31 { 32 typedef std::basic_ostream<CharT> base; test_ostreamtest_ostream33 test_ostream(testbuf<CharT>* sb) : base(sb) {} 34 swaptest_ostream35 void swap(test_ostream& s) {base::swap(s);} 36 }; 37 main(int,char **)38int main(int, char**) 39 { 40 { 41 testbuf<char> sb1; 42 testbuf<char> sb2; 43 test_ostream<char> os1(&sb1); 44 test_ostream<char> os2(&sb2); 45 os1.swap(os2); 46 assert(os1.rdbuf() == &sb1); 47 assert(os1.tie() == 0); 48 assert(os1.fill() == ' '); 49 assert(os1.rdstate() == os1.goodbit); 50 assert(os1.exceptions() == os1.goodbit); 51 assert(os1.flags() == (os1.skipws | os1.dec)); 52 assert(os1.precision() == 6); 53 assert(os1.getloc().name() == "C"); 54 assert(os2.rdbuf() == &sb2); 55 assert(os2.tie() == 0); 56 assert(os2.fill() == ' '); 57 assert(os2.rdstate() == os2.goodbit); 58 assert(os2.exceptions() == os2.goodbit); 59 assert(os2.flags() == (os2.skipws | os2.dec)); 60 assert(os2.precision() == 6); 61 assert(os2.getloc().name() == "C"); 62 } 63 { 64 testbuf<wchar_t> sb1; 65 testbuf<wchar_t> sb2; 66 test_ostream<wchar_t> os1(&sb1); 67 test_ostream<wchar_t> os2(&sb2); 68 os1.swap(os2); 69 assert(os1.rdbuf() == &sb1); 70 assert(os1.tie() == 0); 71 assert(os1.fill() == ' '); 72 assert(os1.rdstate() == os1.goodbit); 73 assert(os1.exceptions() == os1.goodbit); 74 assert(os1.flags() == (os1.skipws | os1.dec)); 75 assert(os1.precision() == 6); 76 assert(os1.getloc().name() == "C"); 77 assert(os2.rdbuf() == &sb2); 78 assert(os2.tie() == 0); 79 assert(os2.fill() == ' '); 80 assert(os2.rdstate() == os2.goodbit); 81 assert(os2.exceptions() == os2.goodbit); 82 assert(os2.flags() == (os2.skipws | os2.dec)); 83 assert(os2.precision() == 6); 84 assert(os2.getloc().name() == "C"); 85 } 86 87 return 0; 88 } 89