1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template <class charT, class traits = char_traits<charT> >
12 // class basic_filebuf
14 // template <class charT, class traits>
16 // swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y);
20 #include "test_macros.h"
21 #include "platform_support.h"
25 std::string temp
= get_temp_file_name();
28 assert(f
.open(temp
.c_str(), std::ios_base::out
| std::ios_base::in
29 | std::ios_base::trunc
) != 0);
31 assert(f
.sputn("123", 3) == 3);
32 f
.pubseekoff(1, std::ios_base::beg
);
33 assert(f
.sgetc() == '2');
38 assert(f2
.sgetc() == '2');
40 std::remove(temp
.c_str());
42 // lhs uses a small buffer, rhs is empty
45 assert(f
.open(temp
.c_str(), std::ios_base::out
| std::ios_base::in
46 | std::ios_base::trunc
) != 0);
48 assert(f
.sputn("123", 3) == 3);
49 f
.pubseekoff(1, std::ios_base::beg
);
50 assert(f
.sgetc() == '2');
55 assert(f2
.sgetc() == '2');
57 std::remove(temp
.c_str());
59 // neither lhs nor rhs use the small buffer
61 std::string tmpA
= get_temp_file_name();
62 std::string tmpB
= get_temp_file_name();
65 // currently the small buffer has size 8
66 std::ofstream
sa(tmpA
), sb(tmpB
);
72 assert(f1
.open(tmpA
, std::ios_base::in
) != 0);
73 assert(f2
.open(tmpB
, std::ios_base::in
) != 0);
74 assert(f1
.sgetc() == '0');
75 assert(f2
.sgetc() == 'a');
79 assert(f1
.sgetc() == 'a');
80 assert(f2
.sgetc() == '0');
82 std::remove(tmpA
.c_str());
83 std::remove(tmpB
.c_str());
86 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
89 assert(f
.open(temp
.c_str(), std::ios_base::out
| std::ios_base::in
90 | std::ios_base::trunc
) != 0);
92 assert(f
.sputn(L
"123", 3) == 3);
93 f
.pubseekoff(1, std::ios_base::beg
);
94 assert(f
.sgetc() == L
'2');
99 assert(f2
.sgetc() == L
'2');
101 std::remove(temp
.c_str());