1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
//
// Copyright 2022 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.hpp>
#include <boost/core/lightweight_test.hpp>
#include "test_fixture.hpp"
#include "core/pixel/test_fixture.hpp"
namespace gil = boost::gil;
namespace fixture = boost::gil::test::fixture;
struct test_constructor_with_alignment
{
template <typename Image>
void operator()(Image const&)
{
std::size_t alignment = 0;
Image image(alignment);
BOOST_TEST(image.width() == 0);
BOOST_TEST(image.height() == 0);
}
static void run()
{
boost::mp11::mp_for_each<fixture::image_types>(test_constructor_with_alignment{});
}
};
struct test_constructor_with_alignment_allocator
{
template <typename Image>
void operator()(Image const&)
{
std::size_t alignment = 0;
std::allocator<unsigned char> allocator;
Image image(alignment, allocator);
BOOST_TEST(image.width() == 0);
BOOST_TEST(image.height() == 0);
}
static void run()
{
boost::mp11::mp_for_each<fixture::image_types>(test_constructor_with_alignment_allocator{});
}
};
struct test_constructor_with_dimensions_alignment
{
template <typename Image>
void operator()(Image const&)
{
gil::point_t const dimensions{256, 128};
std::size_t alignment = 0;
Image image(dimensions, alignment);
BOOST_TEST(image.width() == dimensions.x);
BOOST_TEST(image.height() == dimensions.y);
}
static void run()
{
boost::mp11::mp_for_each<fixture::image_types>(test_constructor_with_dimensions_alignment{});
}
};
struct test_constructor_with_dimensions_alignment_allocator
{
template <typename Image>
void operator()(Image const&)
{
gil::point_t const dimensions{256, 128};
std::size_t alignment = 0;
std::allocator<unsigned char> allocator;
Image image(dimensions, alignment, allocator);
BOOST_TEST(image.width() == dimensions.x);
BOOST_TEST(image.height() == dimensions.y);
}
static void run()
{
boost::mp11::mp_for_each<fixture::image_types>(test_constructor_with_dimensions_alignment_allocator{});
}
};
struct test_constructor_with_dimensions_pixel_alignment
{
template <typename Image>
void operator()(Image const &)
{
gil::point_t const dimensions{3, 3};
using pixel_t = typename Image::view_t::value_type;
pixel_t const rnd_pixel = fixture::pixel_generator<pixel_t>::random();
Image image(dimensions, rnd_pixel, 32u);
BOOST_TEST(image.width() == dimensions.x);
BOOST_TEST(image.height() == dimensions.y);
for (pixel_t const& p : gil::view(image))
{
BOOST_TEST(p == rnd_pixel);
}
}
static void run()
{
boost::mp11::mp_for_each<fixture::image_types>(test_constructor_with_dimensions_pixel_alignment{});
}
};
int main()
{
test_constructor_with_alignment::run();
test_constructor_with_alignment_allocator::run();
test_constructor_with_dimensions_alignment::run();
test_constructor_with_dimensions_alignment_allocator::run();
test_constructor_with_dimensions_pixel_alignment::run();
test_constructor_with_dimensions_pixel_alignment::run();
return ::boost::report_errors();
}
|