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 
main(int,char **)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 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
38     {
39         std::wfilebuf f;
40         assert(f.open(temp.c_str(), std::ios_base::out) != 0);
41         assert(f.is_open());
42         assert(f.sputn(L"123", 3) == 3);
43     }
44     {
45         std::wfilebuf f;
46         assert(f.open(temp.c_str(), std::ios_base::in) != 0);
47         assert(f.is_open());
48         assert(f.sbumpc() == L'1');
49         assert(f.sbumpc() == L'2');
50         assert(f.sbumpc() == L'3');
51     }
52     std::remove(temp.c_str());
53 #endif
54 
55   return 0;
56 }
57