]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/input.output/iostreams.base/ios/iostate.flags/exceptions_iostate.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / input.output / iostreams.base / ios / iostate.flags / exceptions_iostate.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 // <ios>
11
12 // template <class charT, class traits> class basic_ios
13
14 // iostate exceptions() const;
15
16 #include <ios>
17 #include <streambuf>
18 #include <cassert>
19
20 #include "test_macros.h"
21
22 struct testbuf : public std::streambuf {};
23
24 int main()
25 {
26     {
27         std::ios ios(0);
28         assert(ios.exceptions() == std::ios::goodbit);
29         ios.exceptions(std::ios::eofbit);
30         assert(ios.exceptions() == std::ios::eofbit);
31 #ifndef TEST_HAS_NO_EXCEPTIONS
32         try
33         {
34             ios.exceptions(std::ios::badbit);
35             assert(false);
36         }
37         catch (std::ios::failure&)
38         {
39         }
40         assert(ios.exceptions() == std::ios::badbit);
41 #endif
42     }
43     {
44         testbuf sb;
45         std::ios ios(&sb);
46         assert(ios.exceptions() == std::ios::goodbit);
47         ios.exceptions(std::ios::eofbit);
48         assert(ios.exceptions() == std::ios::eofbit);
49         ios.exceptions(std::ios::badbit);
50         assert(ios.exceptions() == std::ios::badbit);
51     }
52 }