1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
//
// assert_exp_test.cpp - tests BOOST_ASSERT expansion
//
// Copyright (c) 2014 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#include <boost/config.hpp>
#include <boost/current_function.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <string>
// Each backslash in __FILE__ when passed through BOOST_STRINGIZE is doubled
static std::string quote( std::string const & s )
{
std::string r;
r.reserve( s.size() );
for( char const * p = s.c_str(); *p; ++p )
{
r += *p;
if( *p == '\\' ) r += *p;
}
return r;
}
// default case, !NDEBUG
// BOOST_ASSERT(x) -> assert(x)
#undef NDEBUG
#include <boost/assert.hpp>
#undef assert
void test_default()
{
std::string v1 = BOOST_STRINGIZE(BOOST_ASSERT(x1));
BOOST_TEST_EQ( v1, "assert(x1)" );
}
// default case, NDEBUG
// BOOST_ASSERT(x) -> assert(x)
#define NDEBUG
#include <boost/assert.hpp>
#undef assert
void test_default_ndebug()
{
std::string v2 = BOOST_STRINGIZE(BOOST_ASSERT(x2));
BOOST_TEST_EQ( v2, "assert(x2)" );
}
// BOOST_DISABLE_ASSERTS, !NDEBUG
// BOOST_ASSERT(x) -> ((void)0)
#define BOOST_DISABLE_ASSERTS
#undef NDEBUG
#include <boost/assert.hpp>
void test_disabled()
{
std::string v3 = BOOST_STRINGIZE(BOOST_ASSERT(x3));
BOOST_TEST_EQ( v3, "((void)0)" );
}
// BOOST_DISABLE_ASSERTS, NDEBUG
// BOOST_ASSERT(x) -> ((void)0)
#define NDEBUG
#include <boost/assert.hpp>
void test_disabled_ndebug()
{
std::string v4 = BOOST_STRINGIZE(BOOST_ASSERT(x4));
BOOST_TEST_EQ( v4, "((void)0)" );
}
#undef BOOST_DISABLE_ASSERTS
// BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG
// BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
#undef BOOST_LIKELY
#undef BOOST_CURRENT_FUNCTION
#define BOOST_ENABLE_ASSERT_HANDLER
#undef NDEBUG
#include <boost/assert.hpp>
void test_handler()
{
std::string v5 = BOOST_STRINGIZE(BOOST_ASSERT(x5)); std::string w5 = "(BOOST_LIKELY(!!(x5))? ((void)0): ::boost::assertion_failed(\"x5\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))";
char const * BOOST_CURRENT_FUNCTION = "void test_handler()";
BOOST_TEST_EQ( v5, w5 );
}
// BOOST_ENABLE_ASSERT_HANDLER, NDEBUG
// BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
#define NDEBUG
#include <boost/assert.hpp>
void test_handler_ndebug()
{
std::string v6 = BOOST_STRINGIZE(BOOST_ASSERT(x6)); std::string w6 = "(BOOST_LIKELY(!!(x6))? ((void)0): ::boost::assertion_failed(\"x6\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))";
char const * BOOST_CURRENT_FUNCTION = "void test_handler_ndebug()";
BOOST_TEST_EQ( v6, w6 );
}
#undef BOOST_ENABLE_ASSERT_HANDLER
// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG
// same as BOOST_ENABLE_ASSERT_HANDLER
#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER
#undef NDEBUG
#include <boost/assert.hpp>
void test_debug_handler()
{
std::string v7 = BOOST_STRINGIZE(BOOST_ASSERT(x7)); std::string w7 = "(BOOST_LIKELY(!!(x7))? ((void)0): ::boost::assertion_failed(\"x7\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))";
char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler()";
BOOST_TEST_EQ( v7, w7 );
}
// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG
// BOOST_ASSERT(x) -> ((void)0)
#define NDEBUG
#include <boost/assert.hpp>
void test_debug_handler_ndebug()
{
std::string v8 = BOOST_STRINGIZE(BOOST_ASSERT(x8));
char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler_ndebug()";
BOOST_TEST_EQ( v8, "((void)0)" );
}
#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER
int main()
{
test_default();
test_default_ndebug();
test_disabled();
test_disabled_ndebug();
test_handler();
test_handler_ndebug();
test_debug_handler();
test_debug_handler_ndebug();
return boost::report_errors();
}
|