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 setstate(iostate state); 15 16#include <ios> 17#include <streambuf> 18#include <cassert> 19 20#include "test_macros.h" 21 22struct testbuf : public std::streambuf {}; 23 24int main() 25{ 26 { 27 std::ios ios(0); 28 ios.setstate(std::ios::goodbit); 29 assert(ios.rdstate() == std::ios::badbit); 30#ifndef TEST_HAS_NO_EXCEPTIONS 31 try 32 { 33 ios.exceptions(std::ios::badbit); 34 assert(false); 35 } 36 catch (...) 37 { 38 } 39 try 40 { 41 ios.setstate(std::ios::goodbit); 42 assert(false); 43 } 44 catch (std::ios::failure&) 45 { 46 assert(ios.rdstate() == std::ios::badbit); 47 } 48 try 49 { 50 ios.setstate(std::ios::eofbit); 51 assert(false); 52 } 53 catch (std::ios::failure&) 54 { 55 assert(ios.rdstate() == (std::ios::eofbit | std::ios::badbit)); 56 } 57#endif 58 } 59 { 60 testbuf sb; 61 std::ios ios(&sb); 62 ios.setstate(std::ios::goodbit); 63 assert(ios.rdstate() == std::ios::goodbit); 64 ios.setstate(std::ios::eofbit); 65 assert(ios.rdstate() == std::ios::eofbit); 66 ios.setstate(std::ios::failbit); 67 assert(ios.rdstate() == (std::ios::eofbit | std::ios::failbit)); 68 } 69} 70