From 1b676201191663cd6225de4f37bc9ce00b63fdd4 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Mon, 25 May 2026 14:58:00 -0400 Subject: [PATCH 1/3] fix cmake test --- test/cmake_test/CMakeLists.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/cmake_test/CMakeLists.txt b/test/cmake_test/CMakeLists.txt index 2e878c4c..a8972d18 100644 --- a/test/cmake_test/CMakeLists.txt +++ b/test/cmake_test/CMakeLists.txt @@ -12,8 +12,18 @@ set(__ignore__ ${CMAKE_C_COMPILER}) set(__ignore__ ${CMAKE_C_FLAGS}) if(BOOST_CI_INSTALL_TEST) - # Boost as a package (https://github.com/boostorg/cmake#using-boost-after-building-and-installing-it-with-cmake) - find_package(Boost CONFIG REQUIRED COMPONENTS openmethod) +# Header-only libraries: + # B2 does not (yet) create/install CMake targets for them, so users are supposed to use the generic Boost::headers target + if(BOOST_CI_INSTALLED_BY STREQUAL "B2") + find_package(Boost REQUIRED) + add_library(_boost_openmethod INTERFACE) + target_link_libraries(_boost_openmethod INTERFACE Boost::headers) + target_compile_features(_boost_openmethod INTERFACE cxx_std_17) + add_library(Boost::openmethod ALIAS _boost_openmethod) + else() + # Boost as a package (https://github.com/boostorg/cmake#using-boost-after-building-and-installing-it-with-cmake) + find_package(Boost CONFIG REQUIRED COMPONENTS openmethod) + endif() elseif(BOOST_CI_INSTALL_MODULE_TEST) # Boost.OpenMethod as a package find_package(boost_openmethod CONFIG REQUIRED) From 2064e06601f7d35626855c82cb6033479a0ff03d Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Mon, 25 May 2026 19:30:43 -0400 Subject: [PATCH 2/3] fix GCC 16 false positive breaking unit test framework shared build Use off instead of off for the boost_unit_test_framework dependency. GCC 16 fires a spurious -Warray-bounds in Boost.Test's junit_log_formatter.hpp when compiling unit_test_log.cpp in shared-link mode; off does not suppress -Werror, so the .so fails to build. Same pattern used by Boost.Redis and Boost.MySQL. Co-Authored-By: Claude Sonnet 4.6 --- test/Jamfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Jamfile b/test/Jamfile index a4becf8c..d47276c7 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -30,7 +30,7 @@ project alias unit_test_framework : # sources - /boost/test//boost_unit_test_framework/off + /boost/test//boost_unit_test_framework/off ; for local src in [ glob test_*.cpp ] From 87afa9c92100765b60b02e831e8cafaf5157bfa7 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Tue, 26 May 2026 19:15:01 -0400 Subject: [PATCH 3/3] codecov --- test/mix_release_debug/lib.cpp | 4 -- test/test_rolex.cpp | 108 +++++++++++++++++++++++++++++---- 2 files changed, 96 insertions(+), 16 deletions(-) diff --git a/test/mix_release_debug/lib.cpp b/test/mix_release_debug/lib.cpp index 037ded2e..9d9c167e 100644 --- a/test/mix_release_debug/lib.cpp +++ b/test/mix_release_debug/lib.cpp @@ -16,7 +16,3 @@ using namespace boost::openmethod; BOOST_OPENMETHOD_CLASSES(Animal, Cat); - -BOOST_OPENMETHOD_OVERRIDE(poke, (virtual_ptr, std::ostream& os), void) { - os << "hiss"; -} diff --git a/test/test_rolex.cpp b/test/test_rolex.cpp index 36cc39d8..4a291e9f 100644 --- a/test/test_rolex.cpp +++ b/test/test_rolex.cpp @@ -6,11 +6,13 @@ #include #include +#define BOOST_TEST_MODULE test_rolex +#include + using boost::openmethod::virtual_ptr; struct Role { - virtual ~Role() { - } + virtual ~Role() {} }; struct Employee : Role { @@ -24,8 +26,7 @@ struct Manager : Employee { struct Founder : Role {}; struct Expense { - virtual ~Expense() { - } + virtual ~Expense() {} }; struct Public : Expense {}; @@ -39,6 +40,7 @@ BOOST_OPENMETHOD_CLASSES( PrivateJet); BOOST_OPENMETHOD(pay, (virtual_ptr), double); + BOOST_OPENMETHOD( approve, (virtual_ptr, virtual_ptr, double), bool); @@ -75,14 +77,6 @@ BOOST_OPENMETHOD_OVERRIDE( return true; } -auto main() -> int { - boost::openmethod::initialize(); -} - -auto call_pay(Employee& emp) -> double { - return pay(emp); -} - auto Employee::pay() -> double { return 3000; } @@ -91,6 +85,10 @@ auto Manager::pay() -> double { return Employee::pay() + 2000; } +auto call_pay(Employee& emp) -> double { + return pay(emp); +} + auto call_pay_vfunc(Employee& emp) -> double { return emp.pay(); } @@ -98,3 +96,89 @@ auto call_pay_vfunc(Employee& emp) -> double { auto call_approve(const Role& r, const Expense& e, double a) -> bool { return approve(r, e, a); } + +BOOST_AUTO_TEST_CASE(pay_employee) { + boost::openmethod::initialize(); + Employee e; + BOOST_TEST(pay(e) == 3000); + BOOST_TEST(call_pay(e) == 3000); + BOOST_TEST(call_pay_vfunc(e) == 3000); +} + +BOOST_AUTO_TEST_CASE(pay_manager_calls_next) { + boost::openmethod::initialize(); + Manager m; + BOOST_TEST(pay(m) == 5000); + BOOST_TEST(call_pay(m) == 5000); + BOOST_TEST(call_pay_vfunc(m) == 5000); +} + +BOOST_AUTO_TEST_CASE(approve_employee) { + boost::openmethod::initialize(); + Employee e; + Bus bus; + Metro metro; + Taxi taxi; + PrivateJet jet; + // Employee may take public transport + BOOST_TEST(approve(e, bus, 10) == true); + BOOST_TEST(approve(e, metro, 10) == true); + // Employee may not take taxi or private jet + BOOST_TEST(approve(e, taxi, 10) == false); + BOOST_TEST(approve(e, jet, 10) == false); +} + +BOOST_AUTO_TEST_CASE(approve_manager) { + boost::openmethod::initialize(); + Manager m; + Bus bus; + Metro metro; + Taxi taxi; + PrivateJet jet; + // Manager inherits employee's public transport approval + BOOST_TEST(approve(m, bus, 10) == true); + BOOST_TEST(approve(m, metro, 10) == true); + // Manager may also take a taxi + BOOST_TEST(approve(m, taxi, 10) == true); + // Manager may not take a private jet + BOOST_TEST(approve(m, jet, 10) == false); +} + +BOOST_AUTO_TEST_CASE(approve_founder) { + boost::openmethod::initialize(); + Founder f; + Bus bus; + Metro metro; + Taxi taxi; + PrivateJet jet; + // Founder approves all expenses + BOOST_TEST(approve(f, bus, 10) == true); + BOOST_TEST(approve(f, metro, 10) == true); + BOOST_TEST(approve(f, taxi, 10) == true); + BOOST_TEST(approve(f, jet, 10) == true); +} + +BOOST_AUTO_TEST_CASE(approve_base_role_denied) { + boost::openmethod::initialize(); + Role r; + Bus bus; + Taxi taxi; + PrivateJet jet; + // Base Role catches all — nothing approved + BOOST_TEST(approve(r, bus, 10) == false); + BOOST_TEST(approve(r, taxi, 10) == false); + BOOST_TEST(approve(r, jet, 10) == false); +} + +BOOST_AUTO_TEST_CASE(approve_via_wrapper) { + boost::openmethod::initialize(); + Employee e; + Manager m; + Founder f; + Bus bus; + Taxi taxi; + BOOST_TEST(call_approve(e, bus, 10) == true); + BOOST_TEST(call_approve(e, taxi, 10) == false); + BOOST_TEST(call_approve(m, taxi, 10) == true); + BOOST_TEST(call_approve(f, taxi, 10) == true); +}