]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/input.output/iostreams.base/ios/iostate.flags/clear.pass.cpp
Vendor import of libc++ trunk r256633:
[FreeBSD/FreeBSD.git] / test / std / input.output / iostreams.base / ios / iostate.flags / clear.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 clear(iostate state = goodbit);
16
17 #include <ios>
18 #include <streambuf>
19 #include <cassert>
20
21 struct testbuf : public std::streambuf {};
22
23 int main()
24 {
25     {
26         std::ios ios(0);
27         ios.clear();
28         assert(ios.rdstate() == std::ios::badbit);
29         try
30         {
31             ios.exceptions(std::ios::badbit);
32         }
33         catch (...)
34         {
35         }
36         try
37         {
38             ios.clear();
39             assert(false);
40         }
41         catch (std::ios::failure&)
42         {
43             assert(ios.rdstate() == std::ios::badbit);
44         }
45         try
46         {
47             ios.clear(std::ios::eofbit);
48             assert(false);
49         }
50         catch (std::ios::failure&)
51         {
52             assert(ios.rdstate() == (std::ios::eofbit | std::ios::badbit));
53         }
54     }
55     {
56         testbuf sb;
57         std::ios ios(&sb);
58         ios.clear();
59         assert(ios.rdstate() == std::ios::goodbit);
60         ios.exceptions(std::ios::badbit);
61         ios.clear();
62         assert(ios.rdstate() == std::ios::goodbit);
63         ios.clear(std::ios::eofbit);
64         assert(ios.rdstate() == std::ios::eofbit);
65     }
66 }