Brian Silverman | ea861c1 | 2018-08-04 17:43:02 -0700 | [diff] [blame^] | 1 | // |
| 2 | // verify_exp_test.cpp - tests BOOST_ASSERT expansion |
| 3 | // |
| 4 | // Copyright (c) 2014 Peter Dimov |
| 5 | // |
| 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 |
| 9 | // |
| 10 | |
| 11 | #include <boost/config.hpp> |
| 12 | #include <boost/current_function.hpp> |
| 13 | #include <boost/detail/lightweight_test.hpp> |
| 14 | #include <string> |
| 15 | |
| 16 | // default case, !NDEBUG |
| 17 | // BOOST_VERIFY(x) -> BOOST_ASSERT(x) |
| 18 | |
| 19 | #undef NDEBUG |
| 20 | #include <boost/assert.hpp> |
| 21 | #undef BOOST_ASSERT |
| 22 | |
| 23 | void test_default() |
| 24 | { |
| 25 | std::string v1 = BOOST_STRINGIZE(BOOST_VERIFY(x1)); |
| 26 | BOOST_TEST_EQ( v1, "BOOST_ASSERT(x1)" ); |
| 27 | } |
| 28 | |
| 29 | // default case, NDEBUG |
| 30 | // BOOST_VERIFY(x) -> ((void)(x)) |
| 31 | |
| 32 | #define NDEBUG |
| 33 | #include <boost/assert.hpp> |
| 34 | |
| 35 | void test_default_ndebug() |
| 36 | { |
| 37 | std::string v2 = BOOST_STRINGIZE(BOOST_VERIFY(x2)); |
| 38 | BOOST_TEST_EQ( v2, "((void)(x2))" ); |
| 39 | } |
| 40 | |
| 41 | // BOOST_DISABLE_ASSERTS, !NDEBUG |
| 42 | // BOOST_VERIFY(x) -> ((void)(x)) |
| 43 | |
| 44 | #define BOOST_DISABLE_ASSERTS |
| 45 | #undef NDEBUG |
| 46 | #include <boost/assert.hpp> |
| 47 | |
| 48 | void test_disabled() |
| 49 | { |
| 50 | std::string v3 = BOOST_STRINGIZE(BOOST_VERIFY(x3)); |
| 51 | BOOST_TEST_EQ( v3, "((void)(x3))" ); |
| 52 | } |
| 53 | |
| 54 | // BOOST_DISABLE_ASSERTS, NDEBUG |
| 55 | // BOOST_VERIFY(x) -> ((void)(x)) |
| 56 | |
| 57 | #undef NDEBUG |
| 58 | #include <boost/assert.hpp> |
| 59 | |
| 60 | void test_disabled_ndebug() |
| 61 | { |
| 62 | std::string v4 = BOOST_STRINGIZE(BOOST_VERIFY(x4)); |
| 63 | BOOST_TEST_EQ( v4, "((void)(x4))" ); |
| 64 | } |
| 65 | |
| 66 | #undef BOOST_DISABLE_ASSERTS |
| 67 | |
| 68 | // BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG |
| 69 | // BOOST_VERIFY(x) -> BOOST_ASSERT(x) |
| 70 | |
| 71 | #define BOOST_ENABLE_ASSERT_HANDLER |
| 72 | |
| 73 | #undef NDEBUG |
| 74 | #include <boost/assert.hpp> |
| 75 | #undef BOOST_ASSERT |
| 76 | |
| 77 | void test_handler() |
| 78 | { |
| 79 | std::string v5 = BOOST_STRINGIZE(BOOST_VERIFY(x5)); |
| 80 | BOOST_TEST_EQ( v5, "BOOST_ASSERT(x5)" ); |
| 81 | } |
| 82 | |
| 83 | #define NDEBUG |
| 84 | #include <boost/assert.hpp> |
| 85 | #undef BOOST_ASSERT |
| 86 | |
| 87 | void test_handler_ndebug() |
| 88 | { |
| 89 | std::string v6 = BOOST_STRINGIZE(BOOST_VERIFY(x6)); |
| 90 | BOOST_TEST_EQ( v6, "BOOST_ASSERT(x6)" ); |
| 91 | } |
| 92 | |
| 93 | #undef BOOST_ENABLE_ASSERT_HANDLER |
| 94 | |
| 95 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG |
| 96 | // BOOST_VERIFY(x) -> BOOST_ASSERT(x) |
| 97 | |
| 98 | #define BOOST_ENABLE_ASSERT_DEBUG_HANDLER |
| 99 | |
| 100 | #undef NDEBUG |
| 101 | #include <boost/assert.hpp> |
| 102 | #undef BOOST_ASSERT |
| 103 | |
| 104 | void test_debug_handler() |
| 105 | { |
| 106 | std::string v7 = BOOST_STRINGIZE(BOOST_VERIFY(x7)); |
| 107 | BOOST_TEST_EQ( v7, "BOOST_ASSERT(x7)" ); |
| 108 | } |
| 109 | |
| 110 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG |
| 111 | // BOOST_VERIFY(x) -> ((void)(x)) |
| 112 | |
| 113 | #define NDEBUG |
| 114 | #include <boost/assert.hpp> |
| 115 | |
| 116 | void test_debug_handler_ndebug() |
| 117 | { |
| 118 | std::string v8 = BOOST_STRINGIZE(BOOST_VERIFY(x8)); |
| 119 | BOOST_TEST_EQ( v8, "((void)(x8))" ); |
| 120 | } |
| 121 | |
| 122 | #undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER |
| 123 | |
| 124 | int main() |
| 125 | { |
| 126 | test_default(); |
| 127 | test_default_ndebug(); |
| 128 | test_disabled(); |
| 129 | test_disabled_ndebug(); |
| 130 | test_handler(); |
| 131 | test_handler_ndebug(); |
| 132 | test_debug_handler(); |
| 133 | test_debug_handler_ndebug(); |
| 134 | |
| 135 | return boost::report_errors(); |
| 136 | } |