throw_exception_test.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include <boost/container/detail/config_begin.hpp>
  12. #include <boost/container/throw_exception.hpp>
  13. #include <boost/core/lightweight_test.hpp>
  14. using namespace boost::container;
  15. static bool bad_alloc_called = false;
  16. static bool out_of_range_called = false;
  17. static bool length_error_called = false;
  18. static bool logic_error_called = false;
  19. static bool runtime_error_called = false;
  20. //User defined throw implementations
  21. namespace boost {
  22. namespace container {
  23. void throw_bad_alloc()
  24. { bad_alloc_called = true; }
  25. void throw_out_of_range(const char* str)
  26. { (void)str; out_of_range_called = true; }
  27. void throw_length_error(const char* str)
  28. { (void)str; length_error_called = true; }
  29. void throw_logic_error(const char* str)
  30. { (void)str; logic_error_called = true; }
  31. void throw_runtime_error(const char* str)
  32. { (void)str; runtime_error_called = true; }
  33. }} //boost::container
  34. int main()
  35. {
  36. //Check user-defined throw callbacks are called
  37. throw_bad_alloc();
  38. BOOST_TEST(bad_alloc_called == true);
  39. throw_out_of_range("dummy");
  40. BOOST_TEST(out_of_range_called == true);
  41. throw_length_error("dummy");
  42. BOOST_TEST(length_error_called == true);
  43. throw_logic_error("dummy");
  44. BOOST_TEST(logic_error_called == true);
  45. throw_runtime_error("dummy");
  46. BOOST_TEST(runtime_error_called == true);
  47. return ::boost::report_errors();
  48. }
  49. #include <boost/container/detail/config_end.hpp>