From 77c019a4d90c41ece8d0642eed9dcce007ad6b04 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 31 Jan 2024 10:39:31 +0100 Subject: [PATCH] fix boost unit test framework in cmake and add cmake files --- CMakeLists.txt | 11 +++-- test/CMakeLists.txt | 44 +++++-------------- test/algorithms/CMakeLists.txt | 4 ++ test/algorithms/detail/CMakeLists.txt | 15 +++++++ .../detail/approximately_equals.cpp | 19 ++++++-- test/algorithms/overlay/CMakeLists.txt | 38 ++++++++++++++++ test/algorithms/overlay/get_clusters.cpp | 5 ++- test/algorithms/relate/CMakeLists.txt | 25 +++++++++++ test/algorithms/within/CMakeLists.txt | 26 +++++++++++ 9 files changed, 145 insertions(+), 42 deletions(-) create mode 100644 test/algorithms/detail/CMakeLists.txt create mode 100644 test/algorithms/overlay/CMakeLists.txt create mode 100644 test/algorithms/relate/CMakeLists.txt create mode 100644 test/algorithms/within/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index c445529493..5b859fe837 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ add_library(boost_geometry INTERFACE) add_library(Boost::geometry ALIAS boost_geometry) target_include_directories(boost_geometry INTERFACE include) +target_compile_features(boost_geometry INTERFACE cxx_std_14) target_link_libraries(boost_geometry INTERFACE @@ -65,18 +66,15 @@ if(BOOST_GEOMETRY_BUILD_OPTIONAL) INTERFACE Boost::thread ) -endif() -# Requirements for extensions -if(BOOST_GEOMETRY_BUILD_OPTIONAL) + # Requirements for extensions target_link_libraries(boost_geometry INTERFACE Boost::endian Boost::predef ) -endif() -target_compile_features(boost_geometry INTERFACE cxx_std_14) +endif() if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") @@ -104,12 +102,13 @@ if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") any lexical_cast math + multiprecision qvm rational serialization tokenizer variant - multiprecision) + test) if (BOOST_SRC_DIR_IS_VALID) set(BOOST_EXCLUDE_LIBRARIES ${PROJECT_NAME}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 996851682c..0fd8182841 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,41 +14,21 @@ function(boost_geometry_add_unit_test prefix item) set(unit_test_name "boost_geometry_${prefix}_${item}") add_executable(${unit_test_name} ${item}.cpp) - target_link_libraries(${unit_test_name} PRIVATE Boost::geometry) - + # Add a dependendcy to Boost.Geometry target_link_libraries(${unit_test_name} PRIVATE - Boost::algorithm - Boost::any - Boost::array - Boost::assert - Boost::concept_check - Boost::config - Boost::core - Boost::function_types - Boost::iterator - Boost::lexical_cast - Boost::math - Boost::move - Boost::mpl - Boost::multiprecision - Boost::numeric_conversion - Boost::qvm - Boost::range - Boost::rational - Boost::static_assert - Boost::throw_exception - Boost::tokenizer - Boost::tuple - Boost::type_traits - Boost::utility - Boost::variant - ) - - target_include_directories(${unit_test_name} PRIVATE "${PROJECT_SOURCE_DIR}/test" .) + Boost::geometry) - # Add the Boost.Test framework - target_include_directories(${unit_test_name} PRIVATE "${BOOST_SRC_DIR}/libs/test/include" .) + # For unit tests, add a dependency to the unit test framework (in header only mode) + target_link_libraries(${unit_test_name} + PRIVATE + Boost::included_unit_test_framework) + + # Incclude the main Geometry test folder and the current folder + target_include_directories(${unit_test_name} + PRIVATE + "${PROJECT_SOURCE_DIR}/test" + .) # To compile with C++14 target_compile_features(${unit_test_name} PRIVATE cxx_std_14) diff --git a/test/algorithms/CMakeLists.txt b/test/algorithms/CMakeLists.txt index 51d2e90f54..f1e59ad408 100644 --- a/test/algorithms/CMakeLists.txt +++ b/test/algorithms/CMakeLists.txt @@ -6,4 +6,8 @@ add_subdirectory(area) add_subdirectory(buffer) +add_subdirectory(detail) +add_subdirectory(overlay) +add_subdirectory(relate) add_subdirectory(set_operations) +add_subdirectory(within) diff --git a/test/algorithms/detail/CMakeLists.txt b/test/algorithms/detail/CMakeLists.txt new file mode 100644 index 0000000000..1dea5e5eec --- /dev/null +++ b/test/algorithms/detail/CMakeLists.txt @@ -0,0 +1,15 @@ +# Boost.Geometry +# Copyright (c) 2024 Barend Gehrels, Amsterdam, the Netherlands. +# Use, modification and distribution is subject to 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(item IN ITEMS + calculate_point_order + approximately_equals + partition + tupled_output + visit + ) + boost_geometry_add_unit_test("algorithms" ${item}) +endforeach() diff --git a/test/algorithms/detail/approximately_equals.cpp b/test/algorithms/detail/approximately_equals.cpp index 39e9ec39a1..0e004737c4 100644 --- a/test/algorithms/detail/approximately_equals.cpp +++ b/test/algorithms/detail/approximately_equals.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include template @@ -81,18 +83,29 @@ void test_all(E const multiplier, std::size_t expected_index) int test_main(int, char* []) { + constexpr bool has_long_double = sizeof(long double) > sizeof(double); + double m = 1000.0; - test_all>(m, 54); + if (BOOST_GEOMETRY_CONDITION(has_long_double)) + { + test_all>(m, 54); + } test_all>(m, 43); test_all>(m, 24); m *= 1000.0; - test_all>(m, 44); + if (BOOST_GEOMETRY_CONDITION(has_long_double)) + { + test_all>(m, 44); + } test_all>(m, 33); test_all>(m, 24); m *= 1000.0; - test_all>(m, 34); + if (BOOST_GEOMETRY_CONDITION(has_long_double)) + { + test_all>(m, 34); + } test_all>(m, 23); test_all>(m, 23); diff --git a/test/algorithms/overlay/CMakeLists.txt b/test/algorithms/overlay/CMakeLists.txt new file mode 100644 index 0000000000..362c5caf81 --- /dev/null +++ b/test/algorithms/overlay/CMakeLists.txt @@ -0,0 +1,38 @@ +# Boost.Geometry +# Copyright (c) 2024 Barend Gehrels, Amsterdam, the Netherlands. +# Use, modification and distribution is subject to 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) + +# Cartesian +foreach(item IN ITEMS + assemble + copy_segment_point + get_clusters + get_distance_measure + get_ring + get_turn_info + get_turns + get_turns_const + get_turns_areal_areal + get_turns_linear_areal + get_turns_linear_linear + overlay + sort_by_side_basic + sort_by_side + relative_order + select_rings + self_intersection_points + ) + boost_geometry_add_unit_test("algorithms" ${item}) +endforeach() + +# Spherical +foreach(item IN ITEMS + get_turns_areal_areal_sph + get_turns_linear_areal_sph + get_turns_linear_linear_sph + get_turns_linear_linear_geo + ) + boost_geometry_add_unit_test("algorithms" ${item}) +endforeach() diff --git a/test/algorithms/overlay/get_clusters.cpp b/test/algorithms/overlay/get_clusters.cpp index 5b9a3602fd..ccfb782e03 100644 --- a/test/algorithms/overlay/get_clusters.cpp +++ b/test/algorithms/overlay/get_clusters.cpp @@ -101,11 +101,14 @@ int test_main(int, char* []) test_get_clusters(); test_get_clusters(); - // These constant relate to the threshold in get_clusters.hpp, + // These constant relate to the (earlier) thresholds in get_clusters.hpp, // and the used floating point type. + // (thresholds are now replaced by common_approximately_equals_epsilon_multiplier) test_get_clusters_border_cases(1.0e-5); test_get_clusters_border_cases(1.0e-14); +#ifndef __APPLE__ test_get_clusters_border_cases(1.0e-17); +#endif return 0; } diff --git a/test/algorithms/relate/CMakeLists.txt b/test/algorithms/relate/CMakeLists.txt new file mode 100644 index 0000000000..3efbdbc4e7 --- /dev/null +++ b/test/algorithms/relate/CMakeLists.txt @@ -0,0 +1,25 @@ +# Boost.Geometry +# Copyright (c) 2024 Barend Gehrels, Amsterdam, the Netherlands. +# Use, modification and distribution is subject to 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) + +# Cartesian +foreach(item IN ITEMS + relate_const_custom + relate_areal_areal + relate_linear_areal + relate_linear_linear + relate_pointlike_geometry + ) + boost_geometry_add_unit_test("algorithms" ${item}) +endforeach() + +# Spherical +foreach(item IN ITEMS + relate_areal_areal_sph + relate_linear_areal_sph + relate_linear_linear_sph + ) + boost_geometry_add_unit_test("algorithms" ${item}) +endforeach() diff --git a/test/algorithms/within/CMakeLists.txt b/test/algorithms/within/CMakeLists.txt new file mode 100644 index 0000000000..d2e7bf33d6 --- /dev/null +++ b/test/algorithms/within/CMakeLists.txt @@ -0,0 +1,26 @@ +# Boost.Geometry +# Copyright (c) 2024 Barend Gehrels, Amsterdam, the Netherlands. +# Use, modification and distribution is subject to 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) + +# Cartesian +foreach(item IN ITEMS + within + within_areal_areal + within_gc + within_linear_areal + within_linear_linear + within_multi + within_pointlike_geometry + ) + boost_geometry_add_unit_test("algorithms" ${item}) +endforeach() + +# Spherical +foreach(item IN ITEMS + within_sph + within_sph_geo + ) + boost_geometry_add_unit_test("algorithms" ${item}) +endforeach()