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 Provides access to various Unit Test Framework runtime parameters 10 /// 11 /// Primarily for use by the framework itself 12 // *************************************************************************** 13 14 #ifndef BOOST_TEST_UNIT_TEST_PARAMETERS_HPP_071894GER 15 #define BOOST_TEST_UNIT_TEST_PARAMETERS_HPP_071894GER 16 17 // Boost.Test 18 #include <boost/test/detail/global_typedef.hpp> 19 #include <boost/test/utils/runtime/argument.hpp> 20 #include <boost/make_shared.hpp> 21 22 // Boost 23 #include <boost/function/function0.hpp> 24 25 // STL 26 #include <iostream> 27 #include <fstream> 28 29 #include <boost/test/detail/suppress_warnings.hpp> 30 31 //____________________________________________________________________________// 32 33 namespace boost { 34 namespace unit_test { 35 namespace runtime_config { 36 37 // ************************************************************************** // 38 // ************** runtime_config ************** // 39 // ************************************************************************** // 40 41 // UTF parameters 42 BOOST_TEST_DECL extern std::string btrt_auto_start_dbg; 43 BOOST_TEST_DECL extern std::string btrt_break_exec_path; 44 BOOST_TEST_DECL extern std::string btrt_build_info; 45 BOOST_TEST_DECL extern std::string btrt_catch_sys_errors; 46 BOOST_TEST_DECL extern std::string btrt_color_output; 47 BOOST_TEST_DECL extern std::string btrt_detect_fp_except; 48 BOOST_TEST_DECL extern std::string btrt_detect_mem_leaks; 49 BOOST_TEST_DECL extern std::string btrt_list_content; 50 BOOST_TEST_DECL extern std::string btrt_list_labels; 51 BOOST_TEST_DECL extern std::string btrt_log_format; 52 BOOST_TEST_DECL extern std::string btrt_log_level; 53 BOOST_TEST_DECL extern std::string btrt_log_sink; 54 BOOST_TEST_DECL extern std::string btrt_combined_logger; 55 BOOST_TEST_DECL extern std::string btrt_output_format; 56 BOOST_TEST_DECL extern std::string btrt_random_seed; 57 BOOST_TEST_DECL extern std::string btrt_report_format; 58 BOOST_TEST_DECL extern std::string btrt_report_level; 59 BOOST_TEST_DECL extern std::string btrt_report_mem_leaks; 60 BOOST_TEST_DECL extern std::string btrt_report_sink; 61 BOOST_TEST_DECL extern std::string btrt_result_code; 62 BOOST_TEST_DECL extern std::string btrt_run_filters; 63 BOOST_TEST_DECL extern std::string btrt_save_test_pattern; 64 BOOST_TEST_DECL extern std::string btrt_show_progress; 65 BOOST_TEST_DECL extern std::string btrt_use_alt_stack; 66 BOOST_TEST_DECL extern std::string btrt_wait_for_debugger; 67 BOOST_TEST_DECL extern std::string btrt_help; 68 BOOST_TEST_DECL extern std::string btrt_usage; 69 BOOST_TEST_DECL extern std::string btrt_version; 70 71 BOOST_TEST_DECL void init( int& argc, char** argv ); 72 73 // ************************************************************************** // 74 // ************** runtime_param::get ************** // 75 // ************************************************************************** // 76 77 /// Access to arguments 78 BOOST_TEST_DECL runtime::arguments_store const& argument_store(); 79 80 template<typename T> 81 inline T const& get(runtime::cstring parameter_name)82get( runtime::cstring parameter_name ) 83 { 84 return argument_store().get<T>( parameter_name ); 85 } 86 has(runtime::cstring parameter_name)87inline bool has( runtime::cstring parameter_name ) 88 { 89 return argument_store().has( parameter_name ); 90 } 91 92 /// For public access 93 BOOST_TEST_DECL bool save_pattern(); 94 95 // ************************************************************************** // 96 // ************** stream_holder ************** // 97 // ************************************************************************** // 98 99 class stream_holder { 100 public: 101 // Constructor stream_holder(std::ostream & default_stream=std::cout)102 explicit stream_holder( std::ostream& default_stream = std::cout ) 103 : m_stream( &default_stream ) 104 { 105 } 106 setup(const const_string & stream_name,boost::function<void ()> const & cleaner_callback=boost::function<void ()> ())107 void setup( const const_string& stream_name, 108 boost::function<void ()> const &cleaner_callback = boost::function<void ()>() ) 109 { 110 if(stream_name.empty()) 111 return; 112 113 if( stream_name == "stderr" ) { 114 m_stream = &std::cerr; 115 if(cleaner_callback) { 116 m_cleaner = boost::make_shared<callback_cleaner>(cleaner_callback); 117 } 118 else { 119 m_cleaner.reset(); 120 } 121 } 122 else if( stream_name == "stdout" ) { 123 m_stream = &std::cout; 124 if (cleaner_callback) { 125 m_cleaner = boost::make_shared<callback_cleaner>(cleaner_callback); 126 } 127 else { 128 m_cleaner.reset(); 129 } 130 } 131 else { 132 m_cleaner = boost::make_shared<callback_cleaner>(cleaner_callback); 133 m_cleaner->m_file.open( std::string(stream_name.begin(), stream_name.end()).c_str() ); 134 m_stream = &m_cleaner->m_file; 135 } 136 } 137 138 // Access methods ref() const139 std::ostream& ref() const { return *m_stream; } 140 141 private: 142 struct callback_cleaner { callback_cleanerboost::unit_test::runtime_config::stream_holder::callback_cleaner143 callback_cleaner(boost::function<void ()> cleaner_callback) 144 : m_cleaner_callback(cleaner_callback) 145 , m_file() { 146 } ~callback_cleanerboost::unit_test::runtime_config::stream_holder::callback_cleaner147 ~callback_cleaner() { 148 if( m_cleaner_callback ) 149 m_cleaner_callback(); 150 } 151 boost::function<void ()> m_cleaner_callback; 152 std::ofstream m_file; 153 }; 154 155 // Data members 156 boost::shared_ptr<callback_cleaner> m_cleaner; 157 std::ostream* m_stream; 158 }; 159 160 } // namespace runtime_config 161 } // namespace unit_test 162 } // namespace boost 163 164 //____________________________________________________________________________// 165 166 #include <boost/test/detail/enable_warnings.hpp> 167 168 #endif // BOOST_TEST_UNIT_TEST_PARAMETERS_HPP_071894GER 169