xref: /llvm-project/libcxx/test/std/input.output/file.streams/fstreams/fstream.members/open_path.pass.cpp (revision c352fa7407122ee62d990d6b82551650149f98d4)
1998a5c88SEric Fiselier //===----------------------------------------------------------------------===//
2998a5c88SEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6998a5c88SEric Fiselier //
7998a5c88SEric Fiselier //===----------------------------------------------------------------------===//
8998a5c88SEric Fiselier 
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
10933518ffSLouis Dionne 
11*f0fc8c48SLouis Dionne // UNSUPPORTED: availability-filesystem-missing
12998a5c88SEric Fiselier 
13998a5c88SEric Fiselier // <fstream>
14998a5c88SEric Fiselier 
15998a5c88SEric Fiselier // plate <class charT, class traits = char_traits<charT> >
16998a5c88SEric Fiselier // class basic_fstream
17998a5c88SEric Fiselier 
18998a5c88SEric Fiselier // void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in|ios_base::out);
19998a5c88SEric Fiselier 
20998a5c88SEric Fiselier #include <fstream>
21998a5c88SEric Fiselier #include <filesystem>
22998a5c88SEric Fiselier #include <cassert>
237fc6a556SMarshall Clow #include "test_macros.h"
24998a5c88SEric Fiselier #include "platform_support.h"
25998a5c88SEric Fiselier 
main(int,char **)262df59c50SJF Bastien int main(int, char**) {
27998a5c88SEric Fiselier   std::filesystem::path p = get_temp_file_name();
28998a5c88SEric Fiselier   {
29998a5c88SEric Fiselier     std::fstream stream;
30998a5c88SEric Fiselier     assert(!stream.is_open());
31998a5c88SEric Fiselier     stream.open(p,
32998a5c88SEric Fiselier                 std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
33998a5c88SEric Fiselier     assert(stream.is_open());
34998a5c88SEric Fiselier     double x = 0;
35998a5c88SEric Fiselier     stream << 3.25;
36998a5c88SEric Fiselier     stream.seekg(0);
37998a5c88SEric Fiselier     stream >> x;
38998a5c88SEric Fiselier     assert(x == 3.25);
39998a5c88SEric Fiselier   }
40f1537708SMartin Storsjö   std::remove(p.string().c_str());
41f4c1258dSLouis Dionne 
42f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
43998a5c88SEric Fiselier   {
44998a5c88SEric Fiselier     std::wfstream stream;
45998a5c88SEric Fiselier     assert(!stream.is_open());
46998a5c88SEric Fiselier     stream.open(p,
47998a5c88SEric Fiselier                 std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
48998a5c88SEric Fiselier     assert(stream.is_open());
49998a5c88SEric Fiselier     double x = 0;
50998a5c88SEric Fiselier     stream << 3.25;
51998a5c88SEric Fiselier     stream.seekg(0);
52998a5c88SEric Fiselier     stream >> x;
53998a5c88SEric Fiselier     assert(x == 3.25);
54998a5c88SEric Fiselier   }
55f1537708SMartin Storsjö   std::remove(p.string().c_str());
56f4c1258dSLouis Dionne #endif
572df59c50SJF Bastien 
582df59c50SJF Bastien   return 0;
59998a5c88SEric Fiselier }
60