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// REQUIRES: locale.en_US.UTF-8
11
12// <streambuf>
13
14// template <class charT, class traits = char_traits<charT> >
15// class basic_streambuf;
16
17// void swap(basic_streambuf& rhs);
18
19#include <streambuf>
20#include <cassert>
21
22#include "platform_support.h" // locale name macros
23
24template <class CharT>
25struct 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        return *this;
52    }
53
54    void setg(CharT* gbeg, CharT* gnext, CharT* gend)
55    {
56        base::setg(gbeg, gnext, gend);
57    }
58    void setp(CharT* pbeg, CharT* pend)
59    {
60        base::setp(pbeg, pend);
61    }
62};
63
64int main()
65{
66    {
67        test<char> t;
68        test<char> t2;
69        swap(t2, t);
70    }
71    {
72        test<wchar_t> t;
73        test<wchar_t> t2;
74        swap(t2, t);
75    }
76    {
77        char g1, g2, g3, p1, p3;
78        test<char> t;
79        t.setg(&g1, &g2, &g3);
80        t.setp(&p1, &p3);
81        test<char> t2;
82        swap(t2, 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        swap(t2, t);
91    }
92    std::locale::global(std::locale(LOCALE_en_US_UTF_8));
93    {
94        test<char> t;
95        test<char> t2;
96        swap(t2, t);
97    }
98    {
99        test<wchar_t> t;
100        test<wchar_t> t2;
101        swap(t2, t);
102    }
103}
104