open_path.pass.cpp (1396B)
1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03, c++11, c++14 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 "platform_support.h" 20 21 namespace fs = std::filesystem; 22 23 int main() { 24 25 fs::path p = get_temp_file_name(); 26 { 27 std::filebuf f; 28 assert(f.open(p, std::ios_base::out) != 0); 29 assert(f.is_open()); 30 assert(f.sputn("123", 3) == 3); 31 } 32 { 33 std::filebuf f; 34 assert(f.open(p, std::ios_base::in) != 0); 35 assert(f.is_open()); 36 assert(f.sbumpc() == '1'); 37 assert(f.sbumpc() == '2'); 38 assert(f.sbumpc() == '3'); 39 } 40 std::remove(p.c_str()); 41 { 42 std::wfilebuf f; 43 assert(f.open(p, std::ios_base::out) != 0); 44 assert(f.is_open()); 45 assert(f.sputn(L"123", 3) == 3); 46 } 47 { 48 std::wfilebuf f; 49 assert(f.open(p, std::ios_base::in) != 0); 50 assert(f.is_open()); 51 assert(f.sbumpc() == L'1'); 52 assert(f.sbumpc() == L'2'); 53 assert(f.sbumpc() == L'3'); 54 } 55 remove(p.c_str()); 56 }