-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add more basic cases for image class (#423)
This hopefully will begin extensive test suite for the image class to maintain decent coverage for this major class of GIL.
- Loading branch information
Showing
5 changed files
with
141 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters