swap.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <streambuf> 11 12// template <class charT, class traits = char_traits<charT> > 13// class basic_streambuf; 14 15// void swap(basic_streambuf& rhs); 16 17#include <streambuf> 18#include <cassert> 19 20template <class CharT> 21struct test 22 : public std::basic_streambuf<CharT> 23{ 24 typedef std::basic_streambuf<CharT> base; 25 test() {} 26 27 void swap(test& t) 28 { 29 test old_this(*this); 30 test old_that(t); 31 base::swap(t); 32 assert(this->eback() == old_that.eback()); 33 assert(this->gptr() == old_that.gptr()); 34 assert(this->egptr() == old_that.egptr()); 35 assert(this->pbase() == old_that.pbase()); 36 assert(this->pptr() == old_that.pptr()); 37 assert(this->epptr() == old_that.epptr()); 38 assert(this->getloc() == old_that.getloc()); 39 40 assert(t.eback() == old_this.eback()); 41 assert(t.gptr() == old_this.gptr()); 42 assert(t.egptr() == old_this.egptr()); 43 assert(t.pbase() == old_this.pbase()); 44 assert(t.pptr() == old_this.pptr()); 45 assert(t.epptr() == old_this.epptr()); 46 assert(t.getloc() == old_this.getloc()); 47 return *this; 48 } 49 50 void setg(CharT* gbeg, CharT* gnext, CharT* gend) 51 { 52 base::setg(gbeg, gnext, gend); 53 } 54 void setp(CharT* pbeg, CharT* pend) 55 { 56 base::setp(pbeg, pend); 57 } 58}; 59 60int main() 61{ 62 { 63 test<char> t; 64 test<char> t2; 65 swap(t2, t); 66 } 67 { 68 test<wchar_t> t; 69 test<wchar_t> t2; 70 swap(t2, t); 71 } 72 { 73 char g1, g2, g3, p1, p3; 74 test<char> t; 75 t.setg(&g1, &g2, &g3); 76 t.setp(&p1, &p3); 77 test<char> t2; 78 swap(t2, t); 79 } 80 { 81 wchar_t g1, g2, g3, p1, p3; 82 test<wchar_t> t; 83 t.setg(&g1, &g2, &g3); 84 t.setp(&p1, &p3); 85 test<wchar_t> t2; 86 swap(t2, t); 87 } 88 std::locale::global(std::locale("en_US")); 89 { 90 test<char> t; 91 test<char> t2; 92 swap(t2, t); 93 } 94 { 95 test<wchar_t> t; 96 test<wchar_t> t2; 97 swap(t2, t); 98 } 99} 100