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