member_swap.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <istream> 11 12// template <class charT, class traits = char_traits<charT> > 13// class basic_istream; 14 15// void swap(basic_istream& rhs); 16 17#include <istream> 18#include <cassert> 19 20template <class CharT> 21struct testbuf 22 : public std::basic_streambuf<CharT> 23{ 24 testbuf() {} 25}; 26 27template <class CharT> 28struct test_istream 29 : public std::basic_istream<CharT> 30{ 31 typedef std::basic_istream<CharT> base; 32 test_istream(testbuf<CharT>* sb) : base(sb) {} 33 34 void swap(test_istream& s) {base::swap(s);} 35}; 36 37int main() 38{ 39 { 40 testbuf<char> sb1; 41 testbuf<char> sb2; 42 test_istream<char> is1(&sb1); 43 test_istream<char> is2(&sb2); 44 is1.swap(is2); 45 assert(is1.rdbuf() == &sb1); 46 assert(is1.tie() == 0); 47 assert(is1.fill() == ' '); 48 assert(is1.rdstate() == is1.goodbit); 49 assert(is1.exceptions() == is1.goodbit); 50 assert(is1.flags() == (is1.skipws | is1.dec)); 51 assert(is1.precision() == 6); 52 assert(is1.getloc().name() == "C"); 53 assert(is2.rdbuf() == &sb2); 54 assert(is2.tie() == 0); 55 assert(is2.fill() == ' '); 56 assert(is2.rdstate() == is2.goodbit); 57 assert(is2.exceptions() == is2.goodbit); 58 assert(is2.flags() == (is2.skipws | is2.dec)); 59 assert(is2.precision() == 6); 60 assert(is2.getloc().name() == "C"); 61 } 62 { 63 testbuf<wchar_t> sb1; 64 testbuf<wchar_t> sb2; 65 test_istream<wchar_t> is1(&sb1); 66 test_istream<wchar_t> is2(&sb2); 67 is1.swap(is2); 68 assert(is1.rdbuf() == &sb1); 69 assert(is1.tie() == 0); 70 assert(is1.fill() == ' '); 71 assert(is1.rdstate() == is1.goodbit); 72 assert(is1.exceptions() == is1.goodbit); 73 assert(is1.flags() == (is1.skipws | is1.dec)); 74 assert(is1.precision() == 6); 75 assert(is1.getloc().name() == "C"); 76 assert(is2.rdbuf() == &sb2); 77 assert(is2.tie() == 0); 78 assert(is2.fill() == ' '); 79 assert(is2.rdstate() == is2.goodbit); 80 assert(is2.exceptions() == is2.goodbit); 81 assert(is2.flags() == (is2.skipws | is2.dec)); 82 assert(is2.precision() == 6); 83 assert(is2.getloc().name() == "C"); 84 } 85} 86