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