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
20 #include "platform_support.h" // locale name macros
21
22 template <class CharT>
23 struct test
24 : public std::basic_streambuf<CharT>
25 {
26 typedef std::basic_streambuf<CharT> base;
testtest27 test() {}
28
swaptest29 void swap(test& t)
30 {
31 test old_this(*this);
32 test old_that(t);
33 base::swap(t);
34 assert(this->eback() == old_that.eback());
35 assert(this->gptr() == old_that.gptr());
36 assert(this->egptr() == old_that.egptr());
37 assert(this->pbase() == old_that.pbase());
38 assert(this->pptr() == old_that.pptr());
39 assert(this->epptr() == old_that.epptr());
40 assert(this->getloc() == old_that.getloc());
41
42 assert(t.eback() == old_this.eback());
43 assert(t.gptr() == old_this.gptr());
44 assert(t.egptr() == old_this.egptr());
45 assert(t.pbase() == old_this.pbase());
46 assert(t.pptr() == old_this.pptr());
47 assert(t.epptr() == old_this.epptr());
48 assert(t.getloc() == old_this.getloc());
49 return *this;
50 }
51
setgtest52 void setg(CharT* gbeg, CharT* gnext, CharT* gend)
53 {
54 base::setg(gbeg, gnext, gend);
55 }
setptest56 void setp(CharT* pbeg, CharT* pend)
57 {
58 base::setp(pbeg, pend);
59 }
60 };
61
main()62 int main()
63 {
64 {
65 test<char> t;
66 test<char> t2;
67 swap(t2, t);
68 }
69 {
70 test<wchar_t> t;
71 test<wchar_t> t2;
72 swap(t2, 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 swap(t2, 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 swap(t2, t);
89 }
90 std::locale::global(std::locale(LOCALE_en_US_UTF_8));
91 {
92 test<char> t;
93 test<char> t2;
94 swap(t2, t);
95 }
96 {
97 test<wchar_t> t;
98 test<wchar_t> t2;
99 swap(t2, t);
100 }
101 }
102