blob: 27b8cfd85c9602bf66d46ffc3bdc5f5ca7ffcb5a [file] [log] [blame]
Marshall Clowb9bf4a22015-01-26 17:24:52 +00001//===----------------------------------------------------------------------===//
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 Albert1d4a1ed2016-05-25 22:36:09 -070024#include <iostream>
Marshall Clowb9bf4a22015-01-26 17:24:52 +000025#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);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070033
Marshall Clowb9bf4a22015-01-26 17:24:52 +000034 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);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070042
43// std::cout << ss.str() << " " << expected << std::endl;
Marshall Clowb9bf4a22015-01-26 17:24:52 +000044 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);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070052
Marshall Clowb9bf4a22015-01-26 17:24:52 +000053 std::string str = ss.str();
54 for (size_t i = 0; i < str.size(); ++i )
55 str[i] = std::toupper(str[i]);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070056
Marshall Clowb9bf4a22015-01-26 17:24:52 +000057 assert(str == expected);
58}
59
Dan Albert1d4a1ed2016-05-25 22:36:09 -070060int main(int argc, char* argv[])
Marshall Clowb9bf4a22015-01-26 17:24:52 +000061{
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 Albert1d4a1ed2016-05-25 22:36:09 -070082
83 return 0;
Marshall Clowb9bf4a22015-01-26 17:24:52 +000084}