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