mirror of
https://github.com/boostorg/gil.git
synced 2026-02-19 14:32:10 +00:00
Refactor single-program channel test to Boost.Test suites and cases
Motivation: - state clearly what is covered with tests without reading non-trivial code - avoid cleverness - tests should be no-brainer - get closer to one test case targets one feature/beaviour with one check - replace obscure `throw std::exception` with diagnostics that are actually useful to pin-point failure cause and location - makes CI logs useful. - allow to select and run specific tests - make tests maintenance easy, quick and fun Propose new structure of tests that reflects the previous tests hierarchy, but organizes channel tests in test/channel directory with test programs each covering specific library feature (or set of closely related features). The refactored tests cover 100% of checks from the old `channel.cpp`, plus it refines or adds a bunch more. NOTE: old test/channel.cpp has not been removed yet. Common definitions from the single test/channel.cpp moved to channel_test_fixtures.hpp and namespace boost::gil::test::fixture: Classes and typedefs: - `do_test` as `fixture::channel` - `value_core` as `fixture::channel_value` - `reference_core` as `fixture::channel_reference` - `packed_reference_core` as `fixture::packed_channel_reference` - `packed_dynamic_reference_core` as `fixture::packed_dynamic_channel_reference` - `channel_archetype` and relatives to `channel_concepts.cpp` which is compile test in Jamfile - `test_packed_channel_reference()` parts as `fixture::packed_channels565` - `test_packed_dynamic_channel_reference()` parts as `fixture::packed_dynamic_channels565` Test case functions called from `do_test<T>::test_all`: - `test_channel_invert()` to `algorithm_channel_invert.cpp` suite - `test_channel_convert()` to `algorithm_channel_convert.cpp` suite - `test_channel_multiply()` to `algorithm_channel_multiply.cpp` suite - `test_channel_math()` split to `algorithm_channel_relation.cpp` and `algorithm_channel_arithmetic.cpp` Add test cases for each channel value type T as used to run from `test_channel_value_impl<T>`, `test_packed_channel_reference<T>` and `test_packed_dynamic_channel_reference<T>`. Add list of possible T-s defined as type-lists `fixture::channel_byte_types`, `fixture::channel_integer_types`, `channel_float_types` and `channel_bitfield_types` which used with `BOOST_AUTO_TEST_CASE_TEMPLATE` generate all possible combination of inputs. Add new `channel_test_fixture.cpp` is a self-test suite verifying the fixtures.
This commit is contained in:
committed by
Stefan Seefeld
parent
b80667f0c6
commit
73ec99e606
115
test/channel/algorithm_channel_convert.cpp
Normal file
115
test/channel/algorithm_channel_convert.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// Copyright 2005-2007 Adobe Systems Incorporated
|
||||
// Copyright 2018 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 <cstdint>
|
||||
|
||||
#define BOOST_TEST_MODULE test_algorithm_channel_convert
|
||||
#include <gil_test_common.hpp>
|
||||
#include "channel_test_fixture.hpp"
|
||||
|
||||
namespace gil = boost::gil;
|
||||
namespace fixture = boost::gil::test::fixture;
|
||||
|
||||
template <typename ChannelFixtureBase>
|
||||
struct test_convert_to
|
||||
{
|
||||
using channel_t = typename fixture::channel<ChannelFixtureBase>::channel_t;
|
||||
using channel_value_t = typename fixture::channel<ChannelFixtureBase>::channel_value_t;
|
||||
|
||||
template <typename Channel>
|
||||
static void from(Channel src_min_v, Channel src_max_v)
|
||||
{
|
||||
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_);
|
||||
}
|
||||
};
|
||||
|
||||
//--- 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
|
||||
|
||||
// FIXME: gil::float32_t <-> gil::float64_t seems not supported
|
||||
|
||||
//--- 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>)
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(channel_value, Channel, fixture::channel_integer_types)
|
||||
{
|
||||
test_convert_to<fixture::channel_value<Channel>>::from(min_v_, max_v_);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(channel_reference, Channel, fixture::channel_integer_types)
|
||||
{
|
||||
test_convert_to<fixture::channel_reference<Channel&>>::from(min_v_, max_v_);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(
|
||||
channel_reference_const, Channel, fixture::channel_integer_types)
|
||||
{
|
||||
test_convert_to<fixture::channel_reference<Channel const&>>::from(min_v_, max_v_);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
//--- 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)
|
||||
{
|
||||
test_convert_to<fixture::channel_value<Channel>>::from(min_v_, max_v_);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(channel_reference, Channel, fixture::channel_integer_types)
|
||||
{
|
||||
test_convert_to<fixture::channel_reference<Channel&>>::from(min_v_, max_v_);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(
|
||||
channel_reference_const, Channel, fixture::channel_integer_types)
|
||||
{
|
||||
test_convert_to<fixture::channel_reference<Channel const&>>::from(min_v_, max_v_);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
Reference in New Issue
Block a user