Skip to content

Commit

Permalink
Replace Boost.Test with Boost.LightweightTest in test/ (#459)
Browse files Browse the repository at this point in the history
Motivation is to:
- use on simpler and light test framework,
- eliminate dependency on libraries like Boost.MPL,
- achieve faster compilation times for CI builds (20% seems feasible)
- have test programs easy to run and debug
- avoid macros

Remove outdated FIXME-s for bugs that have been already fixed.
Fix off-by-one bug in test/core/test_fixture.hpp generators.
Minor corrections and tidying up.

Add missing test assertions to numeric extension tests.
Fixes #458
  • Loading branch information
mloskot committed Mar 21, 2020
1 parent 29fa4c9 commit dda885e
Show file tree
Hide file tree
Showing 94 changed files with 3,957 additions and 2,693 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(Boost_USE_STATIC_RUNTIME OFF)
endif()

find_package(Boost 1.68.0 REQUIRED
find_package(Boost 1.72.0 REQUIRED
COMPONENTS
filesystem
unit_test_framework)
Expand Down
3 changes: 2 additions & 1 deletion test/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
message(STATUS "Boost.GIL: Configuring tests in test/core")

foreach(_name
promote_integral)
promote_integral
test_fixture)
set(_test t_utility_${_name})
set(_target test_utility_${_name})

Expand Down
4 changes: 2 additions & 2 deletions test/core/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ project
alias headers_concepts : [ generate_self_contained_headers concepts ] ;
alias headers : [ generate_self_contained_headers : concepts extension io ] ;

run promote_integral.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run test_fixture.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run promote_integral.cpp ;
run test_fixture.cpp ;

build-project point ;
build-project channel ;
Expand Down
6 changes: 3 additions & 3 deletions test/core/algorithm/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

import testing ;

run for_each_pixel.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run std_fill.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run std_uninitialized_fill.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run for_each_pixel.cpp ;
run std_fill.cpp ;
run std_uninitialized_fill.cpp ;
16 changes: 11 additions & 5 deletions test/core/algorithm/for_each_pixel.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
//
// Copyright 2018 Mateusz Loskot <mateusz at loskot dot net>
// Copyright 2018-2020 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
//
#define BOOST_TEST_MODULE gil/test/core/algorithm/for_each_pixel
#include "unit_test.hpp"

#include <boost/gil/algorithm.hpp>
#include <boost/gil/image.hpp>

#include <boost/core/lightweight_test.hpp>

namespace gil = boost::gil;

BOOST_AUTO_TEST_CASE(lambda_expression)
void test_lambda_expression()
{
gil::gray8_pixel_t const gray128(128);
gil::gray8_image_t image(2, 2, gray128);
Expand All @@ -24,3 +23,10 @@ BOOST_AUTO_TEST_CASE(lambda_expression)
});
BOOST_TEST(sum == 2 * 2 * 128);
}

int main()
{
test_lambda_expression();

return ::boost::report_errors();
}
33 changes: 23 additions & 10 deletions test/core/algorithm/std_fill.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2018 Mateusz Loskot <mateusz at loskot dot net>
// Copyright 2018-2020 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
Expand All @@ -10,16 +10,13 @@
// pixel.hpp(50) : error C2039 : 'type' : is not a member of 'boost::gil::color_space_type<P>
#undef BOOST_GIL_USE_CONCEPT_CHECK
#endif
#define BOOST_TEST_MODULE gil/test/core/algorithm/std_fill
#include "unit_test.hpp"

#include <boost/gil/algorithm.hpp>
#include <boost/gil/image.hpp>
#include <boost/gil/image_view.hpp>

#include <boost/array.hpp>
#include <boost/mp11.hpp>
#include <boost/range/algorithm/fill_n.hpp>
#include <boost/core/lightweight_test.hpp>

#include <array>
#include <cstdint>
Expand All @@ -32,11 +29,27 @@ using array_pixel_types = ::boost::mp11::mp_list
std::array<int, 2>
>;

