ossrv_pub/boost_apis/boost/test/minimal.hpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 //  (C) Copyright Gennadiy Rozental 2002-2005.
       
     2 //  Distributed under the Boost Software License, Version 1.0.
       
     3 //  (See accompanying file LICENSE_1_0.txt or copy at 
       
     4 //  http://www.boost.org/LICENSE_1_0.txt)
       
     5 
       
     6 //  See http://www.boost.org/libs/test for the library home page.
       
     7 //
       
     8 //  File        : $RCSfile: minimal.hpp,v $
       
     9 //
       
    10 //  Version     : $Revision: 1.19 $
       
    11 //
       
    12 //  Description : simple minimal testing definitions and implementation
       
    13 // ***************************************************************************
       
    14 
       
    15 #ifndef BOOST_TEST_MINIMAL_HPP_071894GER
       
    16 #define BOOST_TEST_MINIMAL_HPP_071894GER
       
    17 
       
    18 #define BOOST_CHECK(exp)       \
       
    19   ( (exp)                      \
       
    20       ? static_cast<void>(0)   \
       
    21       : boost::minimal_test::report_error(#exp,__FILE__,__LINE__, BOOST_CURRENT_FUNCTION) )
       
    22 
       
    23 #define BOOST_REQUIRE(exp)     \
       
    24   ( (exp)                      \
       
    25       ? static_cast<void>(0)   \
       
    26       : boost::minimal_test::report_critical_error(#exp,__FILE__,__LINE__,BOOST_CURRENT_FUNCTION))
       
    27 
       
    28 #define BOOST_ERROR( msg_ )    \
       
    29         boost::minimal_test::report_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true )
       
    30 #define BOOST_FAIL( msg_ )     \
       
    31         boost::minimal_test::report_critical_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true )
       
    32 
       
    33 //____________________________________________________________________________//
       
    34 
       
    35 // Boost.Test
       
    36 #include <boost/test/detail/global_typedef.hpp>
       
    37 #include <boost/test/impl/execution_monitor.ipp>
       
    38 #include <boost/test/utils/class_properties.hpp>
       
    39 #include <boost/test/utils/basic_cstring/io.hpp>
       
    40 
       
    41 // Boost
       
    42 #include <boost/cstdlib.hpp>            // for exit codes#include <boost/cstdlib.hpp>            // for exit codes
       
    43 #include <boost/current_function.hpp>   // for BOOST_CURRENT_FUNCTION
       
    44 
       
    45 // STL
       
    46 #include <iostream>                     // std::cerr, std::endl
       
    47 #include <string>                       // std::string
       
    48 
       
    49 #include <boost/test/detail/suppress_warnings.hpp>
       
    50 
       
    51 //____________________________________________________________________________//
       
    52 
       
    53 int test_main( int argc, char* argv[] );  // prototype for users test_main()
       
    54 
       
    55 namespace boost {
       
    56 namespace minimal_test {
       
    57 
       
    58 typedef boost::unit_test::const_string const_string;
       
    59 
       
    60 inline unit_test::counter_t& errors_counter() { static unit_test::counter_t ec = 0; return ec; }
       
    61 
       
    62 inline void
       
    63 report_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false )
       
    64 {
       
    65     ++errors_counter();
       
    66     std::cerr << file << "(" << line << "): ";
       
    67 
       
    68     if( is_msg )
       
    69         std::cerr << msg;
       
    70     else
       
    71         std::cerr << "test " << msg << " failed";
       
    72 
       
    73     if( func_name != "(unknown)" )
       
    74         std::cerr << " in function: '" << func_name << "'";
       
    75 
       
    76     std::cerr << std::endl;
       
    77 }
       
    78 
       
    79 inline void
       
    80 report_critical_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false )
       
    81 {
       
    82     report_error( msg, file, line, func_name, is_msg );
       
    83 
       
    84     throw boost::execution_aborted();
       
    85 }
       
    86 
       
    87 class caller {
       
    88 public:
       
    89     // constructor
       
    90     caller( int argc, char** argv )
       
    91     : m_argc( argc ), m_argv( argv ) {}
       
    92 
       
    93     // execution monitor hook implementation
       
    94     int operator()() { return test_main( m_argc, m_argv ); }
       
    95 
       
    96 private:
       
    97     // Data members
       
    98     int         m_argc;
       
    99     char**      m_argv;
       
   100 }; // monitor
       
   101 
       
   102 } // namespace minimal_test
       
   103 
       
   104 } // namespace boost
       
   105 
       
   106 //____________________________________________________________________________//
       
   107 
       
   108 int BOOST_TEST_CALL_DECL main( int argc, char* argv[] )
       
   109 {
       
   110     using namespace boost::minimal_test;
       
   111 
       
   112     try {
       
   113         ::boost::execution_monitor ex_mon;
       
   114         int run_result = ex_mon.execute( caller( argc, argv ) );
       
   115 
       
   116         BOOST_CHECK( run_result == 0 || run_result == boost::exit_success );
       
   117     }
       
   118     catch( boost::execution_exception const& exex ) {
       
   119         if( exex.code() != boost::execution_exception::no_error )
       
   120             BOOST_ERROR( (std::string( "exception \"" ).
       
   121                             append( exex.what().begin(), exex.what().end() ).
       
   122                             append( "\" caught" ) ).c_str() );
       
   123         std::cerr << "\n**** Testing aborted.";
       
   124     }
       
   125 
       
   126     if( boost::minimal_test::errors_counter() != 0 ) {
       
   127         std::cerr << "\n**** " << errors_counter()
       
   128                   << " error" << (errors_counter() > 1 ? "s" : "" ) << " detected\n";
       
   129 
       
   130         return boost::exit_test_failure;
       
   131     }
       
   132 
       
   133     std::cout << "\n**** no errors detected\n";
       
   134     
       
   135     return boost::exit_success;
       
   136 }
       
   137 
       
   138 //____________________________________________________________________________//
       
   139 
       
   140 #include <boost/test/detail/enable_warnings.hpp>
       
   141 
       
   142 // ***************************************************************************
       
   143 //  Revision History :
       
   144 //  
       
   145 //  $Log: minimal.hpp,v $
       
   146 //  Revision 1.19  2005/02/20 08:27:06  rogeeff
       
   147 //  This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
       
   148 //
       
   149 //  Revision 1.18  2005/02/01 06:40:06  rogeeff
       
   150 //  copyright update
       
   151 //  old log entries removed
       
   152 //  minor stilistic changes
       
   153 //  depricated tools removed
       
   154 //
       
   155 //  Revision 1.17  2005/01/31 07:50:05  rogeeff
       
   156 //  cdecl portability fix
       
   157 //
       
   158 //  Revision 1.16  2005/01/31 06:01:27  rogeeff
       
   159 //  BOOST_TEST_CALL_DECL correctness fixes
       
   160 //
       
   161 //  Revision 1.15  2005/01/22 19:22:12  rogeeff
       
   162 //  implementation moved into headers section to eliminate dependency of included/minimal component on src directory
       
   163 //
       
   164 // ***************************************************************************
       
   165 
       
   166 
       
   167 #endif // BOOST_TEST_MINIMAL_HPP_071894GER