]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/gil/test/core/channel/algorithm_channel_convert.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / gil / test / core / channel / algorithm_channel_convert.cpp
index 92e9654d67cee33f6d2f8b7e8e3668a5335e86b9..e39555b65a394696aeb9488ea9f74bdef082f446 100644 (file)
@@ -1,16 +1,17 @@
 //
 // Copyright 2005-2007 Adobe Systems Incorporated
-// Copyright 2018 Mateusz Loskot <mateusz at loskot dot net>
+// Copyright 2018-2020 Mateusz Loskot <mateusz at loskot dot net>
 //
 // Distributed under the Boost Software License, Version 1.0
 // See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt
 //
 #include <boost/gil/channel_algorithm.hpp>
+
+#include <boost/core/lightweight_test.hpp>
+
 #include <cstdint>
 
-#define BOOST_TEST_MODULE test_algorithm_channel_convert
-#include "unit_test.hpp"
 #include "test_fixture.hpp"
 
 namespace gil = boost::gil;
@@ -28,88 +29,233 @@ struct test_convert_to
         channel_value_t min_v = gil::channel_convert<channel_t>(src_min_v);
         channel_value_t max_v = gil::channel_convert<channel_t>(src_max_v);
         fixture::channel_minmax_value<channel_value_t> expect;
-        BOOST_TEST(min_v == expect.min_v_);
-        BOOST_TEST(max_v == expect.max_v_);
+        BOOST_TEST_EQ(min_v, expect.min_v_);
+        BOOST_TEST_EQ(max_v, expect.max_v_);
     }
 };
 
 //--- Test gil::channel_convert from integral channels to all byte channels -------------
-#define GIL_TEST_CHANNEL_CONVERT_FROM(source_channel_type) \
-    BOOST_FIXTURE_TEST_SUITE( \
-        channel_convert_from_##source_channel_type, \
-        fixture::channel_minmax_value<std::source_channel_type>) \
-    BOOST_AUTO_TEST_CASE_TEMPLATE(channel_value, Channel, fixture::channel_byte_types) \
-    {   test_convert_to<fixture::channel_value<Channel>>::from(min_v_, max_v_); } \
-    BOOST_AUTO_TEST_CASE_TEMPLATE(channel_reference, Channel, fixture::channel_byte_types) \
-    {   test_convert_to<fixture::channel_reference<Channel&>>::from(min_v_, max_v_); } \
-    BOOST_AUTO_TEST_CASE_TEMPLATE(channel_reference_const, Channel, fixture::channel_byte_types) \
-    {   test_convert_to<fixture::channel_reference<Channel const&>>::from(min_v_, max_v_); } \
-    BOOST_AUTO_TEST_CASE(packed_channel_reference) \
-    { \
-        using channels565_t = fixture::packed_channels565<std::uint16_t>; \
-        test_convert_to<typename channels565_t::fixture_0_5_t>::from(min_v_, max_v_); \
-        test_convert_to<typename channels565_t::fixture_5_6_t>::from(min_v_, max_v_); \
-        test_convert_to<typename channels565_t::fixture_11_5_t>::from(min_v_, max_v_); \
-    } \
-    BOOST_AUTO_TEST_CASE(packed_dynamic_channel_reference) \
-    { \
-        using channels565_t = fixture::packed_dynamic_channels565<std::uint16_t>; \
-        test_convert_to<typename channels565_t::fixture_5_t>::from(min_v_, max_v_); \
-        test_convert_to<typename channels565_t::fixture_6_t>::from(min_v_, max_v_); \
-    } \
-    BOOST_AUTO_TEST_SUITE_END()
-
-GIL_TEST_CHANNEL_CONVERT_FROM(uint8_t)
-GIL_TEST_CHANNEL_CONVERT_FROM(int8_t)
-GIL_TEST_CHANNEL_CONVERT_FROM(uint16_t)
-GIL_TEST_CHANNEL_CONVERT_FROM(int16_t)
-GIL_TEST_CHANNEL_CONVERT_FROM(uint32_t)
-GIL_TEST_CHANNEL_CONVERT_FROM(int32_t)
-
-#undef GIL_TEST_CHANNEL_CONVERT_FROM
+template <typename SourceChannel, typename TargetChannel>
+void test_channel_value_convert_from_integral()
+{
+    fixture::channel_minmax_value<SourceChannel> f;
 
-// FIXME: gil::float32_t <-> gil::float64_t seems not supported
+    using channel_t = TargetChannel;
+    // byte channel
+    test_convert_to<fixture::channel_value<channel_t>>::from(f.min_v_, f.max_v_);
+    test_convert_to<fixture::channel_reference<channel_t&>>::from(f.min_v_, f.max_v_);
+    test_convert_to<fixture::channel_reference<channel_t const&>>::from(f.min_v_, f.max_v_);
 
-//--- Test gil::channel_convert from gil::float32_t to all integer channels -------------
-BOOST_FIXTURE_TEST_SUITE(channel_convert_from_float32_t,
-                         fixture::channel_minmax_value<gil::float32_t>)
+    // packed_channel_reference
+    {
+        using channels565_t = fixture::packed_channels565<std::uint16_t>;
+        test_convert_to<typename channels565_t::fixture_0_5_t>::from(f.min_v_, f.max_v_);
+        test_convert_to<typename channels565_t::fixture_5_6_t>::from(f.min_v_, f.max_v_);
+        test_convert_to<typename channels565_t::fixture_11_5_t>::from(f.min_v_, f.max_v_);
+    }
+    // packed_dynamic_channel_reference
+    {
+        using channels565_t = fixture::packed_dynamic_channels565<std::uint16_t>;
+        test_convert_to<typename channels565_t::fixture_5_t>::from(f.min_v_, f.max_v_);
+        test_convert_to<typename channels565_t::fixture_6_t>::from(f.min_v_, f.max_v_);
+    }
+}
 
