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;
testtest29     test() {}
30 
swaptest31     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 
setgtest53     void setg(CharT* gbeg, CharT* gnext, CharT* gend)
54     {
55         base::setg(gbeg, gnext, gend);
56     }
setptest57     void setp(CharT* pbeg, CharT* pend)
58     {
59         base::setp(pbeg, pend);
60     }
61 };
62 
main(int,char **)63 int main(int, char**)
64 {
65     {
66         test<char> t;
67         test<char> t2;
68         t2.swap(t);
69     }
70     {
71         char g[3];
72         char p[3];
73         test<char> t;
74         t.setg(&g[0], &g[1], &g[2]);
75         t.setp(&p[0], &p[2]);
76         test<char> t2;
77         t2.swap(t);
78     }
79 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
80     {
81         test<wchar_t> t;
82         test<wchar_t> t2;
83         t2.swap(t);
84     }
85     {
86         wchar_t g[3];
87         wchar_t p[3];
88         test<wchar_t> t;
89         t.setg(&g[0], &g[1], &g[2]);
90         t.setp(&p[0], &p[2]);
91         test<wchar_t> t2;
92         t2.swap(t);
93     }
94 #endif
95     std::locale::global(std::locale(LOCALE_en_US_UTF_8));
96     {
97         test<char> t;
98         test<char> t2;
99         t2.swap(t);
100     }
101 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
102     {
103         test<wchar_t> t;
104         test<wchar_t> t2;
105         t2.swap(t);
106     }
107 #endif
108 
109   return 0;
110 }
111