Skip to content

Commit

Permalink
test: Add more basic cases for image class (#423)
Browse files Browse the repository at this point in the history
This hopefully will begin extensive test suite for the image class to
maintain decent coverage for this major class of GIL.
  • Loading branch information
mloskot committed Jun 29, 2022
1 parent 86ee473 commit 2409be4
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 6 deletions.
5 changes: 3 additions & 2 deletions test/core/image/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#
foreach(_name
concepts
image
empty_dimensions)
alignment
empty_dimensions
image)
set(_test t_core_image_${_name})
set(_target test_core_image_${_name})

Expand Down
3 changes: 2 additions & 1 deletion test/core/image/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ import testing ;

compile concepts.cpp ;

run image.cpp ;
run alignment.cpp ;
run empty_dimensions.cpp ;
run image.cpp ;
125 changes: 125 additions & 0 deletions test/core/image/alignment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
}
1 change: 1 addition & 0 deletions test/core/image/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ struct test_move_assignement
BOOST_TEST_EQ(image.dimensions(), gil::point_t{});
}
}

static void run()
{
boost::mp11::mp_for_each<fixture::image_types>(test_move_assignement{});
Expand Down
13 changes: 10 additions & 3 deletions test/core/image/test_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#define BOOST_GIL_TEST_CORE_IMAGE_TEST_FIXTURE_HPP

#include <boost/gil.hpp>
#include <boost/assert.hpp>

#include <cstdint>
#include <initializer_list>
Expand All @@ -18,8 +17,6 @@
#include <tuple>
#include <type_traits>

#include "core/test_fixture.hpp"

namespace boost { namespace gil { namespace test { namespace fixture {

using image_types = std::tuple
Expand Down Expand Up @@ -71,6 +68,16 @@ using rgb_interleaved_image_types = std::tuple
gil::rgba32_image_t
>;

using bit_aligned_image_types = std::tuple
<
gil::bit_aligned_image1_type<1, gil::gray_layout_t>::type,
gil::bit_aligned_image1_type<3, gil::gray_layout_t>::type,
gil::bit_aligned_image1_type<8, gil::gray_layout_t>::type,
gil::bit_aligned_image3_type<2, 2, 2, gil::rgb_layout_t>::type,
gil::bit_aligned_image3_type<5, 6, 5, gil::rgb_layout_t>::type,
gil::bit_aligned_image3_type<6, 6, 6, gil::rgb_layout_t>::type
>;

template <typename Image, typename Generator>
auto generate_image(std::ptrdiff_t size_x, std::ptrdiff_t size_y, Generator&& generate) -> Image
{
Expand Down

0 comments on commit 2409be4

Please sign in to comment.