sl@0: // (C) Copyright Gennadiy Rozental 2002-2005. sl@0: // Distributed under the Boost Software License, Version 1.0. sl@0: // (See accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: // See http://www.boost.org/libs/test for the library home page. sl@0: // sl@0: // File : $RCSfile: minimal.hpp,v $ sl@0: // sl@0: // Version : $Revision: 1.19 $ sl@0: // sl@0: // Description : simple minimal testing definitions and implementation sl@0: // *************************************************************************** sl@0: sl@0: #ifndef BOOST_TEST_MINIMAL_HPP_071894GER sl@0: #define BOOST_TEST_MINIMAL_HPP_071894GER sl@0: sl@0: #define BOOST_CHECK(exp) \ sl@0: ( (exp) \ sl@0: ? static_cast(0) \ sl@0: : boost::minimal_test::report_error(#exp,__FILE__,__LINE__, BOOST_CURRENT_FUNCTION) ) sl@0: sl@0: #define BOOST_REQUIRE(exp) \ sl@0: ( (exp) \ sl@0: ? static_cast(0) \ sl@0: : boost::minimal_test::report_critical_error(#exp,__FILE__,__LINE__,BOOST_CURRENT_FUNCTION)) sl@0: sl@0: #define BOOST_ERROR( msg_ ) \ sl@0: boost::minimal_test::report_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true ) sl@0: #define BOOST_FAIL( msg_ ) \ sl@0: boost::minimal_test::report_critical_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: // Boost.Test sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: // Boost sl@0: #include // for exit codes#include // for exit codes sl@0: #include // for BOOST_CURRENT_FUNCTION sl@0: sl@0: // STL sl@0: #include // std::cerr, std::endl sl@0: #include // std::string sl@0: sl@0: #include sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: int test_main( int argc, char* argv[] ); // prototype for users test_main() sl@0: sl@0: namespace boost { sl@0: namespace minimal_test { sl@0: sl@0: typedef boost::unit_test::const_string const_string; sl@0: sl@0: inline unit_test::counter_t& errors_counter() { static unit_test::counter_t ec = 0; return ec; } sl@0: sl@0: inline void sl@0: report_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false ) sl@0: { sl@0: ++errors_counter(); sl@0: std::cerr << file << "(" << line << "): "; sl@0: sl@0: if( is_msg ) sl@0: std::cerr << msg; sl@0: else sl@0: std::cerr << "test " << msg << " failed"; sl@0: sl@0: if( func_name != "(unknown)" ) sl@0: std::cerr << " in function: '" << func_name << "'"; sl@0: sl@0: std::cerr << std::endl; sl@0: } sl@0: sl@0: inline void sl@0: report_critical_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false ) sl@0: { sl@0: report_error( msg, file, line, func_name, is_msg ); sl@0: sl@0: throw boost::execution_aborted(); sl@0: } sl@0: sl@0: class caller { sl@0: public: sl@0: // constructor sl@0: caller( int argc, char** argv ) sl@0: : m_argc( argc ), m_argv( argv ) {} sl@0: sl@0: // execution monitor hook implementation sl@0: int operator()() { return test_main( m_argc, m_argv ); } sl@0: sl@0: private: sl@0: // Data members sl@0: int m_argc; sl@0: char** m_argv; sl@0: }; // monitor sl@0: sl@0: } // namespace minimal_test sl@0: sl@0: } // namespace boost sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: int BOOST_TEST_CALL_DECL main( int argc, char* argv[] ) sl@0: { sl@0: using namespace boost::minimal_test; sl@0: sl@0: try { sl@0: ::boost::execution_monitor ex_mon; sl@0: int run_result = ex_mon.execute( caller( argc, argv ) ); sl@0: sl@0: BOOST_CHECK( run_result == 0 || run_result == boost::exit_success ); sl@0: } sl@0: catch( boost::execution_exception const& exex ) { sl@0: if( exex.code() != boost::execution_exception::no_error ) sl@0: BOOST_ERROR( (std::string( "exception \"" ). sl@0: append( exex.what().begin(), exex.what().end() ). sl@0: append( "\" caught" ) ).c_str() ); sl@0: std::cerr << "\n**** Testing aborted."; sl@0: } sl@0: sl@0: if( boost::minimal_test::errors_counter() != 0 ) { sl@0: std::cerr << "\n**** " << errors_counter() sl@0: << " error" << (errors_counter() > 1 ? "s" : "" ) << " detected\n"; sl@0: sl@0: return boost::exit_test_failure; sl@0: } sl@0: sl@0: std::cout << "\n**** no errors detected\n"; sl@0: sl@0: return boost::exit_success; sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #include sl@0: sl@0: // *************************************************************************** sl@0: // Revision History : sl@0: // sl@0: // $Log: minimal.hpp,v $ sl@0: // Revision 1.19 2005/02/20 08:27:06 rogeeff sl@0: // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates sl@0: // sl@0: // Revision 1.18 2005/02/01 06:40:06 rogeeff sl@0: // copyright update sl@0: // old log entries removed sl@0: // minor stilistic changes sl@0: // depricated tools removed sl@0: // sl@0: // Revision 1.17 2005/01/31 07:50:05 rogeeff sl@0: // cdecl portability fix sl@0: // sl@0: // Revision 1.16 2005/01/31 06:01:27 rogeeff sl@0: // BOOST_TEST_CALL_DECL correctness fixes sl@0: // sl@0: // Revision 1.15 2005/01/22 19:22:12 rogeeff sl@0: // implementation moved into headers section to eliminate dependency of included/minimal component on src directory sl@0: // sl@0: // *************************************************************************** sl@0: sl@0: sl@0: #endif // BOOST_TEST_MINIMAL_HPP_071894GER