blob: 7a23206b42decac33b284e2f9b2901a3dc4c0eb8 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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
Marshall Clow83e2c4d2013-01-05 03:21:01 +000020#include "platform_support.h" // locale name macros
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000021
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022template <class CharT>
23struct test
24 : public std::basic_streambuf<CharT>
25{
26 typedef std::basic_streambuf<CharT> base;
27 test() {}
28
29 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
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
62int 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 }
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000090 std::locale::global(std::locale(LOCALE_en_US_UTF_8));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000091 {
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}