1 | // (C) Copyright Gennadiy Rozental 2001-2005. |
---|
2 | // (C) Copyright Beman Dawes 1995-2001. |
---|
3 | // Distributed under the Boost Software License, Version 1.0. |
---|
4 | // (See accompanying file LICENSE_1_0.txt or copy at |
---|
5 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
6 | |
---|
7 | // See http://www.boost.org/libs/test for the library home page. |
---|
8 | // |
---|
9 | // File : $RCSfile: cpp_main.ipp,v $ |
---|
10 | // |
---|
11 | // Version : $Revision: 1.7 $ |
---|
12 | // |
---|
13 | // Description : main function implementation for Program Executon Monitor |
---|
14 | // *************************************************************************** |
---|
15 | |
---|
16 | #ifndef BOOST_TEST_CPP_MAIN_IPP_012205GER |
---|
17 | #define BOOST_TEST_CPP_MAIN_IPP_012205GER |
---|
18 | |
---|
19 | // Boost.Test |
---|
20 | #include <boost/test/execution_monitor.hpp> |
---|
21 | #include <boost/test/detail/config.hpp> |
---|
22 | #include <boost/test/utils/basic_cstring/io.hpp> |
---|
23 | |
---|
24 | // Boost |
---|
25 | #include <boost/cstdlib.hpp> // for exit codes |
---|
26 | #include <boost/config.hpp> // for workarounds |
---|
27 | |
---|
28 | // STL |
---|
29 | #include <iostream> |
---|
30 | #include <cstdlib> // std::getenv |
---|
31 | |
---|
32 | #include <boost/test/detail/suppress_warnings.hpp> |
---|
33 | |
---|
34 | #include <boost/test/detail/suppress_warnings.hpp> |
---|
35 | |
---|
36 | //____________________________________________________________________________// |
---|
37 | |
---|
38 | #ifdef BOOST_NO_STDC_NAMESPACE |
---|
39 | namespace std { using ::getenv; } |
---|
40 | #endif |
---|
41 | |
---|
42 | namespace { |
---|
43 | |
---|
44 | struct cpp_main_caller { |
---|
45 | cpp_main_caller( int (*cpp_main_func)( int argc, char* argv[] ), int argc, char** argv ) |
---|
46 | : m_cpp_main_func( cpp_main_func ) |
---|
47 | , m_argc( argc ) |
---|
48 | , m_argv( argv ) {} |
---|
49 | |
---|
50 | int operator()() { return (*m_cpp_main_func)( m_argc, m_argv ); } |
---|
51 | |
---|
52 | private: |
---|
53 | // Data members |
---|
54 | int (*m_cpp_main_func)( int argc, char* argv[] ); |
---|
55 | int m_argc; |
---|
56 | char** m_argv; |
---|
57 | }; |
---|
58 | |
---|
59 | } // local namespace |
---|
60 | |
---|
61 | // ************************************************************************** // |
---|
62 | // ************** prg_exec_monitor_main ************** // |
---|
63 | // ************************************************************************** // |
---|
64 | |
---|
65 | namespace boost { |
---|
66 | |
---|
67 | int BOOST_TEST_DECL |
---|
68 | prg_exec_monitor_main( int (*cpp_main)( int argc, char* argv[] ), int argc, char* argv[] ) |
---|
69 | { |
---|
70 | int result; |
---|
71 | |
---|
72 | boost::unit_test::const_string p( std::getenv( "BOOST_TEST_CATCH_SYSTEM_ERRORS" ) ); |
---|
73 | bool catch_system_errors = p != "no"; |
---|
74 | |
---|
75 | try { |
---|
76 | ::boost::execution_monitor ex_mon; |
---|
77 | result = ex_mon.execute( |
---|
78 | ::boost::unit_test::callback0<int>( cpp_main_caller( cpp_main, argc, argv ) ), catch_system_errors ); |
---|
79 | |
---|
80 | if( result == 0 ) |
---|
81 | result = ::boost::exit_success; |
---|
82 | else if( result != ::boost::exit_success ) { |
---|
83 | std::cout << "\n**** error return code: " << result << std::endl; |
---|
84 | result = ::boost::exit_failure; |
---|
85 | } |
---|
86 | } |
---|
87 | catch( ::boost::execution_exception const& exex ) { |
---|
88 | std::cout << "\n**** exception(" << exex.code() << "): " << exex.what() << std::endl; |
---|
89 | result = ::boost::exit_exception_failure; |
---|
90 | } |
---|
91 | |
---|
92 | if( result != ::boost::exit_success ) { |
---|
93 | std::cerr << "******** errors detected; see standard output for details ********" << std::endl; |
---|
94 | } |
---|
95 | else { |
---|
96 | // Some prefer a confirming message when all is well, while others don't |
---|
97 | // like the clutter. Use an environment variable to avoid command |
---|
98 | // line argument modifications; for use in production programs |
---|
99 | // that's a no-no in some organizations. |
---|
100 | ::boost::unit_test::const_string p( std::getenv( "BOOST_PRG_MON_CONFIRM" ) ); |
---|
101 | if( p != "no" ) { |
---|
102 | std::cerr << std::flush << "no errors detected" << std::endl; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | return result; |
---|
107 | } |
---|
108 | |
---|
109 | } // namespace boost |
---|
110 | |
---|
111 | #if !defined(BOOST_TEST_DYN_LINK) && !defined(BOOST_TEST_NO_MAIN) |
---|
112 | |
---|
113 | // ************************************************************************** // |
---|
114 | // ************** main function for tests using lib ************** // |
---|
115 | // ************************************************************************** // |
---|
116 | |
---|
117 | int cpp_main( int argc, char* argv[] ); // prototype for user's cpp_main() |
---|
118 | |
---|
119 | int BOOST_TEST_CALL_DECL |
---|
120 | main( int argc, char* argv[] ) |
---|
121 | { |
---|
122 | return ::boost::prg_exec_monitor_main( &cpp_main, argc, argv ); |
---|
123 | } |
---|
124 | |
---|
125 | //____________________________________________________________________________// |
---|
126 | |
---|
127 | #endif // !BOOST_TEST_DYN_LINK && !BOOST_TEST_NO_MAIN |
---|
128 | |
---|
129 | //____________________________________________________________________________// |
---|
130 | |
---|
131 | #include <boost/test/detail/enable_warnings.hpp> |
---|
132 | |
---|
133 | // *************************************************************************** |
---|
134 | // Revision History : |
---|
135 | // |
---|
136 | // $Log: cpp_main.ipp,v $ |
---|
137 | // Revision 1.7 2006/03/19 11:45:26 rogeeff |
---|
138 | // main function renamed for consistancy |
---|
139 | // |
---|
140 | // Revision 1.6 2005/12/14 05:27:21 rogeeff |
---|
141 | // cpp_main API modified for DLL |
---|
142 | // |
---|
143 | // *************************************************************************** |
---|
144 | |
---|
145 | #endif // BOOST_TEST_CPP_MAIN_IPP_012205GER |
---|