Skip to content

Commit

Permalink
Add more basic test cases cases for image class
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 Feb 1, 2020
1 parent 5f3c002 commit 33c2249
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
75 changes: 75 additions & 0 deletions test/core/image/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,75 @@
namespace gil = boost::gil;
namespace fixture = boost::gil::test::fixture;

BOOST_AUTO_TEST_CASE_TEMPLATE(default_constructor, Image, fixture::image_types)
{
{
Image image;
BOOST_TEST(image.width() == 0);
BOOST_TEST(image.height() == 0);
}
{
std::size_t alignment = 0;
Image image(alignment);
BOOST_TEST(image.width() == 0);
BOOST_TEST(image.height() == 0);
}
{
std::size_t alignment = 0;
std::allocator<unsigned char> allocator;
Image image(alignment, allocator);
BOOST_TEST(image.width() == 0);
BOOST_TEST(image.height() == 0);
}
}

BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_with_dimensions, Image, fixture::image_types)
{
gil::point_t const dimensions{256, 128};
{
Image image(dimensions);
BOOST_TEST(image.width() == dimensions.x);
BOOST_TEST(image.height() == dimensions.y);
}
{
std::size_t alignment = 0;
Image image(dimensions, alignment);
BOOST_TEST(image.width() == dimensions.x);
BOOST_TEST(image.height() == dimensions.y);
}
{
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);
}
}

BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_with_width_height, Image, fixture::image_types)
{
std::ptrdiff_t const width{32};
std::ptrdiff_t const height{64};
{
Image image(width, height);
BOOST_TEST(image.width() == width);
BOOST_TEST(image.height() == height);
}
{
std::size_t alignment = 0;
Image image(width, height, alignment);
BOOST_TEST(image.width() == width);
BOOST_TEST(image.height() == height);
}
{
std::size_t alignment = 0;
std::allocator<unsigned char> allocator;
Image image(width, height, alignment, allocator);
BOOST_TEST(image.width() == width);
BOOST_TEST(image.height() == height);
}
}

BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_with_dimensions_pixel, Image, fixture::image_types)
{
gil::point_t const dimensions{256, 128};
Expand All @@ -33,3 +102,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_with_dimensions_pixel, Image, fixture:
}
}
}

// TODO:
//BOOST_AUTO_TEST_CASE(constructor_with_dimensions_bit_aligned_pixel) {}
//BOOST_AUTO_TEST_CASE(constructor_with_width_height_bit_aligned_pixel) {}
//BOOST_AUTO_TEST_CASE(constructor_with_dimensions_packed_pixel) {}
//BOOST_AUTO_TEST_CASE(constructor_with_width_height_packed_pixel) {}
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 All @@ -38,6 +35,16 @@ using 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 33c2249

Please sign in to comment.