xref: /llvm-project/libcxx/test/std/input.output/file.streams/fstreams/fstream.members/open_path.pass.cpp (revision f4c1258d5633fcf06385ff3fd1f4bf57ab971964)
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: libcpp-has-no-filesystem-library
11 
12 // Filesystem is supported on Apple platforms starting with macosx10.15.
13 // UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}}
14 
15 // <fstream>
16 
17 // plate <class charT, class traits = char_traits<charT> >
18 // class basic_fstream
19 
20 // void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in|ios_base::out);
21 
22 #include <fstream>
23 #include <filesystem>
24 #include <cassert>
25 #include "test_macros.h"
26 #include "platform_support.h"
27 
28 int main(int, char**) {
29   std::filesystem::path p = get_temp_file_name();
30   {
31     std::fstream stream;
32     assert(!stream.is_open());
33     stream.open(p,
34                 std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
35     assert(stream.is_open());
36     double x = 0;
37     stream << 3.25;
38     stream.seekg(0);
39     stream >> x;
40     assert(x == 3.25);
41   }
42   std::remove(p.string().c_str());
43 
44 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
45   {
46     std::wfstream stream;
47     assert(!stream.is_open());
48     stream.open(p,
49                 std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
50     assert(stream.is_open());
51     double x = 0;
52     stream << 3.25;
53     stream.seekg(0);
54     stream >> x;
55     assert(x == 3.25);
56   }
57   std::remove(p.string().c_str());
58 #endif
59 
60   return 0;
61 }
62