-BOOST_AUTO_TEST_CASE_TEMPLATE(channel_value, Channel, fixture::channel_integer_types)
+struct test_channel_value_convert_from_uint8_t
 {
-    test_convert_to<fixture::channel_value<Channel>>::from(min_v_, max_v_);
-}
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        test_channel_value_convert_from_integral<std::uint8_t, channel_t>();
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_value_convert_from_uint8_t{});
+    }
+};
 
-BOOST_AUTO_TEST_CASE_TEMPLATE(channel_reference, Channel, fixture::channel_integer_types)
+struct test_channel_value_convert_from_int8_t
 {
-    test_convert_to<fixture::channel_reference<Channel&>>::from(min_v_, max_v_);
-}
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        test_channel_value_convert_from_integral<std::int8_t, channel_t>();
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_value_convert_from_int8_t{});
+    }
+};
 
-BOOST_AUTO_TEST_CASE_TEMPLATE(
-    channel_reference_const, Channel, fixture::channel_integer_types)
+struct test_channel_value_convert_from_uint16_t
 {
-    test_convert_to<fixture::channel_reference<Channel const&>>::from(min_v_, max_v_);
-}
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        test_channel_value_convert_from_integral<std::uint16_t, channel_t>();
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_value_convert_from_uint16_t{});
+    }
+};
+
+struct test_channel_value_convert_from_int16_t
+{
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        test_channel_value_convert_from_integral<std::int16_t, channel_t>();
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_value_convert_from_int16_t{});
+    }
+};
 
