1 //
2 // Copyright 2020 Mateusz Loskot <mateusz at loskot dot net>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #include <boost/core/lightweight_test.hpp>
9
10 #include "test_utility_output_stream.hpp"
11
12 #include <cstdint>
13 #include <sstream>
14 #include <type_traits>
15
16 namespace utility = boost::gil::test::utility;
17
main()18 int main()
19 {
20 static_assert(
21 std::is_same<utility::printable_numeric_t<std::uint8_t>, int>::value,
22 "std::uint8_t not printable as int");
23 static_assert(
24 !std::is_same<utility::printable_numeric_t<std::uint64_t>, int>::value,
25 "std::uint64_t printable as int");
26 static_assert(
27 std::is_same<utility::printable_numeric_t<float>, double>::value,
28 "float not printable as double");
29
30 {
31 std::ostringstream oss;
32 utility::print_color_base p{oss};
33 p(std::int8_t{-128});
34 BOOST_TEST_EQ(oss.str(), "v0=-128");
35 }
36 {
37 std::ostringstream oss;
38 utility::print_color_base p{oss};
39 p(std::uint8_t{128});
40 BOOST_TEST_EQ(oss.str(), "v0=128");
41 }
42 {
43 std::ostringstream oss;
44 utility::print_color_base p{oss};
45 p(std::int16_t{-32768});
46 BOOST_TEST_EQ(oss.str(), "v0=-32768");
47 }
48 {
49 std::ostringstream oss;
50 utility::print_color_base p{oss};
51 p(std::uint16_t{32768});
52 BOOST_TEST_EQ(oss.str(), "v0=32768");
53 }
54 {
55 std::ostringstream oss;
56 utility::print_color_base p{oss};
57 p(float{1.2345f});
58 BOOST_TEST_EQ(oss.str(), "v0=1.2345");
59 }
60 {
61 std::ostringstream oss;
62 utility::print_color_base p{oss};
63 p(double{1.2345});
64 BOOST_TEST_EQ(oss.str(), "v0=1.2345");
65 }
66
67 return ::boost::report_errors();
68 }
69