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 throw_bad_alloc()29 void throw_bad_alloc() 30 { bad_alloc_called = true; } 31 throw_out_of_range(const char * str)32 void throw_out_of_range(const char* str) 33 { (void)str; out_of_range_called = true; } 34 throw_length_error(const char * str)35 void throw_length_error(const char* str) 36 { (void)str; length_error_called = true; } 37 throw_logic_error(const char * str)38 void throw_logic_error(const char* str) 39 { (void)str; logic_error_called = true; } 40 throw_runtime_error(const char * str)41 void throw_runtime_error(const char* str) 42 { (void)str; runtime_error_called = true; } 43 44 }} //boost::container 45 main()46int 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> 63