unit_test_parameters.hpp 5.7 KB

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