Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:00:58

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  (C) Copyright Beman Dawes 1995-2001.
0003 //  Distributed under the Boost Software License, Version 1.0.
0004 //  (See accompanying file LICENSE_1_0.txt or copy at
0005 //  http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 //  See http://www.boost.org/libs/test for the library home page.
0008 //
0009 //  File        : $RCSfile$
0010 //
0011 //  Version     : $Revision$
0012 //
0013 //  Description : main function implementation for Program Executon Monitor
0014 // ***************************************************************************
0015 
0016 #ifndef BOOST_TEST_CPP_MAIN_IPP_012205GER
0017 #define BOOST_TEST_CPP_MAIN_IPP_012205GER
0018 
0019 // Boost.Test
0020 #include <boost/test/execution_monitor.hpp>
0021 #include <boost/test/detail/config.hpp>
0022 #include <boost/test/utils/basic_cstring/io.hpp>
0023 
0024 // Boost
0025 #include <boost/cstdlib.hpp>    // for exit codes
0026 #include <boost/config.hpp>     // for workarounds
0027 
0028 // STL
0029 #include <iostream>
0030 #include <cstdlib>      // std::getenv
0031 #include <cstring>      // std::strerror
0032 
0033 #include <boost/test/detail/suppress_warnings.hpp>
0034 
0035 //____________________________________________________________________________//
0036 
0037 #ifdef BOOST_NO_STDC_NAMESPACE
0038 namespace std { using ::getenv; using ::strerror; }
0039 #endif
0040 
0041 namespace {
0042 
0043 struct cpp_main_caller {
0044     cpp_main_caller( int (*cpp_main_func)( int argc, char* argv[] ), int argc, char** argv )
0045     : m_cpp_main_func( cpp_main_func )
0046     , m_argc( argc )
0047     , m_argv( argv ) {}
0048 
0049     int     operator()() { return (*m_cpp_main_func)( m_argc, m_argv ); }
0050 
0051 private:
0052     // Data members
0053     int     (*m_cpp_main_func)( int argc, char* argv[] );
0054     int     m_argc;
0055     char**  m_argv;
0056 };
0057 
0058 } // local namespace
0059 
0060 // ************************************************************************** //
0061 // **************             prg_exec_monitor_main            ************** //
0062 // ************************************************************************** //
0063 
0064 namespace boost {
0065 
0066 int BOOST_TEST_DECL
0067 prg_exec_monitor_main( int (*cpp_main)( int argc, char* argv[] ), int argc, char* argv[] )
0068 {
0069     int result = 0;
0070 
0071     BOOST_TEST_I_TRY {
0072         boost::unit_test::const_string p( std::getenv( "BOOST_TEST_CATCH_SYSTEM_ERRORS" ) );
0073         ::boost::execution_monitor ex_mon;
0074 
0075         ex_mon.p_catch_system_errors.value = p != "no";
0076 
0077         result = ex_mon.execute( cpp_main_caller( cpp_main, argc, argv ) );
0078 
0079         if( result == 0 )
0080             result = ::boost::exit_success;
0081         else if( result != ::boost::exit_success ) {
0082             std::cout << "\n**** error return code: " << result << std::endl;
0083             result = ::boost::exit_failure;
0084         }
0085     }
0086     BOOST_TEST_I_CATCH( ::boost::execution_exception, exex ) {
0087         std::cout << "\n**** exception(" << exex.code() << "): " << exex.what() << std::endl;
0088         result = ::boost::exit_exception_failure;
0089     }
0090     BOOST_TEST_I_CATCH( ::boost::system_error, ex ) {
0091         std::cout << "\n**** failed to initialize execution monitor."
0092                   << "\n**** expression at fault: " << ex.p_failed_exp
0093                   << "\n**** error(" << ex.p_errno << "): " << std::strerror( ex.p_errno ) << std::endl;
0094         result = ::boost::exit_exception_failure;
0095     }
0096 
0097     if( result != ::boost::exit_success ) {
0098         std::cerr << "******** errors detected; see standard output for details ********" << std::endl;
0099     }
0100     else {
0101         //  Some prefer a confirming message when all is well, while others don't
0102         //  like the clutter.  Use an environment variable to avoid command
0103         //  line argument modifications; for use in production programs
0104         //  that's a no-no in some organizations.
0105         ::boost::unit_test::const_string p( std::getenv( "BOOST_PRG_MON_CONFIRM" ) );
0106         if( p != "no" ) {
0107             std::cerr << std::flush << "no errors detected" << std::endl;
0108         }
0109     }
0110 
0111     return result;
0112 }
0113 
0114 } // namespace boost
0115 
0116 #if !defined(BOOST_TEST_DYN_LINK) && !defined(BOOST_TEST_NO_MAIN)
0117 
0118 // ************************************************************************** //
0119 // **************        main function for tests using lib     ************** //
0120 // ************************************************************************** //
0121 
0122 int cpp_main( int argc, char* argv[] );  // prototype for user's cpp_main()
0123 
0124 int BOOST_TEST_CALL_DECL
0125 main( int argc, char* argv[] )
0126 {
0127     return ::boost::prg_exec_monitor_main( &cpp_main, argc, argv );
0128 }
0129 
0130 //____________________________________________________________________________//
0131 
0132 #endif // !BOOST_TEST_DYN_LINK && !BOOST_TEST_NO_MAIN
0133 
0134 #include <boost/test/detail/enable_warnings.hpp>
0135 
0136 #endif // BOOST_TEST_CPP_MAIN_IPP_012205GER