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 "test_macros.h" 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(int, char**) 64 { 65 { 66 test<char> t; 67 test<char> t2; 68 t2.swap(t); 69 } 70 { 71 char g1, g2, g3, p1, p3; 72 test<char> t; 73 t.setg(&g1, &g2, &g3); 74 t.setp(&p1, &p3); 75 test<char> t2; 76 t2.swap(t); 77 } 78 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 79 { 80 test<wchar_t> t; 81 test<wchar_t> t2; 82 t2.swap(t); 83 } 84 { 85 wchar_t g1, g2, g3, p1, p3; 86 test<wchar_t> t; 87 t.setg(&g1, &g2, &g3); 88 t.setp(&p1, &p3); 89 test<wchar_t> t2; 90 t2.swap(t); 91 } 92 #endif 93 std::locale::global(std::locale(LOCALE_en_US_UTF_8)); 94 { 95 test<char> t; 96 test<char> t2; 97 t2.swap(t); 98 } 99 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 100 { 101 test<wchar_t> t; 102 test<wchar_t> t2; 103 t2.swap(t); 104 } 105 #endif 106 107 return 0; 108 } 109