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