• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <ios>
11 
12 // template <class charT, class traits> class basic_ios
13 
14 // void set_rdbuf(basic_streambuf<charT, traits>* sb);
15 
16 #include <ios>
17 #include <streambuf>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 
22 struct testbuf
23     : public std::streambuf
24 {
25 };
26 
27 struct testios
28     : public std::ios
29 {
testiostestios30     testios(std::streambuf* p) : std::ios(p) {}
set_rdbuftestios31     void set_rdbuf(std::streambuf* x) {std::ios::set_rdbuf(x);}
32 };
33 
main()34 int main()
35 {
36     testbuf sb1;
37     testbuf sb2;
38     testios ios(&sb1);
39 #ifndef TEST_HAS_NO_EXCEPTIONS
40     try
41     {
42         ios.setstate(std::ios::badbit);
43         ios.exceptions(std::ios::badbit);
44         assert(false);
45     }
46     catch (...)
47     {
48     }
49 #endif
50     ios.set_rdbuf(&sb2);
51     assert(ios.rdbuf() == &sb2);
52 #ifndef TEST_HAS_NO_EXCEPTIONS
53     try
54     {
55         ios.setstate(std::ios::badbit);
56         ios.exceptions(std::ios::badbit);
57     }
58     catch (...)
59     {
60     }
61 #endif
62     ios.set_rdbuf(0);
63     assert(ios.rdbuf() == 0);
64 }
65