blob: 2cbabefcc6f394fd38b04833ed1ba3882418b1b9 [file] [log] [blame]
Brian Silvermanfad8f552018-08-04 23:36:19 -07001//////////////////////////////////////////////////////////////////////////////
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
17using namespace boost::container;
18
19static bool bad_alloc_called = false;
20static bool out_of_range_called = false;
21static bool length_error_called = false;
22static bool logic_error_called = false;
23static bool runtime_error_called = false;
24
25//User defined throw implementations
26namespace boost {
27namespace 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
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>