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 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 54 { 55 testbuf<wchar_t> sb; 56 std::wistream is(&sb); 57 is >> std::setbase(8); 58 assert((is.flags() & std::ios_base::basefield) == std::ios_base::oct); 59 is >> std::setbase(10); 60 assert((is.flags() & std::ios_base::basefield) == std::ios_base::dec); 61 is >> std::setbase(16); 62 assert((is.flags() & std::ios_base::basefield) == std::ios_base::hex); 63 is >> std::setbase(15); 64 assert((is.flags() & std::ios_base::basefield) == 0); 65 } 66 { 67 testbuf<wchar_t> sb; 68 std::wostream os(&sb); 69 os << std::setbase(8); 70 assert((os.flags() & std::ios_base::basefield) == std::ios_base::oct); 71 os << std::setbase(10); 72 assert((os.flags() & std::ios_base::basefield) == std::ios_base::dec); 73 os << std::setbase(16); 74 assert((os.flags() & std::ios_base::basefield) == std::ios_base::hex); 75 os << std::setbase(15); 76 assert((os.flags() & std::ios_base::basefield) == 0); 77 } 78 #endif // TEST_HAS_NO_WIDE_CHARACTERS 79 80 return 0; 81 } 82