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