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 // UNSUPPORTED: c++03, c++11, c++14
10 // UNSUPPORTED: no-filesystem
11
12 // Filesystem is supported on Apple platforms starting with macosx10.15.
13 // UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}}
14
15 // <fstream>
16
17 // basic_filebuf<charT,traits>* open(const filesystem::path& p, ios_base::openmode mode);
18
19 #include <fstream>
20 #include <filesystem>
21 #include <cassert>
22 #include "test_macros.h"
23 #include "platform_support.h"
24
25 namespace fs = std::filesystem;
26
main(int,char **)27 int main(int, char**) {
28
29 fs::path p = get_temp_file_name();
30 {
31 std::filebuf f;
32 assert(f.open(p, std::ios_base::out) != 0);
33 assert(f.is_open());
34 assert(f.sputn("123", 3) == 3);
35 }
36 {
37 std::filebuf f;
38 assert(f.open(p, std::ios_base::in) != 0);
39 assert(f.is_open());
40 assert(f.sbumpc() == '1');
41 assert(f.sbumpc() == '2');
42 assert(f.sbumpc() == '3');
43 }
44 std::remove(p.string().c_str());
45
46 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
47 {
48 std::wfilebuf f;
49 assert(f.open(p, std::ios_base::out) != 0);
50 assert(f.is_open());
51 assert(f.sputn(L"123", 3) == 3);
52 }
53 {
54 std::wfilebuf f;
55 assert(f.open(p, std::ios_base::in) != 0);
56 assert(f.is_open());
57 assert(f.sbumpc() == L'1');
58 assert(f.sbumpc() == L'2');
59 assert(f.sbumpc() == L'3');
60 }
61 std::remove(p.string().c_str());
62 #endif
63
64 return 0;
65 }
66