brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 6b3d6a6 Raw
62 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// <fstream>12 13// basic_filebuf<charT,traits>* open(const filesystem::path& p, ios_base::openmode mode);14 15#include <fstream>16#include <filesystem>17#include <cassert>18#include "test_macros.h"19#include "platform_support.h"20 21namespace fs = std::filesystem;22 23int main(int, char**) {24 25  fs::path p = get_temp_file_name();26  {27    std::filebuf f;28    assert(f.open(p, std::ios_base::out) != 0);29    assert(f.is_open());30    assert(f.sputn("123", 3) == 3);31  }32  {33    std::filebuf f;34    assert(f.open(p, std::ios_base::in) != 0);35    assert(f.is_open());36    assert(f.sbumpc() == '1');37    assert(f.sbumpc() == '2');38    assert(f.sbumpc() == '3');39  }40  std::remove(p.string().c_str());41 42#ifndef TEST_HAS_NO_WIDE_CHARACTERS43  {44    std::wfilebuf f;45    assert(f.open(p, std::ios_base::out) != 0);46    assert(f.is_open());47    assert(f.sputn(L"123", 3) == 3);48  }49  {50    std::wfilebuf f;51    assert(f.open(p, std::ios_base::in) != 0);52    assert(f.is_open());53    assert(f.sbumpc() == L'1');54    assert(f.sbumpc() == L'2');55    assert(f.sbumpc() == L'3');56  }57  std::remove(p.string().c_str());58#endif59 60  return 0;61}62