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 // basic_filebuf(basic_filebuf&& rhs);
15 
16 #include <fstream>
17 #include <cassert>
18 #include "test_macros.h"
19 #include "platform_support.h"
20 
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(std::move(f));
33         assert(!f.is_open());
34         assert(f2.is_open());
35         assert(f2.sgetc() == '2');
36     }
37     std::remove(temp.c_str());
38     {
39         std::wfilebuf f;
40         assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in
41                                                | std::ios_base::trunc) != 0);
42         assert(f.is_open());
43         assert(f.sputn(L"123", 3) == 3);
44         f.pubseekoff(1, std::ios_base::beg);
45         assert(f.sgetc() == L'2');
46         std::wfilebuf f2(std::move(f));
47         assert(!f.is_open());
48         assert(f2.is_open());
49         assert(f2.sgetc() == L'2');
50     }
51     std::remove(temp.c_str());
52 
53   return 0;
54 }
55