1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <iomanip> 10 11 // T3 setbase(int base); 12 13 #include <iomanip> 14 #include <istream> 15 #include <ostream> 16 #include <cassert> 17 18 #include "test_macros.h" 19 20 template <class CharT> 21 struct testbuf 22 : public std::basic_streambuf<CharT> 23 { testbuftestbuf24 testbuf() {} 25 }; 26 main(int,char **)27int main(int, char**) 28 { 29 { 30 testbuf<char> sb; 31 std::istream is(&sb); 32 is >> std::setbase(8); 33 assert((is.flags() & std::ios_base::basefield) == std::ios_base::oct); 34 is >> std::setbase(10); 35 assert((is.flags() & std::ios_base::basefield) == std::ios_base::dec); 36 is >> std::setbase(16); 37 assert((is.flags() & std::ios_base::basefield) == std::ios_base::hex); 38 is >> std::setbase(15); 39 assert((is.flags() & std::ios_base::basefield) == 0); 40 } 41 { 42 testbuf<char> sb; 43 std::ostream os(&sb); 44 os << std::setbase(8); 45 assert((os.flags() & std::ios_base::basefield) == std::ios_base::oct); 46 os << std::setbase(10); 47 assert((os.flags() & std::ios_base::basefield) == std::ios_base::dec); 48 os << std::setbase(16); 49 assert((os.flags() & std::ios_base::basefield) == std::ios_base::hex); 50 os << std::setbase(15); 51 assert((os.flags() & std::ios_base::basefield) == 0); 52 } 53 { 54 testbuf<wchar_t> sb; 55 std::wistream is(&sb); 56 is >> std::setbase(8); 57 assert((is.flags() & std::ios_base::basefield) == std::ios_base::oct); 58 is >> std::setbase(10); 59 assert((is.flags() & std::ios_base::basefield) == std::ios_base::dec); 60 is >> std::setbase(16); 61 assert((is.flags() & std::ios_base::basefield) == std::ios_base::hex); 62 is >> std::setbase(15); 63 assert((is.flags() & std::ios_base::basefield) == 0); 64 } 65 { 66 testbuf<wchar_t> sb; 67 std::wostream os(&sb); 68 os << std::setbase(8); 69 assert((os.flags() & std::ios_base::basefield) == std::ios_base::oct); 70 os << std::setbase(10); 71 assert((os.flags() & std::ios_base::basefield) == std::ios_base::dec); 72 os << std::setbase(16); 73 assert((os.flags() & std::ios_base::basefield) == std::ios_base::hex); 74 os << std::setbase(15); 75 assert((os.flags() & std::ios_base::basefield) == 0); 76 } 77 78 return 0; 79 } 80