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 // <istream> 10 11 // template <class charT, class traits = char_traits<charT> > 12 // class basic_istream; 13 14 // void swap(basic_istream& rhs); 15 16 #include <istream> 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_istream 30 : public std::basic_istream<CharT> 31 { 32 typedef std::basic_istream<CharT> base; test_istreamtest_istream33 test_istream(testbuf<CharT>* sb) : base(sb) {} 34 swaptest_istream35 void swap(test_istream& 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_istream<char> is1(&sb1); 44 test_istream<char> is2(&sb2); 45 is1.swap(is2); 46 assert(is1.rdbuf() == &sb1); 47 assert(is1.tie() == 0); 48 assert(is1.fill() == ' '); 49 assert(is1.rdstate() == is1.goodbit); 50 assert(is1.exceptions() == is1.goodbit); 51 assert(is1.flags() == (is1.skipws | is1.dec)); 52 assert(is1.precision() == 6); 53 assert(is1.getloc().name() == "C"); 54 assert(is2.rdbuf() == &sb2); 55 assert(is2.tie() == 0); 56 assert(is2.fill() == ' '); 57 assert(is2.rdstate() == is2.goodbit); 58 assert(is2.exceptions() == is2.goodbit); 59 assert(is2.flags() == (is2.skipws | is2.dec)); 60 assert(is2.precision() == 6); 61 assert(is2.getloc().name() == "C"); 62 } 63 { 64 testbuf<wchar_t> sb1; 65 testbuf<wchar_t> sb2; 66 test_istream<wchar_t> is1(&sb1); 67 test_istream<wchar_t> is2(&sb2); 68 is1.swap(is2); 69 assert(is1.rdbuf() == &sb1); 70 assert(is1.tie() == 0); 71 assert(is1.fill() == ' '); 72 assert(is1.rdstate() == is1.goodbit); 73 assert(is1.exceptions() == is1.goodbit); 74 assert(is1.flags() == (is1.skipws | is1.dec)); 75 assert(is1.precision() == 6); 76 assert(is1.getloc().name() == "C"); 77 assert(is2.rdbuf() == &sb2); 78 assert(is2.tie() == 0); 79 assert(is2.fill() == ' '); 80 assert(is2.rdstate() == is2.goodbit); 81 assert(is2.exceptions() == is2.goodbit); 82 assert(is2.flags() == (is2.skipws | is2.dec)); 83 assert(is2.precision() == 6); 84 assert(is2.getloc().name() == "C"); 85 } 86 87 return 0; 88 } 89