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 Peter Dimov and Multi Media Ltd.
00014 //
00015 // Distributed under the Boost Software License, Version 1.0. (See
00016 // 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 //
00022 //  int boost::report_errors()
00023 //
00024 
00025 #include <sysc/packages/boost/current_function.hpp>
00026 #include <iostream>
00027 
00028 namespace boost
00029 {
00030 
00031 namespace detail
00032 {
00033 
00034 inline int & test_errors()
00035 {
00036     static int x = 0;
00037     return x;
00038 }
00039 
00040 inline void test_failed_impl(char const * expr, char const * file, int line, char const * function)
00041 {
00042     std::cerr << file << "(" << line << "): test '" << expr << "' failed in function '" << function << "'" << std::endl;
00043     ++test_errors();
00044 }
00045 
00046 inline void error_impl(char const * msg, char const * file, int line, char const * function)
00047 {
00048     std::cerr << file << "(" << line << "): " << msg << " in function '" << function << "'" << std::endl;
00049     ++test_errors();
00050 }
00051 
00052 } // namespace detail
00053 
00054 inline int report_errors()
00055 {
00056     int errors = detail::test_errors();
00057 
00058     if(errors == 0)
00059     {
00060         std::cerr << "No errors detected." << std::endl;
00061         return 0;
00062     }
00063     else
00064     {
00065         std::cerr << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl;
00066         return 1;
00067     }
00068 }
00069 
00070 } // namespace boost
00071 
00072 #define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
00073 #define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
00074 
00075 #endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED

Generated on Wed Jan 21 15:32:09 2009 for SystemC by  doxygen 1.5.5