-BOOST_AUTO_TEST_SUITE_END()
+struct test_channel_value_convert_from_uint32_t
+{
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        test_channel_value_convert_from_integral<std::uint32_t, channel_t>();
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_value_convert_from_uint32_t{});
+    }
+};
+
+struct test_channel_value_convert_from_int32_t
+{
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        test_channel_value_convert_from_integral<std::int32_t, channel_t>();
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_value_convert_from_int32_t{});
+    }
+};
+
+// FIXME: gil::float32_t <-> gil::float64_t seems not supported
+
+//--- Test gil::channel_convert from gil::float32_t to all integer channels -------------
+struct test_channel_value_convert_from_float32_t
+{
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        fixture::channel_minmax_value<gil::float32_t> f;
+        test_convert_to<fixture::channel_value<channel_t>>::from(f.min_v_, f.max_v_);
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_integer_types>(test_channel_value_convert_from_float32_t{});
+    }
+};
+
+struct test_channel_reference_convert_from_float32_t
+{
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        fixture::channel_minmax_value<gil::float32_t> f;
+        test_convert_to<fixture::channel_reference<channel_t&>>::from(f.min_v_, f.max_v_);
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_integer_types>(test_channel_reference_convert_from_float32_t{});
+    }
+};
+
+struct test_channel_reference_const_from_float32_t
+{
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        fixture::channel_minmax_value<gil::float32_t> f;
+        test_convert_to<fixture::channel_reference<channel_t const &>>::from(f.min_v_, f.max_v_);
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_integer_types>(test_channel_reference_const_from_float32_t{});
+    }
+};
 
 //--- Test gil::channel_convert from gil::float64_t to all integer channels -------------
-BOOST_FIXTURE_TEST_SUITE(channel_convert_from_float64_t,
-                         fixture::channel_minmax_value<gil::float64_t>)
 
-BOOST_AUTO_TEST_CASE_TEMPLATE(channel_value, Channel, fixture::channel_integer_types)
+struct test_channel_value_convert_from_float64_t
 {
-    test_convert_to<fixture::channel_value<Channel>>::from(min_v_, max_v_);
-}
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        fixture::channel_minmax_value<gil::float64_t> f;
+        test_convert_to<fixture::channel_value<channel_t>>::from(f.min_v_, f.max_v_);
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_integer_types>(test_channel_value_convert_from_float64_t{});
+    }
+};
 
-BOOST_AUTO_TEST_CASE_TEMPLATE(channel_reference, Channel, fixture::channel_integer_types)
+struct test_channel_reference_convert_from_float64_t
 {
-    test_convert_to<fixture::channel_reference<Channel&>>::from(min_v_, max_v_);
-}
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        fixture::channel_minmax_value<gil::float64_t> f;
+        test_convert_to<fixture::channel_reference<channel_t &>>::from(f.min_v_, f.max_v_);
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_integer_types>(test_channel_reference_convert_from_float64_t{});
+    }
+};
 
-BOOST_AUTO_TEST_CASE_TEMPLATE(
-    channel_reference_const, Channel, fixture::channel_integer_types)
+struct test_channel_reference_const_convert_from_float64_t
 {
-    test_convert_to<fixture::channel_reference<Channel const&>>::from(min_v_, max_v_);
-}
+    template <typename Channel>
+    void operator()(Channel const &)
+    {
+        using channel_t = Channel;
+        fixture::channel_minmax_value<gil::float64_t> f;
+        test_convert_to<fixture::channel_reference<channel_t const &>>::from(f.min_v_, f.max_v_);
+    }
+    static void run()
+    {
+        boost::mp11::mp_for_each<fixture::channel_integer_types>(test_channel_reference_const_convert_from_float64_t{});
+    }
+};
+
+int main()
+{
+    test_channel_value_convert_from_uint8_t::run();
+    test_channel_value_convert_from_int8_t::run();
+    test_channel_value_convert_from_uint16_t::run();
+    test_channel_value_convert_from_int16_t::run();
+    test_channel_value_convert_from_uint32_t::run();
+    test_channel_value_convert_from_int32_t::run();
 
-BOOST_AUTO_TEST_SUITE_END()
+    test_channel_value_convert_from_float32_t::run();
+    test_channel_reference_convert_from_float32_t::run();
+    test_channel_reference_const_from_float32_t::run();
+
+    test_channel_value_convert_from_float64_t::run();
+    test_channel_reference_convert_from_float64_t::run();
+    test_channel_reference_const_convert_from_float64_t::run();
+
+    return ::boost::report_errors();
+}