2
0
mirror of https://github.com/boostorg/gil.git synced 2026-02-19 02:22:09 +00:00
Files
gil/CMakeLists.txt
Mateusz Loskot 73ec99e606 Refactor single-program channel test to Boost.Test suites and cases
Motivation:
- state clearly what is covered with tests without reading non-trivial code
- avoid cleverness - tests should be no-brainer
- get closer to one test case targets one feature/beaviour with one check
- replace obscure `throw std::exception` with diagnostics that are actually
  useful to pin-point failure cause and location - makes CI logs useful.
- allow to select and run specific tests
- make tests maintenance easy, quick and fun

Propose new structure of tests that reflects the previous tests hierarchy,
but organizes channel tests in test/channel directory with test programs
each covering specific library feature (or set of closely related features).

The refactored tests cover 100% of checks from the old `channel.cpp`,
plus it refines or adds a bunch more.
NOTE: old test/channel.cpp has not been removed yet.

Common definitions from the single test/channel.cpp moved to
channel_test_fixtures.hpp and namespace boost::gil::test::fixture:
Classes and typedefs:
- `do_test` as `fixture::channel`
- `value_core` as `fixture::channel_value`
- `reference_core` as `fixture::channel_reference`
- `packed_reference_core` as `fixture::packed_channel_reference`
- `packed_dynamic_reference_core` as `fixture::packed_dynamic_channel_reference`
- `channel_archetype` and relatives to `channel_concepts.cpp` which is compile
   test in Jamfile
- `test_packed_channel_reference()` parts as `fixture::packed_channels565`
- `test_packed_dynamic_channel_reference()` parts as `fixture::packed_dynamic_channels565`
Test case functions called from `do_test<T>::test_all`:
- `test_channel_invert()` to `algorithm_channel_invert.cpp` suite
- `test_channel_convert()` to `algorithm_channel_convert.cpp` suite
- `test_channel_multiply()` to `algorithm_channel_multiply.cpp` suite
- `test_channel_math()` split to `algorithm_channel_relation.cpp`
   and `algorithm_channel_arithmetic.cpp`

Add test cases for each channel value type T as used to run from
`test_channel_value_impl<T>`, `test_packed_channel_reference<T>` and
`test_packed_dynamic_channel_reference<T>`.

Add list of possible T-s defined as type-lists `fixture::channel_byte_types`,
`fixture::channel_integer_types`, `channel_float_types` and
`channel_bitfield_types` which used with `BOOST_AUTO_TEST_CASE_TEMPLATE`
generate all possible combination of inputs.

Add new `channel_test_fixture.cpp` is a self-test suite verifying the fixtures.
2018-06-27 00:02:27 -04:00

159 lines
6.0 KiB
CMake

