1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
// 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)
#define BOOST_TEST_MODULE openmethod
#include <boost/test/unit_test.hpp>
#include <boost/openmethod.hpp>
#include <boost/openmethod/policies/throw_error_handler.hpp>
#include <boost/openmethod/initialize.hpp>
#include "test_util.hpp"
using namespace boost::openmethod;
struct Animal {
virtual ~Animal() {
}
};
struct Dog : Animal {};
struct Bulldog : Dog {};
namespace TEST_NS {
struct registry : test_registry_<__COUNTER__>::with<
policies::runtime_checks, policies::throw_error_handler> {
};
BOOST_OPENMETHOD(poke, (boost::openmethod::virtual_<Animal&>), void, registry);
BOOST_OPENMETHOD_OVERRIDE(poke, (Dog&), void) {
}
BOOST_OPENMETHOD_CLASSES(Animal, registry);
BOOST_AUTO_TEST_CASE(unknown_class_overrider) {
BOOST_CHECK_THROW(initialize<registry>(), missing_class);
}
} // namespace TEST_NS
namespace TEST_NS {
struct registry : test_registry_<__COUNTER__>::with<
policies::runtime_checks, policies::throw_error_handler> {
};
BOOST_OPENMETHOD(poke, (boost::openmethod::virtual_<Animal&>), void, registry);
BOOST_OPENMETHOD_OVERRIDE(poke, (Dog&), void) {
}
BOOST_OPENMETHOD_CLASSES(Animal, registry);
BOOST_OPENMETHOD_CLASSES(Dog, registry); // missing base class
BOOST_AUTO_TEST_CASE(missing_base_class) {
BOOST_CHECK_THROW(initialize<registry>(), missing_base);
}
} // namespace TEST_NS
namespace TEST_NS {
struct registry : test_registry_<__COUNTER__>::with<
policies::runtime_checks, policies::throw_error_handler> {
};
BOOST_OPENMETHOD(poke, (boost::openmethod::virtual_<Animal&>), void, registry);
BOOST_OPENMETHOD_OVERRIDE(poke, (Dog&), void) {
}
BOOST_OPENMETHOD_CLASSES(Animal, Dog, registry);
BOOST_AUTO_TEST_CASE(unknown_class_call) {
initialize<registry>();
Bulldog hector;
BOOST_CHECK_THROW(poke(hector), missing_class);
}
} // namespace TEST_NS
|