Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / gil / test / unit_test_utility.hpp
1 //
2 // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
3 //
4 // Distribtted 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 #ifndef BOOST_GIL_TEST_UNIT_TEST_UTILITY_HPP
9 #define BOOST_GIL_TEST_UNIT_TEST_UTILITY_HPP
10
11 #include <boost/gil/color_base_algorithm.hpp> // static_for_each
12 #include <boost/gil/pixel.hpp>
13 #include <boost/gil/promote_integral.hpp>
14
15 #include <boost/core/typeinfo.hpp>
16
17 #include <cstdint>
18 #include <ostream>
19
20 namespace boost { namespace gil {
21
22 namespace detail {
23
24 struct print_color_base
25 {
26     std::ostream& os_;
27     std::size_t element_index_{0};
28     print_color_base(std::ostream& os) : os_(os) {}
29
30     template <typename Element>
31     void operator()(Element& c)
32     {
33         typename ::boost::gil::promote_integral<Element>::type const v(c);
34         if (element_index_ > 0) os_ << ", ";
35         os_ << "v" << element_index_ << "=" << v;
36         ++element_index_;
37     }
38 };
39
40 } // namespace detail
41
42 // Make `point` printable for BOOST_TEST()
43 template <typename T>
44 std::ostream& operator<<(std::ostream& os, point<T> const& p)
45 {
46     os << "point<" << boost::core::demangled_name(typeid(T)) << ">";
47     os << "(" << p.x << ", " << p.y << ")" << std::endl;
48     return os;
49 }
50
51 // Make `pixel` printable for BOOST_TEST()
52 template <typename ChannelValue, typename Layout>
53 std::ostream& operator<<(std::ostream& os, pixel<ChannelValue, Layout> const& p)
54 {
55     os << "pixel<"
56        << "Channel=" << boost::core::demangled_name(typeid(ChannelValue))
57        << ", Layout=" << boost::core::demangled_name(typeid(Layout))
58        << ">(";
59
60     static_for_each(p, detail::print_color_base{os});
61     os << ")" << std::endl;
62     return os;
63 }
64
65 }} // namespace boost::gil
66
67 #endif