1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // template <class charT, class traits = char_traits<charT> >
13 // class basic_ostream;
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);
22 // Testing to make sure that the max length values are correctly inserted
26 #include <type_traits>
32 void test_octal(const char *expected)
35 ss << std::oct << static_cast<T>(-1);
36 assert(ss.str() == expected);
40 void test_dec(const char *expected)
43 ss << std::dec << static_cast<T>(-1);
44 assert(ss.str() == expected);
48 void test_hex(const char *expected)
51 ss << std::hex << static_cast<T>(-1);
53 std::string str = ss.str();
54 for (size_t i = 0; i < str.size(); ++i )
55 str[i] = static_cast<char>(std::toupper(str[i]));
57 assert(str == expected);
63 test_octal<uint16_t>( "177777");
64 test_octal< int16_t>( "177777");
65 test_octal<uint32_t>( "37777777777");
66 test_octal< int32_t>( "37777777777");
67 test_octal<uint64_t>("1777777777777777777777");
68 test_octal< int64_t>("1777777777777777777777");
69 test_octal<uint64_t>("1777777777777777777777");
71 const bool long_is_64 = std::integral_constant<bool, sizeof(long) == sizeof(int64_t)>::value; // avoid compiler warnings
72 const bool long_long_is_64 = std::integral_constant<bool, sizeof(long long) == sizeof(int64_t)>::value; // avoid compiler warnings
75 test_octal< unsigned long>("1777777777777777777777");
76 test_octal< long>("1777777777777777777777");
78 if (long_long_is_64) {
79 test_octal< unsigned long long>("1777777777777777777777");
80 test_octal< long long>("1777777777777777777777");
83 test_dec<uint16_t>( "65535");
84 test_dec< int16_t>( "-1");
85 test_dec<uint32_t>( "4294967295");
86 test_dec< int32_t>( "-1");
87 test_dec<uint64_t>("18446744073709551615");
88 test_dec< int64_t>( "-1");
90 test_dec<unsigned long>("18446744073709551615");
91 test_dec< long>( "-1");
93 if (long_long_is_64) {
94 test_dec<unsigned long long>("18446744073709551615");
95 test_dec< long long>( "-1");
98 test_hex<uint16_t>( "FFFF");
99 test_hex< int16_t>( "FFFF");
100 test_hex<uint32_t>( "FFFFFFFF");
101 test_hex< int32_t>( "FFFFFFFF");
102 test_hex<uint64_t>("FFFFFFFFFFFFFFFF");
103 test_hex< int64_t>("FFFFFFFFFFFFFFFF");
105 test_hex<unsigned long>("FFFFFFFFFFFFFFFF");
106 test_hex< long>("FFFFFFFFFFFFFFFF");
108 if (long_long_is_64) {
109 test_hex<unsigned long long>("FFFFFFFFFFFFFFFF");
110 test_hex< long long>("FFFFFFFFFFFFFFFF");