Marshall Clow | b9bf4a2 | 2015-01-26 17:24:52 +0000 | [diff] [blame] | 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 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 24 | #include <iostream> |
Marshall Clow | b9bf4a2 | 2015-01-26 17:24:52 +0000 | [diff] [blame] | 25 | #include <sstream> |
| 26 | #include <cassert> |
| 27 | |
| 28 | template <typename T> |
| 29 | void test_octal(const char *expected) |
| 30 | { |
| 31 | std::stringstream ss; |
| 32 | ss << std::oct << static_cast<T>(-1); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 33 | |
Marshall Clow | b9bf4a2 | 2015-01-26 17:24:52 +0000 | [diff] [blame] | 34 | assert(ss.str() == expected); |
| 35 | } |
| 36 | |
| 37 | template <typename T> |
| 38 | void test_dec(const char *expected) |
| 39 | { |
| 40 | std::stringstream ss; |
| 41 | ss << std::dec << static_cast<T>(-1); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 42 | |
| 43 | // std::cout << ss.str() << " " << expected << std::endl; |
Marshall Clow | b9bf4a2 | 2015-01-26 17:24:52 +0000 | [diff] [blame] | 44 | assert(ss.str() == expected); |
| 45 | } |
| 46 | |
| 47 | template <typename T> |
| 48 | void test_hex(const char *expected) |
| 49 | { |
| 50 | std::stringstream ss; |
| 51 | ss << std::hex << static_cast<T>(-1); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 52 | |
Marshall Clow | b9bf4a2 | 2015-01-26 17:24:52 +0000 | [diff] [blame] | 53 | std::string str = ss.str(); |
| 54 | for (size_t i = 0; i < str.size(); ++i ) |
| 55 | str[i] = std::toupper(str[i]); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 56 | |
Marshall Clow | b9bf4a2 | 2015-01-26 17:24:52 +0000 | [diff] [blame] | 57 | assert(str == expected); |
| 58 | } |
| 59 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 60 | int main(int argc, char* argv[]) |
Marshall Clow | b9bf4a2 | 2015-01-26 17:24:52 +0000 | [diff] [blame] | 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"); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 82 | |
| 83 | return 0; |
Marshall Clow | b9bf4a2 | 2015-01-26 17:24:52 +0000 | [diff] [blame] | 84 | } |