]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/gil/test/core/channel/scoped_channel_value.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / gil / test / core / channel / scoped_channel_value.cpp
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 // Copyright 2018 Mateusz Loskot <mateusz at loskot dot net>
4 //
5 // Distribtted 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.hpp>
10 #include <boost/gil/channel_algorithm.hpp>
11 #include <boost/gil/typedefs.hpp>
12 #include <cstdint>
13 #include <limits>
14
15 #define BOOST_TEST_MODULE test_scoped_channel_value
16 #include "unit_test.hpp"
17
18 namespace gil = boost::gil;
19
20 struct int_minus_value { static std::int8_t apply() { return -64; } };
21 struct int_plus_value { static std::int8_t apply() { return 64; } };
22 using fixture = gil::scoped_channel_value
23 <
24 std::uint8_t, int_minus_value, int_plus_value
25 >;
26
27 BOOST_AUTO_TEST_CASE(scoped_channel_value_default_constructor)
28 {
29 fixture f;
30 std::uint8_t v = f;
31 BOOST_TEST(v == std::uint8_t{0});
32 }
33
34 BOOST_AUTO_TEST_CASE(scoped_channel_value_user_defined_constructors)
35 {
36 fixture f{1};
37 std::uint8_t v = f;
38 BOOST_TEST(v == std::uint8_t{1});
39 }
40
41 BOOST_AUTO_TEST_CASE(scoped_channel_value_copy_constructors)
42 {
43 fixture f1{128};
44 fixture f2{f1};
45
46 BOOST_TEST(std::uint8_t{f1} == std::uint8_t{128});
47 BOOST_TEST(std::uint8_t{f1} == std::uint8_t{f2});
48 }
49
50 BOOST_AUTO_TEST_CASE(scoped_channel_value_assignment)
51 {
52 fixture f;
53 f = 64;
54 std::uint8_t v = f;
55 BOOST_TEST(v == std::uint8_t{64});
56 }
57
58 BOOST_AUTO_TEST_CASE(scoped_channel_value_float32_t)
59 {
60 auto const tolerance = btt::tolerance(std::numeric_limits<float>::epsilon());
61 // min
62 BOOST_TEST(gil::float_point_zero<float>::apply() == 0.0, tolerance);
63 BOOST_TEST(gil::channel_traits<gil::float32_t>::min_value() == 0.0);
64 // max
65 BOOST_TEST(gil::float_point_one<float>::apply() == 1.0, tolerance);
66 BOOST_TEST(gil::channel_traits<gil::float32_t>::max_value() == 1.0);
67 }
68
69 BOOST_AUTO_TEST_CASE(scoped_channel_value_float64_t)
70 {
71 auto const tolerance = btt::tolerance(std::numeric_limits<double>::epsilon());
72 // min
73 BOOST_TEST(gil::float_point_zero<double>::apply() == 0.0, tolerance);
74 BOOST_TEST(gil::channel_traits<gil::float64_t>::min_value() == 0.0, tolerance);
75 // max
76 BOOST_TEST(gil::float_point_one<double>::apply() == 1.0, tolerance);
77 BOOST_TEST(gil::channel_traits<gil::float64_t>::max_value() == 1.0, tolerance);
78 }
79
80 BOOST_AUTO_TEST_CASE(scoped_channel_value_halfs)
81 {
82 // Create a double channel with range [-0.5 .. 0.5]
83 struct minus_half { static double apply() { return -0.5; } };
84 struct plus_half { static double apply() { return 0.5; } };
85 using halfs = gil::scoped_channel_value<double, minus_half, plus_half>;
86
87 auto const tolerance = btt::tolerance(std::numeric_limits<double>::epsilon());
88 BOOST_TEST(gil::channel_traits<halfs>::min_value() == minus_half::apply(), tolerance);
89 BOOST_TEST(gil::channel_traits<halfs>::max_value() == plus_half::apply(), tolerance);
90 // scoped channel maximum should map to the maximum
91 BOOST_TEST(gil::channel_convert<std::uint16_t>(
92 gil::channel_traits<halfs>::max_value()) == 65535, tolerance);
93 }