]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // (C) Copyright Gennadiy Rozental 2001. |
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 | |
9 | /// @brief Deprecated implementation of simple minimal testing | |
10 | /// @deprecated | |
11 | /// To convert to Unit Test Framework simply rewrite: | |
12 | /// @code | |
13 | /// #include <boost/test/minimal.hpp> | |
14 | /// | |
15 | /// int test_main( int, char *[] ) | |
16 | /// { | |
17 | /// ... | |
18 | /// } | |
19 | /// @endcode | |
20 | /// as | |
21 | /// @code | |
22 | /// #include <boost/test/included/unit_test.hpp> | |
23 | /// | |
24 | /// BOOST_AUTO_TEST_CASE(test_main) | |
25 | /// { | |
26 | /// ... | |
27 | /// } | |
28 | /// @endcode | |
29 | // *************************************************************************** | |
30 | ||
31 | #ifndef BOOST_TEST_MINIMAL_HPP_071894GER | |
32 | #define BOOST_TEST_MINIMAL_HPP_071894GER | |
33 | ||
34 | #define BOOST_CHECK(exp) \ | |
35 | ( (exp) \ | |
36 | ? static_cast<void>(0) \ | |
37 | : boost::minimal_test::report_error(#exp,__FILE__,__LINE__, BOOST_CURRENT_FUNCTION) ) | |
38 | ||
39 | #define BOOST_REQUIRE(exp) \ | |
40 | ( (exp) \ | |
41 | ? static_cast<void>(0) \ | |
42 | : boost::minimal_test::report_critical_error(#exp,__FILE__,__LINE__,BOOST_CURRENT_FUNCTION)) | |
43 | ||
44 | #define BOOST_ERROR( msg_ ) \ | |
45 | boost::minimal_test::report_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true ) | |
46 | #define BOOST_FAIL( msg_ ) \ | |
47 | boost::minimal_test::report_critical_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true ) | |
48 | ||
49 | //____________________________________________________________________________// | |
50 | ||
51 | // Boost.Test | |
52 | #include <boost/test/detail/global_typedef.hpp> | |
53 | #include <boost/test/impl/execution_monitor.ipp> | |
54 | #include <boost/test/impl/debug.ipp> | |
55 | #include <boost/test/utils/class_properties.hpp> | |
56 | #include <boost/test/utils/basic_cstring/io.hpp> | |
57 | ||
58 | // Boost | |
59 | #include <boost/cstdlib.hpp> // for exit codes | |
60 | #include <boost/current_function.hpp> // for BOOST_CURRENT_FUNCTION | |
61 | ||
62 | // STL | |
63 | #include <iostream> // std::cerr, std::endl | |
64 | #include <string> // std::string | |
65 | ||
66 | #include <boost/test/detail/suppress_warnings.hpp> | |
67 | ||
68 | //____________________________________________________________________________// | |
69 | ||
70 | int test_main( int argc, char* argv[] ); // prototype for users test_main() | |
71 | ||
72 | namespace boost { | |
73 | namespace minimal_test { | |
74 | ||
75 | typedef boost::unit_test::const_string const_string; | |
76 | ||
77 | inline unit_test::counter_t& errors_counter() { static unit_test::counter_t ec = 0; return ec; } | |
78 | ||
79 | inline void | |
80 | report_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false ) | |
81 | { | |
82 | ++errors_counter(); | |
83 | std::cerr << file << "(" << line << "): "; | |
84 | ||
85 | if( is_msg ) | |
86 | std::cerr << msg; | |
87 | else | |
88 | std::cerr << "test " << msg << " failed"; | |
89 | ||
90 | if( func_name != "(unknown)" ) | |
91 | std::cerr << " in function: '" << func_name << "'"; | |
92 | ||
93 | std::cerr << std::endl; | |
94 | } | |
95 | ||
96 | inline void | |
97 | report_critical_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false ) | |
98 | { | |
99 | report_error( msg, file, line, func_name, is_msg ); | |
100 | ||
101 | throw boost::execution_aborted(); | |
102 | } | |
103 | ||
104 | class caller { | |
105 | public: | |
106 | // constructor | |
107 | caller( int argc, char** argv ) | |
108 | : m_argc( argc ), m_argv( argv ) {} | |
109 | ||
110 | // execution monitor hook implementation | |
111 | int operator()() { return test_main( m_argc, m_argv ); } | |
112 | ||
113 | private: | |
114 | // Data members | |
115 | int m_argc; | |
116 | char** m_argv; | |
117 | }; // monitor | |
118 | ||
119 | } // namespace minimal_test | |
120 | } // namespace boost | |
121 | ||
122 | //____________________________________________________________________________// | |
123 | ||
124 | int BOOST_TEST_CALL_DECL main( int argc, char* argv[] ) | |
125 | { | |
126 | using namespace boost::minimal_test; | |
127 | ||
128 | try { | |
129 | ::boost::execution_monitor ex_mon; | |
130 | int run_result = ex_mon.execute( caller( argc, argv ) ); | |
131 | ||
132 | BOOST_CHECK( run_result == 0 || run_result == boost::exit_success ); | |
133 | } | |
134 | catch( boost::execution_exception const& exex ) { | |
135 | if( exex.code() != boost::execution_exception::no_error ) | |
136 | BOOST_ERROR( (std::string( "exception \"" ) + exex.what() + "\" caught").c_str() ); | |
137 | std::cerr << "\n**** Testing aborted."; | |
138 | } | |
139 | ||
140 | if( boost::minimal_test::errors_counter() != 0 ) { | |
141 | std::cerr << "\n**** " << errors_counter() | |
142 | << " error" << (errors_counter() > 1 ? "s" : "" ) << " detected\n"; | |
143 | ||
144 | return boost::exit_test_failure; | |
145 | } | |
146 | ||
147 | std::cout << "\n**** no errors detected\n"; | |
148 | ||
149 | return boost::exit_success; | |
150 | } | |
151 | ||
152 | //____________________________________________________________________________// | |
153 | ||
154 | #include <boost/test/detail/enable_warnings.hpp> | |
155 | ||
156 | #endif // BOOST_TEST_MINIMAL_HPP_071894GER |