unit_test_utility.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include <boost/gil/color_base_algorithm.hpp> // static_for_each
  11. #include <boost/gil/pixel.hpp>
  12. #include <boost/gil/promote_integral.hpp>
  13. #include <boost/core/typeinfo.hpp>
  14. #include <cstdint>
  15. #include <ostream>
  16. namespace boost { namespace gil {
  17. namespace detail {
  18. struct print_color_base
  19. {
  20. std::ostream& os_;
  21. std::size_t element_index_{0};
  22. print_color_base(std::ostream& os) : os_(os) {}
  23. template <typename Element>
  24. void operator()(Element& c)
  25. {
  26. typename ::boost::gil::promote_integral<Element>::type const v(c);
  27. if (element_index_ > 0) os_ << ", ";
  28. os_ << "v" << element_index_ << "=" << v;
  29. ++element_index_;
  30. }
  31. };
  32. } // namespace detail
  33. // Make `point` printable for BOOST_TEST()
  34. template <typename T>
  35. std::ostream& operator<<(std::ostream& os, point<T> const& p)
  36. {
  37. os << "point<" << boost::core::demangled_name(typeid(T)) << ">";
  38. os << "(" << p.x << ", " << p.y << ")" << std::endl;
  39. return os;
  40. }
  41. // Make `pixel` printable for BOOST_TEST()
  42. template <typename ChannelValue, typename Layout>
  43. std::ostream& operator<<(std::ostream& os, pixel<ChannelValue, Layout> const& p)
  44. {
  45. os << "pixel<"
  46. << "Channel=" << boost::core::demangled_name(typeid(ChannelValue))
  47. << ", Layout=" << boost::core::demangled_name(typeid(Layout))
  48. << ">(";
  49. static_for_each(p, detail::print_color_base{os});
  50. os << ")" << std::endl;
  51. return os;
  52. }
  53. }} // namespace boost::gil
  54. #endif