File indexing completed on 2025-01-30 10:01:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_TEST_UNIT_TEST_MAIN_IPP_012205GER
0016 #define BOOST_TEST_UNIT_TEST_MAIN_IPP_012205GER
0017
0018
0019 #include <boost/test/framework.hpp>
0020 #include <boost/test/results_collector.hpp>
0021 #include <boost/test/results_reporter.hpp>
0022
0023 #include <boost/test/tree/visitor.hpp>
0024 #include <boost/test/tree/test_unit.hpp>
0025 #include <boost/test/tree/traverse.hpp>
0026
0027 #include <boost/test/unit_test_parameters.hpp>
0028
0029 #include <boost/test/utils/foreach.hpp>
0030 #include <boost/test/utils/basic_cstring/io.hpp>
0031
0032
0033 #include <boost/core/ignore_unused.hpp>
0034 #include <boost/cstdlib.hpp>
0035
0036
0037 #include <cstdio>
0038 #include <stdexcept>
0039 #include <iostream>
0040 #include <iomanip>
0041 #include <iterator>
0042 #include <set>
0043
0044 #include <boost/test/detail/suppress_warnings.hpp>
0045
0046
0047
0048 namespace boost {
0049 namespace unit_test {
0050
0051 namespace ut_detail {
0052
0053
0054
0055
0056
0057 struct hrf_content_reporter : test_tree_visitor {
0058 explicit hrf_content_reporter( std::ostream& os ) : m_os( os ), m_indent( -4 ) {}
0059
0060 private:
0061 void report_test_unit( test_unit const& tu )
0062 {
0063 m_os << std::setw( m_indent ) << "" << tu.p_name;
0064 m_os << (tu.p_default_status == test_unit::RS_ENABLED ? "*" : " ");
0065
0066 if( !tu.p_description->empty() )
0067 m_os << ": " << tu.p_description;
0068
0069 m_os << "\n";
0070 }
0071 void visit( test_case const& tc ) BOOST_OVERRIDE { report_test_unit( tc ); }
0072 bool test_suite_start( test_suite const& ts ) BOOST_OVERRIDE
0073 {
0074 if( m_indent >= 0 )
0075 report_test_unit( ts );
0076 m_indent += 4;
0077 return true;
0078 }
0079 void test_suite_finish( test_suite const& ) BOOST_OVERRIDE
0080 {
0081 m_indent -= 4;
0082 }
0083
0084
0085 std::ostream& m_os;
0086 int m_indent;
0087 };
0088
0089
0090
0091
0092
0093 struct dot_content_reporter : test_tree_visitor {
0094 explicit dot_content_reporter( std::ostream& os ) : m_os( os ) {}
0095
0096 private:
0097 void report_test_unit( test_unit const& tu )
0098 {
0099 bool master_ts = tu.p_parent_id == INV_TEST_UNIT_ID;
0100
0101 m_os << "tu" << tu.p_id;
0102
0103 m_os << (master_ts ? "[shape=ellipse,peripheries=2" : "[shape=Mrecord" );
0104
0105 m_os << ",fontname=Helvetica";
0106
0107 m_os << (tu.p_default_status == test_unit::RS_ENABLED ? ",color=green" : ",color=yellow");
0108
0109 if( master_ts )
0110 m_os << ",label=\"" << tu.p_name << "\"];\n";
0111 else {
0112 m_os << ",label=\"" << tu.p_name << "|" << tu.p_file_name << "(" << tu.p_line_num << ")";
0113 if( tu.p_timeout > 0 )
0114 m_os << "|timeout=" << tu.p_timeout;
0115 if( tu.p_expected_failures != 0 )
0116 m_os << "|expected failures=" << tu.p_expected_failures;
0117 if( !tu.p_labels->empty() ) {
0118 m_os << "|labels:";
0119
0120 BOOST_TEST_FOREACH( std::string const&, l, tu.p_labels.get() )
0121 m_os << " @" << l;
0122 }
0123 m_os << "\"];\n";
0124 }
0125
0126 if( !master_ts )
0127 m_os << "tu" << tu.p_parent_id << " -> " << "tu" << tu.p_id << ";\n";
0128
0129 BOOST_TEST_FOREACH( test_unit_id, dep_id, tu.p_dependencies.get() ) {
0130 test_unit const& dep = framework::get( dep_id, TUT_ANY );
0131
0132 m_os << "tu" << tu.p_id << " -> " << "tu" << dep.p_id << "[color=red,style=dotted,constraint=false];\n";
0133 }
0134
0135 }
0136 void visit( test_case const& tc ) BOOST_OVERRIDE
0137 {
0138 report_test_unit( tc );
0139 }
0140 bool test_suite_start( test_suite const& ts ) BOOST_OVERRIDE
0141 {
0142 if( ts.p_parent_id == INV_TEST_UNIT_ID )
0143 m_os << "digraph G {rankdir=LR;\n";
0144
0145 report_test_unit( ts );
0146
0147 m_os << "{\n";
0148
0149 return true;
0150 }
0151 void test_suite_finish( test_suite const& ts ) BOOST_OVERRIDE
0152 {
0153 m_os << "}\n";
0154 if( ts.p_parent_id == INV_TEST_UNIT_ID )
0155 m_os << "}\n";
0156 }
0157
0158 std::ostream& m_os;
0159 };
0160
0161
0162
0163
0164
0165 struct labels_collector : test_tree_visitor {
0166 std::set<std::string> const& labels() const { return m_labels; }
0167
0168 private:
0169 bool visit( test_unit const& tu ) BOOST_OVERRIDE
0170 {
0171 m_labels.insert( tu.p_labels->begin(), tu.p_labels->end() );
0172 return true;
0173 }
0174
0175
0176 std::set<std::string> m_labels;
0177 };
0178
0179 struct framework_shutdown_helper {
0180 ~framework_shutdown_helper() {
0181 try {
0182 framework::shutdown();
0183 }
0184 catch(...) {
0185 std::cerr << "Boost.Test shutdown exception caught" << std::endl;
0186 }
0187 }
0188 };
0189
0190 }
0191
0192
0193
0194
0195
0196
0197
0198 int BOOST_TEST_DECL
0199 unit_test_main( init_unit_test_func init_func, int argc, char* argv[] )
0200 {
0201 int result_code = 0;
0202
0203 ut_detail::framework_shutdown_helper shutdown_helper;
0204 boost::ignore_unused(shutdown_helper);
0205
0206 BOOST_TEST_I_TRY {
0207
0208 framework::init( init_func, argc, argv );
0209
0210 if( runtime_config::get<bool>( runtime_config::btrt_wait_for_debugger ) ) {
0211 results_reporter::get_stream() << "Press any key to continue..." << std::endl;
0212
0213
0214
0215 (std::getchar)();
0216 results_reporter::get_stream() << "Continuing..." << std::endl;
0217 }
0218
0219 framework::finalize_setup_phase();
0220
0221 output_format list_cont = runtime_config::get<output_format>( runtime_config::btrt_list_content );
0222 if( list_cont != unit_test::OF_INVALID ) {
0223 if( list_cont == unit_test::OF_DOT ) {
0224 ut_detail::dot_content_reporter reporter( results_reporter::get_stream() );
0225
0226 traverse_test_tree( framework::master_test_suite().p_id, reporter, true );
0227 }
0228 else {
0229 ut_detail::hrf_content_reporter reporter( results_reporter::get_stream() );
0230
0231 traverse_test_tree( framework::master_test_suite().p_id, reporter, true );
0232 }
0233
0234 return boost::exit_success;
0235 }
0236
0237 if( runtime_config::get<bool>( runtime_config::btrt_list_labels ) ) {
0238 ut_detail::labels_collector collector;
0239
0240 traverse_test_tree( framework::master_test_suite().p_id, collector, true );
0241
0242 results_reporter::get_stream() << "Available labels:\n ";
0243 std::copy( collector.labels().begin(), collector.labels().end(),
0244 std::ostream_iterator<std::string>( results_reporter::get_stream(), "\n " ) );
0245 results_reporter::get_stream() << "\n";
0246
0247 return boost::exit_success;
0248 }
0249
0250 framework::run();
0251
0252 result_code = !runtime_config::get<bool>( runtime_config::btrt_result_code )
0253 ? boost::exit_success
0254 : results_collector.results( framework::master_test_suite().p_id ).result_code();
0255 }
0256 BOOST_TEST_I_CATCH( framework::nothing_to_test, ex ) {
0257 result_code = ex.m_result_code;
0258 }
0259 BOOST_TEST_I_CATCH( framework::internal_error, ex ) {
0260 results_reporter::get_stream() << "Boost.Test framework internal error: " << ex.what() << std::endl;
0261
0262 result_code = boost::exit_exception_failure;
0263 }
0264 BOOST_TEST_I_CATCH( framework::setup_error, ex ) {
0265 results_reporter::get_stream() << "Test setup error: " << ex.what() << std::endl;
0266
0267 result_code = boost::exit_exception_failure;
0268 }
0269 BOOST_TEST_I_CATCH( std::logic_error, ex ) {
0270 results_reporter::get_stream() << "Test setup error: " << ex.what() << std::endl;
0271
0272 result_code = boost::exit_exception_failure;
0273 }
0274 BOOST_TEST_I_CATCHALL() {
0275 results_reporter::get_stream() << "Boost.Test framework internal error: unknown reason" << std::endl;
0276
0277 result_code = boost::exit_exception_failure;
0278 }
0279
0280 return result_code;
0281 }
0282
0283 }
0284 }
0285
0286 #if !defined(BOOST_TEST_DYN_LINK) && !defined(BOOST_TEST_NO_MAIN)
0287
0288
0289
0290
0291
0292 int BOOST_TEST_CALL_DECL
0293 main( int argc, char* argv[] )
0294 {
0295
0296 #ifdef BOOST_TEST_ALTERNATIVE_INIT_API
0297 extern bool init_unit_test();
0298
0299 boost::unit_test::init_unit_test_func init_func = &init_unit_test;
0300 #else
0301 extern ::boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] );
0302
0303 boost::unit_test::init_unit_test_func init_func = &init_unit_test_suite;
0304 #endif
0305
0306 return ::boost::unit_test::unit_test_main( init_func, argc, argv );
0307 }
0308
0309 #endif
0310
0311
0312
0313 #include <boost/test/detail/enable_warnings.hpp>
0314
0315 #endif