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_ofstream 17998a5c88SEric Fiselier 18998a5c88SEric Fiselier // void open(const filesystem::path& s, ios_base::openmode mode = 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 26998a5c88SEric Fiselier namespace fs = std::filesystem; 27998a5c88SEric Fiselier main(int,char **)282df59c50SJF Bastienint main(int, char**) { 29998a5c88SEric Fiselier fs::path p = get_temp_file_name(); 30998a5c88SEric Fiselier { 31998a5c88SEric Fiselier std::ofstream fs; 32998a5c88SEric Fiselier assert(!fs.is_open()); 33998a5c88SEric Fiselier char c = 'a'; 34998a5c88SEric Fiselier fs << c; 35998a5c88SEric Fiselier assert(fs.fail()); 36998a5c88SEric Fiselier fs.open(p); 37998a5c88SEric Fiselier assert(fs.is_open()); 38998a5c88SEric Fiselier fs << c; 39998a5c88SEric Fiselier } 40998a5c88SEric Fiselier { 41998a5c88SEric Fiselier std::ifstream fs(p.c_str()); 42998a5c88SEric Fiselier char c = 0; 43998a5c88SEric Fiselier fs >> c; 44998a5c88SEric Fiselier assert(c == 'a'); 45998a5c88SEric Fiselier } 46f1537708SMartin Storsjö std::remove(p.string().c_str()); 47f4c1258dSLouis Dionne 48f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS 49998a5c88SEric Fiselier { 50998a5c88SEric Fiselier std::wofstream fs; 51998a5c88SEric Fiselier assert(!fs.is_open()); 52998a5c88SEric Fiselier wchar_t c = L'a'; 53998a5c88SEric Fiselier fs << c; 54998a5c88SEric Fiselier assert(fs.fail()); 55998a5c88SEric Fiselier fs.open(p); 56998a5c88SEric Fiselier assert(fs.is_open()); 57998a5c88SEric Fiselier fs << c; 58998a5c88SEric Fiselier } 59998a5c88SEric Fiselier { 60998a5c88SEric Fiselier std::wifstream fs(p.c_str()); 61998a5c88SEric Fiselier wchar_t c = 0; 62998a5c88SEric Fiselier fs >> c; 63998a5c88SEric Fiselier assert(c == L'a'); 64998a5c88SEric Fiselier } 65f1537708SMartin Storsjö std::remove(p.string().c_str()); 66f4c1258dSLouis Dionne #endif 672df59c50SJF Bastien 682df59c50SJF Bastien return 0; 69998a5c88SEric Fiselier } 70