-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add virtual_2d_locator fixture; is_2d_traversable test case
- Loading branch information
Showing
5 changed files
with
156 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# | ||
# Copyright (c) 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) | ||
# | ||
foreach(_name | ||
is_2d_traversable) | ||
set(_test t_core_virtual_2d_locator_${_name}) | ||
set(_target test_core_virtual_2d_locator_${_name}) | ||
|
||
add_executable(${_target} "") | ||
target_sources(${_target} PRIVATE ${_name}.cpp) | ||
target_link_libraries(${_target} | ||
PRIVATE | ||
gil_compile_options | ||
gil_include_directories | ||
gil_dependencies) | ||
target_compile_definitions(${_target} PRIVATE BOOST_GIL_USE_CONCEPT_CHECK) | ||
add_test(NAME ${_test} COMMAND ${_target}) | ||
|
||
unset(_name) | ||
unset(_target) | ||
unset(_test) | ||
endforeach() |
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,11 @@ | ||
# Boost.GIL (Generic Image Library) - tests | ||
# | ||
# Copyright (c) 2022 Mateusz Loskot <[email protected]> | ||
# | ||
# 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) | ||
|
||
import testing ; | ||
|
||
run is_2d_traversable.cpp ; |
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,41 @@ | ||
// | ||
// 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_pixel_types | ||
{ | ||
template <typename Pixel> | ||
void operator()(Pixel const&) | ||
{ | ||
using deref_t = fixture::noop_dereference_fn<Pixel>; | ||
using locator_t = gil::virtual_2d_locator<deref_t, false>; | ||
using view_t = gil::image_view<locator_t>; | ||
|
||
view_t view; | ||
BOOST_TEST(!view.is_1d_traversable()); | ||
} | ||
static void run() | ||
{ | ||
boost::mp11::mp_for_each<fixture::pixel_types>(test_pixel_types{}); | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
test_pixel_types::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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// 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 | ||
// | ||
#ifndef BOOST_GIL_TEST_CORE_VIRTUAL_2D_LOCATOR_TEST_FIXTURE_HPP | ||
#define BOOST_GIL_TEST_CORE_VIRTUAL_2D_LOCATOR_TEST_FIXTURE_HPP | ||
|
||
#include <boost/gil.hpp> | ||
#include <boost/assert.hpp> | ||
|
||
#include <stdexcept> | ||
|
||
#include "core/pixel/test_fixture.hpp" | ||
|
||
namespace boost { namespace gil { namespace test { namespace fixture { | ||
|
||
template <typename Pixel> | ||
struct noop_dereference_fn | ||
{ | ||
static constexpr bool is_mutable =false; | ||
|
||
using const_t = noop_dereference_fn; | ||
using value_type = Pixel; | ||
using reference = value_type; | ||
using const_reference = value_type; | ||
using argument_type = gil::point_t; | ||
using result_type = reference; | ||
|
||
static_assert(std::is_same<value_type, reference>::value, "value_type != reference"); | ||
static_assert(std::is_same<value_type, result_type>::value, "value_type != result_type"); | ||
|
||
result_type operator()(gil::point_t const&) const | ||
{ | ||
return result_type{}; | ||
} | ||
}; | ||
|
||
template <typename Pixel> | ||
struct locator_dereference_fn | ||
{ | ||
static constexpr bool is_mutable =false; | ||
|
||
using const_t = locator_dereference_fn; | ||
using value_type = Pixel; | ||
using reference = value_type; | ||
using const_reference = value_type; | ||
using argument_type = gil::point_t; | ||
using result_type = reference; | ||
|
||
static_assert(std::is_same<value_type, reference>::value, "value_type != reference"); | ||
static_assert(std::is_same<value_type, result_type>::value, "value_type != result_type"); | ||
|
||
locator_dereference_fn() = default; | ||
locator_dereference_fn(point_t const& dims) : _dimensions(dims) {} | ||
|
||
result_type operator()(gil::point_t const& position) const | ||
{ | ||
if (position.x >= _dimensions.x) | ||
throw std::out_of_range("position x out of range"); | ||
if (position.y >= _dimensions.y) | ||
throw std::out_of_range("position y out of range"); | ||
|
||
auto pixel = pixel_generator<value_type>::random(); | ||
return pixel; | ||
} | ||
|
||
private: | ||
gil::point_t _dimensions; | ||
}; | ||
|
||
}}}} // namespace boost::gil::test::fixture | ||
|
||
#endif |