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