]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/input.output/iostreams.base/ios/basic.ios.members/set_rdbuf.pass.cpp
Vendor import of libc++ trunk r256633:
[FreeBSD/FreeBSD.git] / test / std / input.output / iostreams.base / ios / basic.ios.members / set_rdbuf.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // XFAIL: libcpp-no-exceptions
11 // <ios>
12
13 // template <class charT, class traits> class basic_ios
14
15 // void set_rdbuf(basic_streambuf<charT, traits>* sb);
16
17 #include <ios>
18 #include <streambuf>
19 #include <cassert>
20
21 struct testbuf
22     : public std::streambuf
23 {
24 };
25
26 struct testios
27     : public std::ios
28 {
29     testios(std::streambuf* p) : std::ios(p) {}
30     void set_rdbuf(std::streambuf* x) {std::ios::set_rdbuf(x);}
31 };
32
33 int main()
34 {
35     testbuf sb1;
36     testbuf sb2;
37     testios ios(&sb1);
38     try
39     {
40         ios.setstate(std::ios::badbit);
41         ios.exceptions(std::ios::badbit);
42     }
43     catch (...)
44     {
45     }
46     ios.set_rdbuf(&sb2);
47     assert(ios.rdbuf() == &sb2);
48     try
49     {
50         ios.setstate(std::ios::badbit);
51         ios.exceptions(std::ios::badbit);
52     }
53     catch (...)
54     {
55     }
56     ios.set_rdbuf(0);
57     assert(ios.rdbuf() == 0);
58 }