Go to the documentation of this file.00001 #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
00002 #define BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
00003
00004
00005
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <boost/current_function.hpp>
00027 #include <iostream>
00028
00029 namespace boost
00030 {
00031
00032 namespace detail
00033 {
00034
00035 inline int & test_errors()
00036 {
00037 static int x = 0;
00038 return x;
00039 }
00040
00041 inline void test_failed_impl(char const * expr, char const * file, int line, char const * function)
00042 {
00043 std::cerr << file << "(" << line << "): test '" << expr << "' failed in function '" << function << "'" << std::endl;
00044 ++test_errors();
00045 }
00046
00047 inline void error_impl(char const * msg, char const * file, int line, char const * function)
00048 {
00049 std::cerr << file << "(" << line << "): " << msg << " in function '" << function << "'" << std::endl;
00050 ++test_errors();
00051 }
00052
00053 template<class T, class U> inline void test_eq_impl( char const * expr1, char const * expr2, char const * file, int line, char const * function, T const & t, U const & u )
00054 {
00055 if( t == u )
00056 {
00057 }
00058 else
00059 {
00060 std::cerr << file << "(" << line << "): test '" << expr1 << " == " << expr2
00061 << "' failed in function '" << function << "': "
00062 << "'" << t << "' != '" << u << "'" << std::endl;
00063 ++test_errors();
00064 }
00065 }
00066
00067 }
00068
00069 inline int report_errors()
00070 {
00071 int errors = detail::test_errors();
00072
00073 if( errors == 0 )
00074 {
00075 std::cerr << "No errors detected." << std::endl;
00076 return 0;
00077 }
00078 else
00079 {
00080 std::cerr << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl;
00081 return 1;
00082 }
00083 }
00084
00085 }
00086
00087 #define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
00088 #define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
00089 #define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
00090
00091 #endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED