// // Copyright 2005-2007 Adobe Systems Incorporated // Copyright 2018 Mateusz Loskot // // 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 #include #include #define BOOST_TEST_MODULE test_algorithm_channel_arithmetic #include "unit_test.hpp" #include "test_fixture.hpp" namespace gil = boost::gil; namespace fixture = boost::gil::test::fixture; template void test_channel_arithmetic_mutable(std::false_type) {} template void test_channel_arithmetic_mutable(std::true_type) { using fixture_t = fixture::channel; using channel_value_t = typename fixture_t::channel_value_t; fixture_t f; channel_value_t const v = f.min_v_; channel_value_t const one = 1; ++f.min_v_; f.min_v_++; --f.min_v_; f.min_v_--; BOOST_TEST(v == f.min_v_); f.min_v_ += one; f.min_v_ -= one; BOOST_TEST(v == f.min_v_); f.min_v_ *= one; f.min_v_ /= one; BOOST_TEST(v == f.min_v_); f.min_v_ = one; // assignable to scalar BOOST_TEST(f.min_v_ == one); f.min_v_ = v; // and to value type BOOST_TEST(f.min_v_ == v); // test swap channel_value_t v1 = f.min_v_; channel_value_t v2 = f.max_v_; std::swap(f.min_v_, f.max_v_); BOOST_TEST(f.min_v_ > f.max_v_); channel_value_t v3 = f.min_v_; channel_value_t v4 = f.max_v_; BOOST_TEST(v1 == v4); BOOST_TEST(v2 == v3); } template void test_channel_arithmetic() { using fixture_t = fixture::channel; fixture_t f; BOOST_TEST(f.min_v_ * 1 == f.min_v_); BOOST_TEST(f.min_v_ / 1 == f.min_v_); BOOST_TEST((f.min_v_ + 1) + 1 == f.min_v_ + 2); BOOST_TEST((f.max_v_ - 1) - 1 == f.max_v_ - 2); using is_mutable_t = std::integral_constant < bool, gil::channel_traits::is_mutable >; test_channel_arithmetic_mutable(is_mutable_t{}); } BOOST_AUTO_TEST_CASE_TEMPLATE(channel_value, Channel, fixture::channel_byte_types) { using fixture_t = fixture::channel_value; test_channel_arithmetic(); } BOOST_AUTO_TEST_CASE_TEMPLATE(channel_reference, Channel, fixture::channel_byte_types) { using fixture_t = fixture::channel_reference; test_channel_arithmetic(); } BOOST_AUTO_TEST_CASE_TEMPLATE( channel_reference_const, Channel, fixture::channel_byte_types) { using fixture_t = fixture::channel_reference; test_channel_arithmetic(); } BOOST_AUTO_TEST_CASE_TEMPLATE( packed_channel_reference, BitField, fixture::channel_bitfield_types) { using channels565_t = fixture::packed_channels565; test_channel_arithmetic(); test_channel_arithmetic(); test_channel_arithmetic(); } BOOST_AUTO_TEST_CASE_TEMPLATE( packed_dynamic_channel_reference, BitField, fixture::channel_bitfield_types) { using channels565_t = fixture::packed_dynamic_channels565; test_channel_arithmetic(); test_channel_arithmetic(); }