Home | History | Annotate | Download | only in iostate.flags
      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 struct testbuf : public std::streambuf {};
     21 
     22 int main()
     23 {
     24     {
     25         std::ios ios(0);
     26         ios.setstate(std::ios::goodbit);
     27         assert(ios.rdstate() == std::ios::badbit);
     28         try
     29         {
     30             ios.exceptions(std::ios::badbit);
     31         }
     32         catch (...)
     33         {
     34         }
     35         try
     36         {
     37             ios.setstate(std::ios::goodbit);
     38             assert(false);
     39         }
     40         catch (std::ios::failure&)
     41         {
     42             assert(ios.rdstate() == std::ios::badbit);
     43         }
     44         try
     45         {
     46             ios.setstate(std::ios::eofbit);
     47             assert(false);
     48         }
     49         catch (std::ios::failure&)
     50         {
     51             assert(ios.rdstate() == (std::ios::eofbit | std::ios::badbit));
     52         }
     53     }
     54     {
     55         testbuf sb;
     56         std::ios ios(&sb);
     57         ios.setstate(std::ios::goodbit);
     58         assert(ios.rdstate() == std::ios::goodbit);
     59         ios.setstate(std::ios::eofbit);
     60         assert(ios.rdstate() == std::ios::eofbit);
     61         ios.setstate(std::ios::failbit);
     62         assert(ios.rdstate() == (std::ios::eofbit | std::ios::failbit));
     63     }
     64 }
     65