2
0
mirror of https://github.com/boostorg/gil.git synced 2026-02-26 16:52:10 +00:00

Fix GCC -Wunused-but-set-variable warning in toolbox tests (#219)

Fixes at least eight warnings issued by in the toolbox tests:
  warning: variable (...) set but not used [-Wunused-but-set-variable]

Add new or improve existing BOOST_TEST checks.
This commit is contained in:
Mateusz Loskot
2019-01-20 18:46:21 +01:00
committed by GitHub
parent 54b9dc7382
commit afcdeb04cd
2 changed files with 98 additions and 83 deletions

View File

@@ -11,28 +11,32 @@
#include <boost/test/unit_test.hpp>
#include <boost/type_traits/is_same.hpp>
using namespace boost;
using namespace gil;
namespace bg = boost::gil;
BOOST_AUTO_TEST_SUITE( toolbox_tests )
BOOST_AUTO_TEST_SUITE(toolbox_tests)
BOOST_AUTO_TEST_CASE( channel_view_test )
BOOST_AUTO_TEST_CASE(channel_view_test)
{
using image_t = rgb8_image_t;
using image_t = bg::rgb8_image_t;
image_t img(100, 100);
image_t img( 100, 100 );
using kth_channel_view_t
= bg::kth_channel_view_type<0, bg::rgb8_view_t::const_t>::type;
using channel_view_t
= bg::channel_view_type<bg::red_t, bg::rgb8_view_t::const_t>::type;
using view_t = kth_channel_view_type<0, rgb8_view_t::const_t>::type;
view_t red = kth_channel_view<0>( const_view( img ));
using channel_view_t = channel_view_type<red_t, rgb8_view_t::const_t>::type;
channel_view_t red_ = channel_view< red_t >( const_view( img ));
static_assert(is_same
static_assert(boost::is_same
<
kth_channel_view_type<0, rgb8_view_t const>::type,
channel_view_type<red_t, rgb8_view_t const>::type
>::value, "");
kth_channel_view_t,
channel_view_t
>::value,
"");
kth_channel_view_t const kth0 = bg::kth_channel_view<0>(bg::const_view(img));
BOOST_TEST(kth0.num_channels() == 1);
channel_view_t const red = bg::channel_view<bg::red_t>(bg::const_view(img));
BOOST_TEST(red.num_channels() == 1);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -11,49 +11,61 @@
#include <boost/assert.hpp>
#include <boost/test/unit_test.hpp>
using namespace std;
using namespace boost;
using namespace gil;
#include <cstdint>
BOOST_AUTO_TEST_SUITE( toolbox_tests )
namespace bg = boost::gil;
BOOST_AUTO_TEST_CASE( index_image_test )
BOOST_AUTO_TEST_SUITE(toolbox_tests)
BOOST_AUTO_TEST_CASE(index_image_test)
{
{
indexed_image< uint8_t, rgb8_pixel_t > img( 640, 480 );
fill_pixels( view( img ), rgb8_pixel_t( 255, 0, 0 ));
auto const pixel_generator = []() -> bg::rgb8_pixel_t {
static std::uint8_t i = 0;
i = (i == 256) ? 0 : (i + 1);
return bg::rgb8_pixel_t(i, i, i);
};
rgb8_pixel_t p = *view( img ).xy_at( 10, 10 );
{
bg::indexed_image<std::uint8_t, bg::rgb8_pixel_t> img(640, 480);
bg::fill_pixels(bg::view(img), bg::rgb8_pixel_t(255, 0, 0));
bg::rgb8_pixel_t const p = *bg::view(img).xy_at(10, 10);
BOOST_TEST(p[0] == 255);
}
{
using image_t = indexed_image<gray8_pixel_t, rgb8_pixel_t>;
using image_t = bg::indexed_image<bg::gray8_pixel_t, bg::rgb8_pixel_t>;
image_t img(640, 480, 256);
image_t img( 640, 480, 256 );
generate_pixels(img.get_indices_view(), []() -> uint8_t
generate_pixels(img.get_indices_view(), []() -> std::uint8_t
{
static uint8_t i = 0;
static std::uint8_t i = 0;
i = (i == 256) ? 0 : (i + 1);
return gray8_pixel_t(i);
return bg::gray8_pixel_t(i);
});
generate_pixels(img.get_palette_view(), pixel_generator);
generate_pixels(img.get_palette_view(), []() -> rgb8_pixel_t
{
static uint8_t i = 0;
i = (i == 256) ? 0 : (i + 1);
return rgb8_pixel_t(i, i, i);
});
bg::gray8_pixel_t index{0};
index = *img.get_indices_view().xy_at(0, 0); // verify values along first row
BOOST_TEST(static_cast<int>(index) == (0 + 1));
index = *img.get_indices_view().xy_at(128, 0);
BOOST_TEST(static_cast<int>(index) == (128 + 1));
// verify wrapping of value by the pixels generator above
index = *img.get_indices_view().xy_at(255, 0);
BOOST_TEST(static_cast<int>(index) == 0);
gray8_pixel_t index = *img.get_indices_view().xy_at( 10 , 1 );
rgb8_pixel_t color = *img.get_palette_view().xy_at( index, 0 );
// access via member function
bg::rgb8_pixel_t const pixel1 = *img.get_palette_view().xy_at(index, 0);
BOOST_TEST(pixel1[0] == pixel1[1]);
BOOST_TEST(pixel1[1] == pixel1[2]);
rgb8_pixel_t p = *view( img ).xy_at( 10, 1 );
// access via free function
bg::rgb8_pixel_t const pixel2 = *bg::view(img).xy_at(10, 1);
BOOST_TEST(pixel2[0] == pixel2[1]);
BOOST_TEST(pixel2[1] == pixel2[2]);
}
{
using image_t = indexed_image<gray8_pixel_t, rgb8_pixel_t>;
image_t img( 640, 480, 256 );
using image_t = bg::indexed_image<bg::gray8_pixel_t, bg::rgb8_pixel_t>;
image_t img(640, 480, 256);
generate_pixels(img.get_indices_view(), []() -> uint8_t
{
@@ -61,34 +73,35 @@ BOOST_AUTO_TEST_CASE( index_image_test )
i = (i == 256) ? 0 : (i + 1);
return i;
});
generate_pixels(img.get_palette_view(), pixel_generator);
generate_pixels(img.get_palette_view(), []() -> rgb8_pixel_t
{
static uint8_t i = 0;
i = (i == 256) ? 0 : (i + 1);
return rgb8_pixel_t(i, i, i);
});
std::uint8_t index = *img.get_indices_view().xy_at(128, 0);
BOOST_TEST(static_cast<int>(index) == (128 + 1));
uint8_t index = *img.get_indices_view().xy_at( 10 , 1 );
rgb8_pixel_t color = *img.get_palette_view().xy_at( index, 0 );
bg::rgb8_pixel_t const pixel1 = *img.get_palette_view().xy_at(index, 0);
BOOST_TEST(pixel1[0] == pixel1[1]);
BOOST_TEST(pixel1[1] == pixel1[2]);
rgb8_pixel_t p = *view( img ).xy_at( 10, 1 );
bg::rgb8_pixel_t const pixel2 = *view(img).xy_at(10, 1);
BOOST_TEST(pixel2[0] == pixel2[1]);
BOOST_TEST(pixel2[1] == pixel2[2]);
}
{
using image_t = indexed_image<uint8_t, rgb8_pixel_t>;
image_t img( 640, 480, 256 );
using image_t = bg::indexed_image<std::uint8_t, bg::rgb8_pixel_t>;
image_t img(640, 480, 256);
for( image_t::y_coord_t y = 0; y < view( img ).height(); ++y )
for (image_t::y_coord_t y = 0; y < bg::view(img).height(); ++y)
{
image_t::view_t::x_iterator it = view( img ).row_begin( y );
for( image_t::x_coord_t x = 0; x < view( img ).width(); ++x )
image_t::view_t::x_iterator it = bg::view(img).row_begin(y);
for (image_t::x_coord_t x = 0; x < bg::view(img).width(); ++x)
{
rgb8_pixel_t p = *it;
bg::rgb8_pixel_t p = *it;
boost::ignore_unused(p);
it++;
}
}
// TODO: No checks? ~mloskot
}
}
@@ -101,37 +114,35 @@ BOOST_AUTO_TEST_CASE(index_image_view_test)
std::uint8_t const index = 2;
// indices
vector<uint8_t> indices(width * height, index);
std::vector<std::uint8_t> indices(width * height, index);
// colors
vector<rgb8_pixel_t> palette(num_colors);
palette[0] = rgb8_pixel_t(10, 20, 30);
palette[1] = rgb8_pixel_t(40, 50, 60);
palette[2] = rgb8_pixel_t(70, 80, 90);
std::vector<bg::rgb8_pixel_t> palette(num_colors);
palette[0] = bg::rgb8_pixel_t(10, 20, 30);
palette[1] = bg::rgb8_pixel_t(40, 50, 60);
palette[2] = bg::rgb8_pixel_t(70, 80, 90);
// create image views from raw memory
auto indices_view = interleaved_view(width, height
, (gray8_image_t::view_t::x_iterator) indices.data()
, width // row size in bytes
);
auto indices_view = bg::interleaved_view(width, height,
(bg::gray8_image_t::view_t::x_iterator) indices.data(),
width); // row size in bytes
auto palette_view = interleaved_view(100, 1
, (rgb8_image_t::view_t::x_iterator) palette.data()
, num_colors * 3 // row size in bytes
);
auto palette_view = bg::interleaved_view(100, 1,
(bg::rgb8_image_t::view_t::x_iterator) palette.data(),
num_colors * 3); // row size in bytes
auto ii_view = view(indices_view, palette_view);
auto ii_view = bg::view(indices_view, palette_view);
auto p = ii_view(point_t(0, 0));
auto q = *ii_view.at(point_t(0, 0));
auto p = ii_view(bg::point_t(0, 0));
auto q = *ii_view.at(bg::point_t(0, 0));
BOOST_ASSERT(get_color(p, red_t()) == 70);
BOOST_ASSERT(get_color(p, green_t()) == 80);
BOOST_ASSERT(get_color(p, blue_t()) == 90);
BOOST_ASSERT(bg::get_color(p, bg::red_t()) == 70);
BOOST_ASSERT(bg::get_color(p, bg::green_t()) == 80);
BOOST_ASSERT(bg::get_color(p, bg::blue_t()) == 90);
BOOST_ASSERT(get_color(q, red_t()) == 70);
BOOST_ASSERT(get_color(q, green_t()) == 80);
BOOST_ASSERT(get_color(q, blue_t()) == 90);
BOOST_ASSERT(bg::get_color(q, bg::red_t()) == 70);
BOOST_ASSERT(bg::get_color(q, bg::green_t()) == 80);
BOOST_ASSERT(bg::get_color(q, bg::blue_t()) == 90);
}
BOOST_AUTO_TEST_SUITE_END()