#
# Copyright (c) 2017 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)
#
cmake_minimum_required(VERSION 3.10)
project(Boost.GIL CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include(CMakeDependentOption)
option(GIL_BUILD_TESTS "Build GIL tests" ON)
option(GIL_BUILD_EXAMPLES "Build GIL examples" OFF) # FIXME: Switch to ON after https://github.com/boostorg/gil/issues/40
option(GIL_ENABLE_IO "Enable GIL IO in tests and examples (require libjpeg, libpng, libtiff)" ON)
option(GIL_USE_BOOST_STAGE "Use Boost from current source tree and libraries from stage, unless BOOST_ROOT specified." ON)
option(GIL_USE_CONAN "Use Conan to install dependencies" OFF)
#-----------------------------------------------------------------------------
# Dependency: Boost
# - look for stage Build
# - look for default installation location
# - look for location specified with BOOST_ROOT
#-----------------------------------------------------------------------------
if (CMAKE_VERSION VERSION_LESS 3.11)
# Latest FindBoost.cmake has likely been updated to detect Boost version not yet released
if (NOT EXISTS "${CMAKE_BINARY_DIR}/cmake/FindBoost.cmake")
message(STATUS "Downloading FindBoost.cmake from https://gitlab.kitware.com/cmake/ release branch")
file(DOWNLOAD
"https://gitlab.kitware.com/cmake/cmake/raw/release/Modules/FindBoost.cmake"
"${CMAKE_BINARY_DIR}/cmake/FindBoost.cmake")
endif()
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_BINARY_DIR}/cmake)
endif()
if(GIL_USE_BOOST_STAGE AND NOT DEFINED BOOST_ROOT AND NOT DEFINED ENV{BOOST_ROOT})
get_filename_component(_boost_root ../../ ABSOLUTE)
if(EXISTS ${_boost_root}/boost-build.jam)
set(BOOST_ROOT ${_boost_root})
message(STATUS "Using Boost libraries from stage directory in BOOST_ROOT=${BOOST_ROOT}")
endif()
endif()
set(BOOST_COMPONENTS)
if(GIL_BUILD_TESTS)
list(APPEND BOOST_COMPONENTS unit_test_framework filesystem)
endif()
set(Boost_DETAILED_FAILURE_MSG ON)
if(MSVC)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME OFF)
endif()
find_package(Boost 1.67.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
# The boostorg/gil repository includes must come first,
# before Boost includes from cloned Boost superproject or installed distribution.
# Otherwise the IDE sees the wrong file (ie. due to boost/ symlinks or
# GIL headers from installed Boost instead of this clone of boostog/gil).
include_directories(include)
# GIL header gil_test_common.hpp shared between tests
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test)
#-----------------------------------------------------------------------------
# Dependency: libpng, libjpeg, libtiff via Vcpkg or Conan
#-----------------------------------------------------------------------------
if (GIL_ENABLE_IO)
if(GIL_USE_CONAN)
# Download automatically, you can also just copy the conan.cmake file
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.9/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake")
endif()
# NOTE: See RelWithDebInfo for Release builds, http://docs.conan.io/en/latest/howtos/vs2017_cmake.html
set(_build_type_saved ${CMAKE_BUILD_TYPE})
if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(CMAKE_BUILD_TYPE "Release")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt BASIC_SETUP CMAKE_TARGETS)
set(CMAKE_BUILD_TYPE ${_build_type_saved})
else()
find_package(JPEG)
find_package(PNG)
find_package(TIFF)
endif()
endif()
#-----------------------------------------------------------------------------
# Compiler
#
# Follows https://svn.boost.org/trac10/wiki/Guidelines/WarningsGuidelines
#-----------------------------------------------------------------------------
if(MSVC)
string(REGEX REPLACE "/W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "-W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
add_compile_options(-W4)
add_compile_options(-bigobj)
add_compile_options(-FC) # Need absolute path for __FILE__ used in tests
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE=1)
add_definitions(-D_SCL_SECURE_NO_DEPRECATE=1)
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
add_definitions(-D_SCL_SECURE_NO_WARNINGS=1)
add_definitions(-DNOMINMAX=1)
add_definitions(-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE=1)
else()
# Assumes compilers which recognize GCC and clang speak
add_compile_options(-pedantic)
add_compile_options(-fstrict-aliasing)
add_compile_options(-Wall)
add_compile_options(-Wextra)
add_compile_options(-Wstrict-aliasing)
add_compile_options(-Wconversion )
add_compile_options(-Wsign-promo)
add_compile_options(-Wfloat-equal)
add_compile_options(-Wunused-parameter)
add_compile_options(-Wshadow)
endif()
#-----------------------------------------------------------------------------
# Headers
#-----------------------------------------------------------------------------
file(GLOB _boost_gil_headers
${PROJECT_SOURCE_DIR}/include/boost/gil/*.hpp
${PROJECT_SOURCE_DIR}/include/boost/gil.hpp)
#-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
if(GIL_BUILD_TESTS)
file(GLOB _boost_gil_test_headers
${PROJECT_SOURCE_DIR}/test/gil_test_common.hpp)
enable_testing()
add_subdirectory(test)
if (GIL_ENABLE_IO)
add_subdirectory(io/test)
endif()
add_subdirectory(numeric/test)
add_subdirectory(toolbox/test)
endif()
#-----------------------------------------------------------------------------
# Examples
#-----------------------------------------------------------------------------
if(GIL_BUILD_EXAMPLES AND GIL_ENABLE_IO)
add_subdirectory(example)
endif()