nonmember_swap.pass.cpp revision 13aaf422e49fa4b66642966bfc6078b5d9adde12
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// <fstream>
11
12// template <class charT, class traits = char_traits<charT> >
13// class basic_filebuf
14
15// template <class charT, class traits>
16// void
17// swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y);
18
19#include <fstream>
20#include <cassert>
21
22int main()
23{
24    char temp[L_tmpnam];
25    tmpnam(temp);
26    {
27        std::filebuf f;
28        assert(f.open(temp, std::ios_base::out | std::ios_base::in
29                                               | std::ios_base::trunc) != 0);
30        assert(f.is_open());
31        assert(f.sputn("123", 3) == 3);
32        f.pubseekoff(1, std::ios_base::beg);
33        assert(f.sgetc() == '2');
34        std::filebuf f2;
35        swap(f2, f);
36        assert(!f.is_open());
37        assert(f2.is_open());
38        assert(f2.sgetc() == '2');
39    }
40    remove(temp);
41    {
42        std::wfilebuf f;
43        assert(f.open(temp, std::ios_base::out | std::ios_base::in
44                                               | std::ios_base::trunc) != 0);
45        assert(f.is_open());
46        assert(f.sputn(L"123", 3) == 3);
47        f.pubseekoff(1, std::ios_base::beg);
48        assert(f.sgetc() == L'2');
49        std::wfilebuf f2;
50        swap(f2, f);
51        assert(!f.is_open());
52        assert(f2.is_open());
53        assert(f2.sgetc() == L'2');
54    }
55    remove(temp);
56}
57