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 // REQUIRES: locale.en_US.UTF-8 11 12 // <streambuf> 13 14 // template <class charT, class traits = char_traits<charT> > 15 // class basic_streambuf; 16 17 // void swap(basic_streambuf& rhs); 18 19 #include <streambuf> 20 #include <cassert> 21 22 #include "platform_support.h" // locale name macros 23 24 template <class CharT> 25 struct test 26 : public std::basic_streambuf<CharT> 27 { 28 typedef std::basic_streambuf<CharT> base; 29 test() {} 30 31 void swap(test& t) 32 { 33 test old_this(*this); 34 test old_that(t); 35 base::swap(t); 36 assert(this->eback() == old_that.eback()); 37 assert(this->gptr() == old_that.gptr()); 38 assert(this->egptr() == old_that.egptr()); 39 assert(this->pbase() == old_that.pbase()); 40 assert(this->pptr() == old_that.pptr()); 41 assert(this->epptr() == old_that.epptr()); 42 assert(this->getloc() == old_that.getloc()); 43 44 assert(t.eback() == old_this.eback()); 45 assert(t.gptr() == old_this.gptr()); 46 assert(t.egptr() == old_this.egptr()); 47 assert(t.pbase() == old_this.pbase()); 48 assert(t.pptr() == old_this.pptr()); 49 assert(t.epptr() == old_this.epptr()); 50 assert(t.getloc() == old_this.getloc()); 51 } 52 53 void setg(CharT* gbeg, CharT* gnext, CharT* gend) 54 { 55 base::setg(gbeg, gnext, gend); 56 } 57 void setp(CharT* pbeg, CharT* pend) 58 { 59 base::setp(pbeg, pend); 60 } 61 }; 62 63 int main() 64 { 65 { 66 test<char> t; 67 test<char> t2; 68 t2.swap(t); 69 } 70 { 71 test<wchar_t> t; 72 test<wchar_t> t2; 73 t2.swap(t); 74 } 75 { 76 char g1, g2, g3, p1, p3; 77 test<char> t; 78 t.setg(&g1, &g2, &g3); 79 t.setp(&p1, &p3); 80 test<char> t2; 81 t2.swap(t); 82 } 83 { 84 wchar_t g1, g2, g3, p1, p3; 85 test<wchar_t> t; 86 t.setg(&g1, &g2, &g3); 87 t.setp(&p1, &p3); 88 test<wchar_t> t2; 89 t2.swap(t); 90 } 91 std::locale::global(std::locale(LOCALE_en_US_UTF_8)); 92 { 93 test<char> t; 94 test<char> t2; 95 t2.swap(t); 96 } 97 { 98 test<wchar_t> t; 99 test<wchar_t> t2; 100 t2.swap(t); 101 } 102 } 103