annotate DEPENDENCIES/generic/include/boost/detail/lightweight_test.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
rev   line source
Chris@16 1 #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
Chris@16 2 #define BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
Chris@16 3
Chris@16 4 // MS compatible compilers support #pragma once
Chris@16 5
Chris@16 6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
Chris@16 7 # pragma once
Chris@16 8 #endif
Chris@16 9
Chris@16 10 //
Chris@16 11 // boost/detail/lightweight_test.hpp - lightweight test library
Chris@16 12 //
Chris@16 13 // Copyright (c) 2002, 2009 Peter Dimov
Chris@16 14 // Copyright (2) Beman Dawes 2010, 2011
Chris@16 15 // Copyright (3) Ion Gaztanaga 2013
Chris@16 16 //
Chris@16 17 // Distributed under the Boost Software License, Version 1.0.
Chris@16 18 // See accompanying file LICENSE_1_0.txt or copy at
Chris@16 19 // http://www.boost.org/LICENSE_1_0.txt
Chris@16 20 //
Chris@16 21 // ---------------
Chris@16 22 //
Chris@16 23 // If expression is false increases the error count
Chris@16 24 // and outputs a message containing 'expression'
Chris@16 25 //
Chris@16 26 // BOOST_TEST(expression)
Chris@16 27 //
Chris@16 28 // ---------------
Chris@16 29 //
Chris@16 30 // Increases error count and outputs a message containing 'message'
Chris@16 31 //
Chris@16 32 // BOOST_ERROR(message)
Chris@16 33 //
Chris@16 34 // ---------------
Chris@16 35 //
Chris@16 36 // If 'expr1' != 'expr2' increases the error count
Chris@16 37 // and outputs a message containing both expressions
Chris@16 38 //
Chris@16 39 // BOOST_TEST_EQ(expr1, expr2)
Chris@16 40 //
Chris@16 41 // ---------------
Chris@16 42 //
Chris@16 43 // If 'expr1' == 'expr2' increases the error count
Chris@16 44 // and outputs a message containing both expressions
Chris@16 45 //
Chris@16 46 // BOOST_TEST_NE(expr1, expr2)
Chris@16 47 //
Chris@16 48 // ---------------
Chris@16 49 //
Chris@16 50 // If BOOST_NO_EXCEPTIONS is NOT defined and if 'expr' does not
Chris@16 51 // throw an exception of type 'excep', increases the error count
Chris@16 52 // and outputs a message containing the expression.
Chris@16 53 //
Chris@16 54 // If BOOST_NO_EXCEPTIONS is defined, this macro expands to nothing
Chris@16 55 // and 'expr' is not evaluated.
Chris@16 56 //
Chris@16 57 // BOOST_TEST_THROWS(expr, excep)
Chris@16 58 //
Chris@16 59 // ---------------
Chris@16 60 //
Chris@16 61 // Returns the error count
Chris@16 62 //
Chris@16 63 // int boost::report_errors()
Chris@16 64 //
Chris@16 65
Chris@16 66 #include <iostream>
Chris@16 67 #include <boost/current_function.hpp>
Chris@16 68 #include <boost/assert.hpp>
Chris@16 69 #include <boost/detail/no_exceptions_support.hpp>
Chris@16 70
Chris@16 71 // IDE's like Visual Studio perform better if output goes to std::cout or
Chris@16 72 // some other stream, so allow user to configure output stream:
Chris@16 73 #ifndef BOOST_LIGHTWEIGHT_TEST_OSTREAM
Chris@16 74 # define BOOST_LIGHTWEIGHT_TEST_OSTREAM std::cerr
Chris@16 75 #endif
Chris@16 76
Chris@16 77 namespace boost
Chris@16 78 {
Chris@16 79
Chris@16 80 namespace detail
Chris@16 81 {
Chris@16 82
Chris@16 83 struct report_errors_reminder
Chris@16 84 {
Chris@16 85 bool called_report_errors_function;
Chris@16 86 report_errors_reminder() : called_report_errors_function(false) {}
Chris@16 87 ~report_errors_reminder()
Chris@16 88 {
Chris@16 89 BOOST_ASSERT(called_report_errors_function); // verify report_errors() was called
Chris@16 90 }
Chris@16 91 };
Chris@16 92
Chris@16 93 inline report_errors_reminder& report_errors_remind()
Chris@16 94 {
Chris@16 95 static report_errors_reminder r;
Chris@16 96 return r;
Chris@16 97 }
Chris@16 98
Chris@16 99 inline int & test_errors()
Chris@16 100 {
Chris@16 101 static int x = 0;
Chris@16 102 report_errors_remind();
Chris@16 103 return x;
Chris@16 104 }
Chris@16 105
Chris@16 106 inline void test_failed_impl(char const * expr, char const * file, int line, char const * function)
Chris@16 107 {
Chris@16 108 BOOST_LIGHTWEIGHT_TEST_OSTREAM
Chris@16 109 << file << "(" << line << "): test '" << expr << "' failed in function '"
Chris@16 110 << function << "'" << std::endl;
Chris@16 111 ++test_errors();
Chris@16 112 }
Chris@16 113
Chris@16 114 inline void error_impl(char const * msg, char const * file, int line, char const * function)
Chris@16 115 {
Chris@16 116 BOOST_LIGHTWEIGHT_TEST_OSTREAM
Chris@16 117 << file << "(" << line << "): " << msg << " in function '"
Chris@16 118 << function << "'" << std::endl;
Chris@16 119 ++test_errors();
Chris@16 120 }
Chris@16 121
Chris@16 122 inline void throw_failed_impl(char const * excep, char const * file, int line, char const * function)
Chris@16 123 {
Chris@16 124 BOOST_LIGHTWEIGHT_TEST_OSTREAM
Chris@16 125 << file << "(" << line << "): Exception '" << excep << "' not thrown in function '"
Chris@16 126 << function << "'" << std::endl;
Chris@16 127 ++test_errors();
Chris@16 128 }
Chris@16 129
Chris@16 130 template<class T, class U> inline void test_eq_impl( char const * expr1, char const * expr2,
Chris@16 131 char const * file, int line, char const * function, T const & t, U const & u )
Chris@16 132 {
Chris@16 133 if( t == u )
Chris@16 134 {
Chris@16 135 }
Chris@16 136 else
Chris@16 137 {
Chris@16 138 BOOST_LIGHTWEIGHT_TEST_OSTREAM
Chris@16 139 << file << "(" << line << "): test '" << expr1 << " == " << expr2
Chris@16 140 << "' failed in function '" << function << "': "
Chris@16 141 << "'" << t << "' != '" << u << "'" << std::endl;
Chris@16 142 ++test_errors();
Chris@16 143 }
Chris@16 144 }
Chris@16 145
Chris@16 146 template<class T, class U> inline void test_ne_impl( char const * expr1, char const * expr2,
Chris@16 147 char const * file, int line, char const * function, T const & t, U const & u )
Chris@16 148 {
Chris@16 149 if( t != u )
Chris@16 150 {
Chris@16 151 }
Chris@16 152 else
Chris@16 153 {
Chris@16 154 BOOST_LIGHTWEIGHT_TEST_OSTREAM
Chris@16 155 << file << "(" << line << "): test '" << expr1 << " != " << expr2
Chris@16 156 << "' failed in function '" << function << "': "
Chris@16 157 << "'" << t << "' == '" << u << "'" << std::endl;
Chris@16 158 ++test_errors();
Chris@16 159 }
Chris@16 160 }
Chris@16 161
Chris@16 162 } // namespace detail
Chris@16 163
Chris@16 164 inline int report_errors()
Chris@16 165 {
Chris@16 166 detail::report_errors_remind().called_report_errors_function = true;
Chris@16 167
Chris@16 168 int errors = detail::test_errors();
Chris@16 169
Chris@16 170 if( errors == 0 )
Chris@16 171 {
Chris@16 172 BOOST_LIGHTWEIGHT_TEST_OSTREAM
Chris@16 173 << "No errors detected." << std::endl;
Chris@16 174 return 0;
Chris@16 175 }
Chris@16 176 else
Chris@16 177 {
Chris@16 178 BOOST_LIGHTWEIGHT_TEST_OSTREAM
Chris@16 179 << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl;
Chris@16 180 return 1;
Chris@16 181 }
Chris@16 182 }
Chris@16 183
Chris@16 184 } // namespace boost
Chris@16 185
Chris@16 186 #define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
Chris@16 187 #define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
Chris@16 188 #define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
Chris@16 189 #define BOOST_TEST_NE(expr1,expr2) ( ::boost::detail::test_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
Chris@16 190 #ifndef BOOST_NO_EXCEPTIONS
Chris@16 191 #define BOOST_TEST_THROWS( EXPR, EXCEP ) \
Chris@16 192 try { \
Chris@16 193 EXPR; \
Chris@16 194 ::boost::detail::throw_failed_impl \
Chris@16 195 (#EXCEP, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); \
Chris@16 196 } \
Chris@16 197 catch(EXCEP const&) { \
Chris@16 198 } \
Chris@16 199 catch(...) { \
Chris@16 200 ::boost::detail::throw_failed_impl \
Chris@16 201 (#EXCEP, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); \
Chris@16 202 } \
Chris@16 203 //
Chris@16 204 #else
Chris@16 205 #define BOOST_TEST_THROWS( EXPR, EXCEP )
Chris@16 206 #endif
Chris@16 207
Chris@16 208 #endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED