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