BOOST_AUTO_TEST_CASE_TEMPLATE(array_as_range, ArrayPixel, array_pixel_types)
struct test_array_as_pixel
{
template <typename Pixel>
void operator()(Pixel const&)
{
using pixel_t = Pixel;
gil::image<pixel_t> img(1, 1);
std::fill(gil::view(img).begin(), gil::view(img).end(), pixel_t{0, 1});
auto a = *gil::view(img).at(0, 0);
auto e = pixel_t{0, 1};
BOOST_TEST(a == e);
}
static void run()
{
boost::mp11::mp_for_each<array_pixel_types>(test_array_as_pixel{});
}
};

int main()
{
static_assert(ArrayPixel().size() == 2, "two-element array expected");
test_array_as_pixel::run();

gil::image<ArrayPixel> img(1, 1);
std::fill(gil::view(img).begin(), gil::view(img).end(), ArrayPixel{0, 1});
BOOST_TEST(*gil::view(img).at(0,0) == (ArrayPixel{0, 1}));
return ::boost::report_errors();
}
93 changes: 62 additions & 31 deletions test/core/algorithm/std_uninitialized_fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#define BOOST_TEST_MODULE gil/test/core/algorithm/std_uninitialized_fill
#include "unit_test.hpp"

#include <boost/gil.hpp>

#include <boost/mp11.hpp>
#include <boost/core/lightweight_test.hpp>

#include <memory>
#include <random>
Expand Down Expand Up @@ -54,40 +53,57 @@ struct pixel_array
namespace gil = boost::gil;
namespace fixture = boost::gil::test::fixture;

BOOST_TEST_DONT_PRINT_LOG_VALUE(fixture::bit_aligned_pixel_bgr232)

BOOST_AUTO_TEST_CASE_TEMPLATE(fill_with_pixel_integer_types, Pixel, fixture::pixel_integer_types)
struct fill_with_pixel_integer_types
{
auto min_pixel = fixture::pixel_generator<Pixel>::min();
auto max_pixel = fixture::pixel_generator<Pixel>::max();
auto rnd_pixel = fixture::pixel_generator<Pixel>::random();

for (auto const& fill_pixel : {min_pixel, max_pixel, rnd_pixel} )
template <typename Pixel>
void operator()(Pixel const &)
{
fixture::pixel_array<Pixel> pixels;
std::uninitialized_fill(pixels.begin(), pixels.end(), fill_pixel);
using pixel_t = Pixel;
auto min_pixel = fixture::pixel_generator<pixel_t>::min();
auto max_pixel = fixture::pixel_generator<pixel_t>::max();
auto rnd_pixel = fixture::pixel_generator<pixel_t>::random();

for (Pixel const& p : pixels)
BOOST_TEST(p == fill_pixel);
for (auto const &fill_pixel : {min_pixel, max_pixel, rnd_pixel})
{
fixture::pixel_array<pixel_t> pixels;
std::uninitialized_fill(pixels.begin(), pixels.end(), fill_pixel);

for (pixel_t const &p : pixels)
BOOST_TEST(p == fill_pixel);
}
}
}
static void run()
{
boost::mp11::mp_for_each<fixture::pixel_integer_types>(fill_with_pixel_integer_types{});
}
};

BOOST_AUTO_TEST_CASE_TEMPLATE(fill_with_pixel_float_types, Pixel, fixture::pixel_float_types)
struct fill_with_pixel_float_types
{
auto min_pixel = fixture::pixel_generator<Pixel>::min();
auto max_pixel = fixture::pixel_generator<Pixel>::max();

for (auto const& fill_pixel : {min_pixel, max_pixel} )
template <typename Pixel>
void operator()(Pixel const &)
{
fixture::pixel_array<Pixel> pixels;
std::uninitialized_fill(pixels.begin(), pixels.end(), fill_pixel);
using pixel_t = Pixel;
auto min_pixel = fixture::pixel_generator<pixel_t>::min();
auto max_pixel = fixture::pixel_generator<pixel_t>::max();

for (Pixel const& p : pixels)
BOOST_TEST(p == fill_pixel);
for (auto const &fill_pixel : {min_pixel, max_pixel})
{
fixture::pixel_array<Pixel> pixels;
std::uninitialized_fill(pixels.begin(), pixels.end(), fill_pixel);

for (Pixel const &p : pixels)
BOOST_TEST(p == fill_pixel);
}
}
}
static void run()
{
boost::mp11::mp_for_each<fixture::pixel_float_types>(fill_with_pixel_float_types{});
}
};

BOOST_AUTO_TEST_CASE(fill_with_packed_pixel_gray3)
void
test_fill_with_packed_pixel_gray3()
{
auto min_pixel = fixture::packed_pixel_gray3{0};
auto mid_pixel = fixture::packed_pixel_gray3{3};
Expand All @@ -106,7 +122,7 @@ BOOST_AUTO_TEST_CASE(fill_with_packed_pixel_gray3)
}
}

BOOST_AUTO_TEST_CASE(fill_with_packed_pixel_bgr121)
void test_fill_with_packed_pixel_bgr121()
{
auto min_pixel = fixture::packed_pixel_bgr121{0};
auto mid_pixel = fixture::packed_pixel_bgr121{8};
Expand All @@ -127,7 +143,7 @@ BOOST_AUTO_TEST_CASE(fill_with_packed_pixel_bgr121)
}
}

BOOST_AUTO_TEST_CASE(fill_with_packed_pixel_rgb535)
void test_fill_with_packed_pixel_rgb535()
{
fixture::packed_pixel_rgb535 min_pixel(0, 0, 0);
fixture::packed_pixel_rgb535 mid_pixel(15, 3, 15);
Expand All @@ -148,7 +164,7 @@ BOOST_AUTO_TEST_CASE(fill_with_packed_pixel_rgb535)
}
}

BOOST_AUTO_TEST_CASE(bit_aligned_pixel_bgr232)
void test_bit_aligned_pixel_bgr232()
{
fixture::bit_aligned_pixel_bgr232 min_pixel(0, 0, 0);
fixture::bit_aligned_pixel_bgr232 mid_pixel(1, 4, 2);
Expand All @@ -169,7 +185,7 @@ BOOST_AUTO_TEST_CASE(bit_aligned_pixel_bgr232)
}
}

BOOST_AUTO_TEST_CASE(bit_aligned_pixel_rgb567)
void test_bit_aligned_pixel_rgb567()
{
fixture::bit_aligned_pixel_rgb567 min_pixel(0, 0, 0);
fixture::bit_aligned_pixel_rgb567 mid_pixel(15, 31, 63);
Expand All @@ -189,3 +205,18 @@ BOOST_AUTO_TEST_CASE(bit_aligned_pixel_rgb567)
}
}
}

int main()
{
fill_with_pixel_integer_types::run();
fill_with_pixel_float_types::run();

test_fill_with_packed_pixel_gray3();
test_fill_with_packed_pixel_bgr121();
test_fill_with_packed_pixel_rgb535();

test_bit_aligned_pixel_bgr232();
test_bit_aligned_pixel_rgb567();

return ::boost::report_errors();
}
22 changes: 11 additions & 11 deletions test/core/channel/Jamfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Boost.GIL (Generic Image Library) - tests
#
# Copyright (c) 2018 Mateusz Loskot <mateusz@loskot.net>
# Copyright (c) 2018-2020 Mateusz Loskot <mateusz@loskot.net>
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or
Expand All @@ -10,14 +10,14 @@ import testing ;

compile is_channel_integral.cpp ;

run concepts.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run channel_traits.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run test_fixture.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run packed_channel_value.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run scoped_channel_value.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run concepts.cpp ;
run channel_traits.cpp ;
run test_fixture.cpp ;
run packed_channel_value.cpp ;
run scoped_channel_value.cpp ;

run algorithm_channel_arithmetic.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run algorithm_channel_convert.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run algorithm_channel_invert.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run algorithm_channel_multiply.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run algorithm_channel_relation.cpp /boost/test//boost_unit_test_framework : : : <link>shared:<define>BOOST_TEST_DYN_LINK=1 ;
run algorithm_channel_arithmetic.cpp ;
run algorithm_channel_convert.cpp ;
run algorithm_channel_invert.cpp ;
run algorithm_channel_multiply.cpp ;
run algorithm_channel_relation.cpp ;
Loading

0 comments on commit dda885e

Please sign in to comment.