• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 // Copyright 2018-2020 Mateusz Loskot <mateusz at loskot dot net>
4 //
5 // Distributed under the Boost Software License, Version 1.0
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
8 //
9 #include <boost/gil/channel_algorithm.hpp>
10 
11 #include <boost/core/lightweight_test.hpp>
12 
13 #include <cstdint>
14 
15 #include "test_fixture.hpp"
16 
17 namespace gil = boost::gil;
18 namespace fixture = boost::gil::test::fixture;
19 
20 template <typename ChannelFixtureBase>
test_channel_relation()21 void test_channel_relation()
22 {
23     using fixture_t = fixture::channel<ChannelFixtureBase>;
24     using channel_value_t = typename fixture_t::channel_value_t;
25     channel_value_t const one = 1;
26 
27     fixture_t f;
28     BOOST_TEST_LE(f.min_v_, f.max_v_);
29     BOOST_TEST_GE(f.max_v_, f.min_v_);
30     BOOST_TEST_LT(f.min_v_, f.max_v_);
31     BOOST_TEST_GT(f.max_v_, f.min_v_);
32     BOOST_TEST_NE(f.max_v_, f.min_v_);
33     BOOST_TEST_EQ(f.min_v_, f.min_v_);
34     BOOST_TEST_NE(f.min_v_, one); // comparable to integral
35 }
36 
37 struct test_channel_value
38 {
39     template <typename Channel>
operator ()test_channel_value40     void operator()(Channel const &)
41     {
42         using channel_t = Channel;
43         using fixture_t = fixture::channel_value<channel_t>;
44         test_channel_relation<fixture_t>();
45     }
runtest_channel_value46     static void run()
47     {
48         boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_value{});
49     }
50 };
51 
52 struct test_channel_reference
53 {
54     template <typename Channel>
operator ()test_channel_reference55     void operator()(Channel const &)
56     {
57         using channel_t = Channel;
58         using fixture_t = fixture::channel_reference<channel_t&>;
59         test_channel_relation<fixture_t>();
60     }
runtest_channel_reference61     static void run()
62     {
63         boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_reference{});
64     }
65 };
66 
67 struct test_channel_reference_const
68 {
69     template <typename Channel>
operator ()test_channel_reference_const70     void operator()(Channel const &)
71     {
72         using channel_t = Channel;
73         using fixture_t = fixture::channel_reference<channel_t const&>;
74         test_channel_relation<fixture_t>();
75     }
runtest_channel_reference_const76     static void run()
77     {
78         boost::mp11::mp_for_each<fixture::channel_byte_types>(test_channel_reference_const{});
79     }
80 };
81 
82 struct test_packed_channel_reference
83 {
84     template <typename BitField>
operator ()test_packed_channel_reference85     void operator()(BitField const &)
86     {
87         using bitfield_t = BitField;
88         using channels565_t = fixture::packed_channels565<bitfield_t>;
89         test_channel_relation<typename channels565_t::fixture_0_5_t>();
90         test_channel_relation<typename channels565_t::fixture_5_6_t>();
91         test_channel_relation<typename channels565_t::fixture_11_5_t>();
92     }
runtest_packed_channel_reference93     static void run()
94     {
95         boost::mp11::mp_for_each<fixture::channel_bitfield_types>(test_packed_channel_reference{});
96     }
97 };
98 
99 struct test_packed_dynamic_channel_reference
100 {
101     template <typename BitField>
operator ()test_packed_dynamic_channel_reference102     void operator()(BitField const &)
103     {
104         using bitfield_t = BitField;
105         using channels565_t = fixture::packed_dynamic_channels565<bitfield_t>;
106         test_channel_relation<typename channels565_t::fixture_5_t>();
107         test_channel_relation<typename channels565_t::fixture_6_t>();
108     }
runtest_packed_dynamic_channel_reference109     static void run()
110     {
111         boost::mp11::mp_for_each<fixture::channel_bitfield_types>(test_packed_dynamic_channel_reference{});
112     }
113 };
114 
main()115 int main()
116 {
117     test_channel_value::run();
118     test_channel_reference::run();
119     test_channel_reference_const::run();
120     test_packed_channel_reference::run();
121     test_packed_dynamic_channel_reference::run();
122 
123     // TODO: packed_channel_reference_const ?
124     // TODO: packed_dynamic_channel_reference_const ?
125 
126     return ::boost::report_errors();
127 }
128