// Copyright (c) 2018-2025 Jean-Louis Leroy // 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 #include #include #include "test_util.hpp" #include #define BOOST_TEST_MODULE openmethod #include using namespace boost::openmethod; using namespace test_matrices; struct capture_output : policies::output { template struct fn { inline static std::ostringstream os; }; }; namespace not_initialized { struct registry : test_registry_<__COUNTER__, capture_output> { struct output { using error_handler = policy; output() { prev = error_handler::set( [this]( const policies::default_error_handler::error_variant& error) { prev(error); std::visit([](auto&& arg) { throw arg; }, error); }); } ~output() { error_handler::set(prev); policy::os.clear(); } auto operator()() const { return policy::os.str(); } policies::default_error_handler::function_type prev; }; }; BOOST_OPENMETHOD( transpose, (virtual_ptr), std::string, registry); BOOST_OPENMETHOD_OVERRIDE( transpose, (virtual_ptr), std::string) { return DIAGONAL; } BOOST_AUTO_TEST_CASE(not_initialized) { if constexpr (registry::runtime_checks) { // throw during virtual_ptr construction, because of hash table lookup { registry::output output; BOOST_CHECK_THROW( (unique_virtual_ptr{ std::make_unique()}), not_initialized_error); BOOST_TEST(output() == "not initialized\n"); } // throw during method call { registry::output output; BOOST_CHECK_THROW( transpose(make_unique_virtual()), not_initialized_error); } } else { try { registry::check_initialized(); } catch (not_initialized_error) { BOOST_TEST_FAIL("should have not thrown in release variant"); } } } } // namespace not_initialized