brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 04b1b9f Raw
66 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// <ios>10 11// template <class charT, class traits> class basic_ios12 13// void set_rdbuf(basic_streambuf<charT, traits>* sb);14 15#include <ios>16#include <streambuf>17#include <cassert>18 19#include "test_macros.h"20 21struct testbuf22    : public std::streambuf23{24};25 26struct testios27    : public std::ios28{29    testios(std::streambuf* p) : std::ios(p) {}30    void set_rdbuf(std::streambuf* x) {std::ios::set_rdbuf(x);}31};32 33int main(int, char**)34{35    testbuf sb1;36    testbuf sb2;37    testios ios(&sb1);38#ifndef TEST_HAS_NO_EXCEPTIONS39    try40    {41        ios.setstate(std::ios::badbit);42        ios.exceptions(std::ios::badbit);43        assert(false);44    }45    catch (...)46    {47    }48#endif49    ios.set_rdbuf(&sb2);50    assert(ios.rdbuf() == &sb2);51#ifndef TEST_HAS_NO_EXCEPTIONS52    try53    {54        ios.setstate(std::ios::badbit);55        ios.exceptions(std::ios::badbit);56    }57    catch (...)58    {59    }60#endif61    ios.set_rdbuf(0);62    assert(ios.rdbuf() == 0);63 64  return 0;65}66