• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <fstream>
10 
11 // template <class charT, class traits = char_traits<charT> >
12 // class basic_filebuf
13 
14 // void swap(basic_filebuf& rhs);
15 
16 #include <fstream>
17 #include <cassert>
18 #include "test_macros.h"
19 #include "platform_support.h"
20 
main(int,char **)21 int main(int, char**)
22 {
23     std::string temp = get_temp_file_name();
24     {
25         std::filebuf f;
26         assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in
27                                                | std::ios_base::trunc) != 0);
28         assert(f.is_open());
29         assert(f.sputn("123", 3) == 3);
30         f.pubseekoff(1, std::ios_base::beg);
31         assert(f.sgetc() == '2');
32         std::filebuf f2;
33         f2.swap(f);
34         assert(!f.is_open());
35         assert(f2.is_open());
36         assert(f2.sgetc() == '2');
37     }
38     std::remove(temp.c_str());
39     {
40         std::wfilebuf f;
41         assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in
42                                                | std::ios_base::trunc) != 0);
43         assert(f.is_open());
44         assert(f.sputn(L"123", 3) == 3);
45         f.pubseekoff(1, std::ios_base::beg);
46         assert(f.sgetc() == L'2');
47         std::wfilebuf f2;
48         f2.swap(f);
49         assert(!f.is_open());
50         assert(f2.is_open());
51         assert(f2.sgetc() == L'2');
52     }
53     std::remove(temp.c_str());
54 
55   return 0;
56 }
57