lightweight_test.hpp
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 // MS compatible compilers support #pragma once
00005 
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009 
00010 //
00011 //  boost/detail/lightweight_test.hpp - lightweight test library
00012 //
00013 //  Copyright (c) 2002, 2009 Peter Dimov
00014 //
00015 //  Distributed under the Boost Software License, Version 1.0.
00016 //  See accompanying file LICENSE_1_0.txt or copy at
00017 //  http://www.boost.org/LICENSE_1_0.txt
00018 //
00019 //  BOOST_TEST(expression)
00020 //  BOOST_ERROR(message)
00021 //  BOOST_TEST_EQ(expr1, expr2)
00022 //
00023 //  int boost::report_errors()
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 } // namespace detail
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 } // namespace boost
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


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29