]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/assert/test/assert_msg_test2.cpp
2 // assert_msg_test2.cpp - a test for BOOST_ASSERT_MSG and NDEBUG
4 // Copyright (c) 2014 Peter Dimov
6 // Distributed under the Boost Software License, Version 1.0.
7 // See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt
11 #include <boost/detail/lightweight_test.hpp>
14 // default case, !NDEBUG
15 // BOOST_ASSERT_MSG(x) -> assert(x)
18 #include <boost/assert.hpp>
24 BOOST_ASSERT_MSG( 1, "msg" );
25 BOOST_ASSERT_MSG( x
, "msg" );
26 BOOST_ASSERT_MSG( x
== 1, "msg" );
29 // default case, NDEBUG
30 // BOOST_ASSERT_MSG(x) -> assert(x)
33 #include <boost/assert.hpp>
35 void test_default_ndebug()
39 BOOST_ASSERT_MSG( 1, "msg" );
40 BOOST_ASSERT_MSG( x
, "msg" );
41 BOOST_ASSERT_MSG( x
== 1, "msg" );
43 BOOST_ASSERT_MSG( 0, "msg" );
44 BOOST_ASSERT_MSG( !x
, "msg" );
45 BOOST_ASSERT_MSG( x
== 0, "msg" );
48 // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG
49 // same as BOOST_ENABLE_ASSERT_HANDLER
51 #define BOOST_ENABLE_ASSERT_DEBUG_HANDLER
54 #include <boost/assert.hpp>
56 int handler_invoked
= 0;
58 void boost::assertion_failed_msg( char const * expr
, char const * msg
, char const * function
, char const * file
, long line
)
60 printf( "Expression: %s\nMessage: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr
, msg
, function
, file
, line
);
64 void test_debug_handler()
70 BOOST_ASSERT_MSG( 1, "msg" );
71 BOOST_ASSERT_MSG( x
, "msg" );
72 BOOST_ASSERT_MSG( x
== 1, "msg" );
74 BOOST_ASSERT_MSG( 0, "msg" );
75 BOOST_ASSERT_MSG( !x
, "msg" );
76 BOOST_ASSERT_MSG( x
== 0, "msg" );
78 BOOST_TEST( handler_invoked
== 3 );
81 // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG
82 // BOOST_ASSERT_MSG(x) -> ((void)0)
85 #include <boost/assert.hpp>
87 void test_debug_handler_ndebug()
93 BOOST_ASSERT_MSG( 1, "msg" );
94 BOOST_ASSERT_MSG( x
, "msg" );
95 BOOST_ASSERT_MSG( x
== 1, "msg" );
97 BOOST_ASSERT_MSG( 0, "msg" );
98 BOOST_ASSERT_MSG( !x
, "msg" );
99 BOOST_ASSERT_MSG( x
== 0, "msg" );
101 BOOST_TEST( handler_invoked
== 0 );
104 #undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER
109 test_default_ndebug();
110 test_debug_handler();
111 test_debug_handler_ndebug();
113 return boost::report_errors();