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// <ostream> 11 12// template <class charT, class traits = char_traits<charT> > 13// class basic_ostream; 14 15// operator<<( int16_t val); 16// operator<<(uint16_t val); 17// operator<<( int32_t val); 18// operator<<(uint32_t val); 19// operator<<( int64_t val); 20// operator<<(uint64_t val); 21 22// Testing to make sure that the max length values are correctly inserted 23 24#include <iostream> 25#include <sstream> 26#include <cassert> 27 28template <typename T> 29void test_octal(const char *expected) 30{ 31 std::stringstream ss; 32 ss << std::oct << static_cast<T>(-1); 33 34 assert(ss.str() == expected); 35} 36 37template <typename T> 38void test_dec(const char *expected) 39{ 40 std::stringstream ss; 41 ss << std::dec << static_cast<T>(-1); 42 43// std::cout << ss.str() << " " << expected << std::endl; 44 assert(ss.str() == expected); 45} 46 47template <typename T> 48void test_hex(const char *expected) 49{ 50 std::stringstream ss; 51 ss << std::hex << static_cast<T>(-1); 52 53 std::string str = ss.str(); 54 for (size_t i = 0; i < str.size(); ++i ) 55 str[i] = std::toupper(str[i]); 56 57 assert(str == expected); 58} 59 60int main(int argc, char* argv[]) 61{ 62 test_octal<uint16_t>( "177777"); 63 test_octal< int16_t>( "177777"); 64 test_octal<uint32_t>( "37777777777"); 65 test_octal< int32_t>( "37777777777"); 66 test_octal<uint64_t>("1777777777777777777777"); 67 test_octal< int64_t>("1777777777777777777777"); 68 69 test_dec<uint16_t>( "65535"); 70 test_dec< int16_t>( "-1"); 71 test_dec<uint32_t>( "4294967295"); 72 test_dec< int32_t>( "-1"); 73 test_dec<uint64_t>("18446744073709551615"); 74 test_dec< int64_t>( "-1"); 75 76 test_hex<uint16_t>( "FFFF"); 77 test_hex< int16_t>( "FFFF"); 78 test_hex<uint32_t>( "FFFFFFFF"); 79 test_hex< int32_t>( "FFFFFFFF"); 80 test_hex<uint64_t>("FFFFFFFFFFFFFFFF"); 81 test_hex< int64_t>("FFFFFFFFFFFFFFFF"); 82 83 return 0; 84} 85