2 // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
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
8 #ifndef BOOST_GIL_TEST_UNIT_TEST_UTILITY_HPP
9 #define BOOST_GIL_TEST_UNIT_TEST_UTILITY_HPP
11 #include <boost/gil/color_base_algorithm.hpp> // static_for_each
12 #include <boost/gil/pixel.hpp>
13 #include <boost/gil/promote_integral.hpp>
15 #include <boost/core/typeinfo.hpp>
20 namespace boost { namespace gil {
24 struct print_color_base
27 std::size_t element_index_{0};
28 print_color_base(std::ostream& os) : os_(os) {}
30 template <typename Element>
31 void operator()(Element& c)
33 typename ::boost::gil::promote_integral<Element>::type const v(c);
34 if (element_index_ > 0) os_ << ", ";
35 os_ << "v" << element_index_ << "=" << v;
42 // Make `point` printable for BOOST_TEST()
44 std::ostream& operator<<(std::ostream& os, point<T> const& p)
46 os << "point<" << boost::core::demangled_name(typeid(T)) << ">";
47 os << "(" << p.x << ", " << p.y << ")" << std::endl;
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)
56 << "Channel=" << boost::core::demangled_name(typeid(ChannelValue))
57 << ", Layout=" << boost::core::demangled_name(typeid(Layout))
60 static_for_each(p, detail::print_color_base{os});
61 os << ")" << std::endl;
65 }} // namespace boost::gil