libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

setbase.pass.cpp (2575B)


      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 // <iomanip>
     11 
     12 // T3 setbase(int base);
     13 
     14 #include <iomanip>
     15 #include <istream>
     16 #include <ostream>
     17 #include <cassert>
     18 
     19 template <class CharT>
     20 struct testbuf
     21     : public std::basic_streambuf<CharT>
     22 {
     23     testbuf() {}
     24 };
     25 
     26 int main()
     27 {
     28     {
     29         testbuf<char> sb;
     30         std::istream is(&sb);
     31         is >> std::setbase(8);
     32         assert((is.flags() & std::ios_base::basefield) == std::ios_base::oct);
     33         is >> std::setbase(10);
     34         assert((is.flags() & std::ios_base::basefield) == std::ios_base::dec);
     35         is >> std::setbase(16);
     36         assert((is.flags() & std::ios_base::basefield) == std::ios_base::hex);
     37         is >> std::setbase(15);
     38         assert((is.flags() & std::ios_base::basefield) == 0);
     39     }
     40     {
     41         testbuf<char> sb;
     42         std::ostream os(&sb);
     43         os << std::setbase(8);
     44         assert((os.flags() & std::ios_base::basefield) == std::ios_base::oct);
     45         os << std::setbase(10);
     46         assert((os.flags() & std::ios_base::basefield) == std::ios_base::dec);
     47         os << std::setbase(16);
     48         assert((os.flags() & std::ios_base::basefield) == std::ios_base::hex);
     49         os << std::setbase(15);
     50         assert((os.flags() & std::ios_base::basefield) == 0);
     51     }
     52     {
     53         testbuf<wchar_t> sb;
     54         std::wistream is(&sb);
     55         is >> std::setbase(8);
     56         assert((is.flags() & std::ios_base::basefield) == std::ios_base::oct);
     57         is >> std::setbase(10);
     58         assert((is.flags() & std::ios_base::basefield) == std::ios_base::dec);
     59         is >> std::setbase(16);
     60         assert((is.flags() & std::ios_base::basefield) == std::ios_base::hex);
     61         is >> std::setbase(15);
     62         assert((is.flags() & std::ios_base::basefield) == 0);
     63     }
     64     {
     65         testbuf<wchar_t> sb;
     66         std::wostream os(&sb);
     67         os << std::setbase(8);
     68         assert((os.flags() & std::ios_base::basefield) == std::ios_base::oct);
     69         os << std::setbase(10);
     70         assert((os.flags() & std::ios_base::basefield) == std::ios_base::dec);
     71         os << std::setbase(16);
     72         assert((os.flags() & std::ios_base::basefield) == std::ios_base::hex);
     73         os << std::setbase(15);
     74         assert((os.flags() & std::ios_base::basefield) == 0);
     75     }
     76 }