Skip to content

Commit

Permalink
fix boost unit test framework in cmake and add cmake files
Browse files Browse the repository at this point in the history
  • Loading branch information
barendgehrels committed Jan 31, 2024
1 parent 3348c37 commit 77c019a
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 42 deletions.
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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})
Expand Down
44 changes: 12 additions & 32 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 15 additions & 0 deletions test/algorithms/detail/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 16 additions & 3 deletions test/algorithms/detail/approximately_equals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/util/condition.hpp>

#include <boost/geometry/io/wkt/wkt.hpp>

template <typename P>
Expand Down Expand Up @@ -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<bg::model::point<long double, 2, bg::cs::cartesian>>(m, 54);
if (BOOST_GEOMETRY_CONDITION(has_long_double))
{
test_all<bg::model::point<long double, 2, bg::cs::cartesian>>(m, 54);
}
test_all<bg::model::point<double, 2, bg::cs::cartesian>>(m, 43);
test_all<bg::model::point<float, 2, bg::cs::cartesian>>(m, 24);

m *= 1000.0;
test_all<bg::model::point<long double, 2, bg::cs::cartesian>>(m, 44);
if (BOOST_GEOMETRY_CONDITION(has_long_double))
{
test_all<bg::model::point<long double, 2, bg::cs::cartesian>>(m, 44);
}
test_all<bg::model::point<double, 2, bg::cs::cartesian>>(m, 33);
test_all<bg::model::point<float, 2, bg::cs::cartesian>>(m, 24);

m *= 1000.0;
test_all<bg::model::point<long double, 2, bg::cs::cartesian>>(m, 34);
if (BOOST_GEOMETRY_CONDITION(has_long_double))
{
test_all<bg::model::point<long double, 2, bg::cs::cartesian>>(m, 34);
}
test_all<bg::model::point<double, 2, bg::cs::cartesian>>(m, 23);
test_all<bg::model::point<float, 2, bg::cs::cartesian>>(m, 23);

Expand Down
38 changes: 38 additions & 0 deletions test/algorithms/overlay/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 4 additions & 1 deletion test/algorithms/overlay/get_clusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,14 @@ int test_main(int, char* [])
test_get_clusters<dp>();
test_get_clusters<ep>();

// 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<fp>(1.0e-5);
test_get_clusters_border_cases<dp>(1.0e-14);
#ifndef __APPLE__
test_get_clusters_border_cases<ep>(1.0e-17);
#endif

return 0;
}
25 changes: 25 additions & 0 deletions test/algorithms/relate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
26 changes: 26 additions & 0 deletions test/algorithms/within/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 77c019a

Please sign in to comment.