[flang][OpenMP] Parse METADIRECTIVE in specification part (#123397)
[llvm-project.git] / libcxx / test / std / input.output / file.streams / fstreams / filebuf.assign / nonmember_swap.pass.cpp
blob003b0302c8acd69279cc8e3ff76c3a4c399d1b6f
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 //===----------------------------------------------------------------------===//
9 // <fstream>
11 // template <class charT, class traits = char_traits<charT> >
12 // class basic_filebuf
14 // template <class charT, class traits>
15 // void
16 // swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y);
18 #include <fstream>
19 #include <cassert>
20 #include "test_macros.h"
21 #include "platform_support.h"
23 int main(int, char**)
25 std::string temp = get_temp_file_name();
27 std::filebuf f;
28 assert(f.open(temp.c_str(), 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');
40 std::remove(temp.c_str());
42 // lhs uses a small buffer, rhs is empty
44 std::filebuf f;
45 assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in
46 | std::ios_base::trunc) != 0);
47 assert(f.is_open());
48 assert(f.sputn("123", 3) == 3);
49 f.pubseekoff(1, std::ios_base::beg);
50 assert(f.sgetc() == '2');
51 std::filebuf f2;
52 swap(f, f2);
53 assert(!f.is_open());
54 assert(f2.is_open());
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);
67 sa << "0123456789";
68 sb << "abcdefghij";
71 std::filebuf f1, f2;
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');
77 swap(f1, f2);
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
88 std::wfilebuf f;
89 assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in
90 | std::ios_base::trunc) != 0);
91 assert(f.is_open());
92 assert(f.sputn(L"123", 3) == 3);
93 f.pubseekoff(1, std::ios_base::beg);
94 assert(f.sgetc() == L'2');
95 std::wfilebuf f2;
96 swap(f2, f);
97 assert(!f.is_open());
98 assert(f2.is_open());
99 assert(f2.sgetc() == L'2');
101 std::remove(temp.c_str());
102 #endif
104 return 0;