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 10*a7f9895cSLouis Dionne // UNSUPPORTED: no-filesystem 11933518ffSLouis Dionne 12933518ffSLouis Dionne // Filesystem is supported on Apple platforms starting with macosx10.15. 13c360553cSLouis Dionne // UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}} 14998a5c88SEric Fiselier 15998a5c88SEric Fiselier // <fstream> 16998a5c88SEric Fiselier 17998a5c88SEric Fiselier // plate <class charT, class traits = char_traits<charT> > 18998a5c88SEric Fiselier // class basic_fstream 19998a5c88SEric Fiselier 20998a5c88SEric Fiselier // void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in|ios_base::out); 21998a5c88SEric Fiselier 22998a5c88SEric Fiselier #include <fstream> 23998a5c88SEric Fiselier #include <filesystem> 24998a5c88SEric Fiselier #include <cassert> 257fc6a556SMarshall Clow #include "test_macros.h" 26998a5c88SEric Fiselier #include "platform_support.h" 27998a5c88SEric Fiselier main(int,char **)282df59c50SJF Bastienint main(int, char**) { 29998a5c88SEric Fiselier std::filesystem::path p = get_temp_file_name(); 30998a5c88SEric Fiselier { 31998a5c88SEric Fiselier std::fstream stream; 32998a5c88SEric Fiselier assert(!stream.is_open()); 33998a5c88SEric Fiselier stream.open(p, 34998a5c88SEric Fiselier std::ios_base::in | std::ios_base::out | std::ios_base::trunc); 35998a5c88SEric Fiselier assert(stream.is_open()); 36998a5c88SEric Fiselier double x = 0; 37998a5c88SEric Fiselier stream << 3.25; 38998a5c88SEric Fiselier stream.seekg(0); 39998a5c88SEric Fiselier stream >> x; 40998a5c88SEric Fiselier assert(x == 3.25); 41998a5c88SEric Fiselier } 42f1537708SMartin Storsjö std::remove(p.string().c_str()); 43f4c1258dSLouis Dionne 44f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS 45998a5c88SEric Fiselier { 46998a5c88SEric Fiselier std::wfstream stream; 47998a5c88SEric Fiselier assert(!stream.is_open()); 48998a5c88SEric Fiselier stream.open(p, 49998a5c88SEric Fiselier std::ios_base::in | std::ios_base::out | std::ios_base::trunc); 50998a5c88SEric Fiselier assert(stream.is_open()); 51998a5c88SEric Fiselier double x = 0; 52998a5c88SEric Fiselier stream << 3.25; 53998a5c88SEric Fiselier stream.seekg(0); 54998a5c88SEric Fiselier stream >> x; 55998a5c88SEric Fiselier assert(x == 3.25); 56998a5c88SEric Fiselier } 57f1537708SMartin Storsjö std::remove(p.string().c_str()); 58f4c1258dSLouis Dionne #endif 592df59c50SJF Bastien 602df59c50SJF Bastien return 0; 61998a5c88SEric Fiselier } 62