assert.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
  4. // Copyright (c) 2015 Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #include <geometry_test_common.hpp>
  10. #define BOOST_GEOMETRY_ENABLE_ASSERT_HANDLER
  11. #include <boost/geometry/core/assert.hpp>
  12. struct assert_failure_exception
  13. : std::exception
  14. {
  15. const char * what() const throw()
  16. {
  17. return "assertion failure";
  18. }
  19. };
  20. namespace boost { namespace geometry {
  21. inline void assertion_failed(char const * /*expr*/, char const * /*function*/, char const * /*file*/, long /*line*/)
  22. {
  23. throw assert_failure_exception();
  24. }
  25. inline void assertion_failed_msg(char const * /*expr*/, char const * /*msg*/, char const * /*function*/, char const * /*file*/, long /*line*/)
  26. {
  27. throw assert_failure_exception();
  28. }
  29. }}
  30. void fun1(bool condition)
  31. {
  32. BOOST_GEOMETRY_ASSERT(condition);
  33. }
  34. void fun2(bool condition, const char* msg = "")
  35. {
  36. BOOST_GEOMETRY_ASSERT_MSG(condition, msg);
  37. }
  38. bool is_ok(assert_failure_exception const& ) { return true; }
  39. int test_main(int, char* [])
  40. {
  41. int a = 1;
  42. fun1(a == 1);
  43. BOOST_CHECK_EXCEPTION(fun1(a == 2), assert_failure_exception, is_ok);
  44. fun2(a == 1);
  45. BOOST_CHECK_EXCEPTION(fun2(a == 2), assert_failure_exception, is_ok);
  46. return 0;
  47. }