From 86ee473f51cfc6b2f9ee205bc88b09673fea34b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Wed, 29 Jun 2022 22:58:00 +0200 Subject: [PATCH] test: Add virtual_2d_locator fixture; is_2d_traversable test case --- test/core/CMakeLists.txt | 3 +- test/core/virtual_2d_locator/CMakeLists.txt | 26 +++++++ test/core/virtual_2d_locator/Jamfile | 11 +++ .../virtual_2d_locator/is_2d_traversable.cpp | 41 ++++++++++ test/core/virtual_2d_locator/test_fixture.hpp | 76 +++++++++++++++++++ 5 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 test/core/virtual_2d_locator/CMakeLists.txt create mode 100644 test/core/virtual_2d_locator/Jamfile create mode 100644 test/core/virtual_2d_locator/is_2d_traversable.cpp create mode 100644 test/core/virtual_2d_locator/test_fixture.hpp diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index 761632decd..2b70482aa0 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -35,8 +35,9 @@ add_subdirectory(color_base) add_subdirectory(pixel) add_subdirectory(iterator) add_subdirectory(locator) +add_subdirectory(virtual_2d_locator) add_subdirectory(image) add_subdirectory(image_view) add_subdirectory(algorithm) add_subdirectory(image_processing) -add_subdirectory(histogram) \ No newline at end of file +add_subdirectory(histogram) diff --git a/test/core/virtual_2d_locator/CMakeLists.txt b/test/core/virtual_2d_locator/CMakeLists.txt new file mode 100644 index 0000000000..fa3ddb8936 --- /dev/null +++ b/test/core/virtual_2d_locator/CMakeLists.txt @@ -0,0 +1,26 @@ +# +# Copyright (c) 2022 Mateusz Loskot +# +# 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() diff --git a/test/core/virtual_2d_locator/Jamfile b/test/core/virtual_2d_locator/Jamfile new file mode 100644 index 0000000000..5607cd3741 --- /dev/null +++ b/test/core/virtual_2d_locator/Jamfile @@ -0,0 +1,11 @@ +# Boost.GIL (Generic Image Library) - tests +# +# Copyright (c) 2022 Mateusz Loskot +# +# 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 ; diff --git a/test/core/virtual_2d_locator/is_2d_traversable.cpp b/test/core/virtual_2d_locator/is_2d_traversable.cpp new file mode 100644 index 0000000000..f6d3147488 --- /dev/null +++ b/test/core/virtual_2d_locator/is_2d_traversable.cpp @@ -0,0 +1,41 @@ +// +// Copyright 2022 Mateusz Loskot +// +// 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 + +#include + +#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 + void operator()(Pixel const&) + { + using deref_t = fixture::noop_dereference_fn; + using locator_t = gil::virtual_2d_locator; + using view_t = gil::image_view; + + view_t view; + BOOST_TEST(!view.is_1d_traversable()); + } + static void run() + { + boost::mp11::mp_for_each(test_pixel_types{}); + } +}; + +int main() +{ + test_pixel_types::run(); + + return boost::report_errors(); +} diff --git a/test/core/virtual_2d_locator/test_fixture.hpp b/test/core/virtual_2d_locator/test_fixture.hpp new file mode 100644 index 0000000000..83f1b2fea2 --- /dev/null +++ b/test/core/virtual_2d_locator/test_fixture.hpp @@ -0,0 +1,76 @@ +// +// Copyright 2022 Mateusz Loskot +// +// 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 +#include + +#include + +#include "core/pixel/test_fixture.hpp" + +namespace boost { namespace gil { namespace test { namespace fixture { + +template +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, "value_type != reference"); + static_assert(std::is_same::value, "value_type != result_type"); + + result_type operator()(gil::point_t const&) const + { + return result_type{}; + } +}; + +template +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, "value_type != reference"); + static_assert(std::is_same::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::random(); + return pixel; + } + +private: + gil::point_t _dimensions; +}; + +}}}} // namespace boost::gil::test::fixture + +#endif