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