Brian Silverman | fad8f55 | 2018-08-04 23:36:19 -0700 | [diff] [blame^] | 1 | ////////////////////////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // (C) Copyright Ion Gaztanaga 2012-2013. Distributed under the Boost |
| 4 | // Software License, Version 1.0. (See accompanying file |
| 5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | // |
| 7 | // See http://www.boost.org/libs/container for documentation. |
| 8 | // |
| 9 | ////////////////////////////////////////////////////////////////////////////// |
| 10 | #define BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS |
| 11 | |
| 12 | #include <boost/container/detail/config_begin.hpp> |
| 13 | |
| 14 | #include <boost/container/throw_exception.hpp> |
| 15 | #include <boost/core/lightweight_test.hpp> |
| 16 | |
| 17 | using namespace boost::container; |
| 18 | |
| 19 | static bool bad_alloc_called = false; |
| 20 | static bool out_of_range_called = false; |
| 21 | static bool length_error_called = false; |
| 22 | static bool logic_error_called = false; |
| 23 | static bool runtime_error_called = false; |
| 24 | |
| 25 | //User defined throw implementations |
| 26 | namespace boost { |
| 27 | namespace container { |
| 28 | |
| 29 | void throw_bad_alloc() |
| 30 | { bad_alloc_called = true; } |
| 31 | |
| 32 | void throw_out_of_range(const char* str) |
| 33 | { (void)str; out_of_range_called = true; } |
| 34 | |
| 35 | void throw_length_error(const char* str) |
| 36 | { (void)str; length_error_called = true; } |
| 37 | |
| 38 | void throw_logic_error(const char* str) |
| 39 | { (void)str; logic_error_called = true; } |
| 40 | |
| 41 | void throw_runtime_error(const char* str) |
| 42 | { (void)str; runtime_error_called = true; } |
| 43 | |
| 44 | }} //boost::container |
| 45 | |
| 46 | int main() |
| 47 | { |
| 48 | //Check user-defined throw callbacks are called |
| 49 | throw_bad_alloc(); |
| 50 | BOOST_TEST(bad_alloc_called == true); |
| 51 | throw_out_of_range("dummy"); |
| 52 | BOOST_TEST(out_of_range_called == true); |
| 53 | throw_length_error("dummy"); |
| 54 | BOOST_TEST(length_error_called == true); |
| 55 | throw_logic_error("dummy"); |
| 56 | BOOST_TEST(logic_error_called == true); |
| 57 | throw_runtime_error("dummy"); |
| 58 | BOOST_TEST(runtime_error_called == true); |
| 59 | return ::boost::report_errors(); |
| 60 | } |
| 61 | |
| 62 | #include <boost/container/detail/config_end.hpp> |