brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 8e76e11 Raw
60 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// <fstream>10 11// template <class charT, class traits = char_traits<charT> >12// class basic_filebuf13 14// basic_filebuf& operator=(basic_filebuf&& rhs);15 16#include <fstream>17#include <cassert>18#include "test_macros.h"19#include "platform_support.h"20 21int main(int, char**)22{23    std::string temp = get_temp_file_name();24    {25        std::filebuf f;26        assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in27                                               | std::ios_base::trunc) != 0);28        assert(f.is_open());29        assert(f.sputn("123", 3) == 3);30        f.pubseekoff(1, std::ios_base::beg);31        assert(f.sgetc() == '2');32        std::filebuf f2;33        f2 = std::move(f);34        assert(!f.is_open());35        assert(f2.is_open());36        assert(f2.sgetc() == '2');37    }38    std::remove(temp.c_str());39 40#ifndef TEST_HAS_NO_WIDE_CHARACTERS41    {42        std::wfilebuf f;43        assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in44                                               | std::ios_base::trunc) != 0);45        assert(f.is_open());46        assert(f.sputn(L"123", 3) == 3);47        f.pubseekoff(1, std::ios_base::beg);48        assert(f.sgetc() == L'2');49        std::wfilebuf f2;50        f2 = std::move(f);51        assert(!f.is_open());52        assert(f2.is_open());53        assert(f2.sgetc() == L'2');54    }55    std::remove(temp.c_str());56#endif57 58  return 0;59}60