unit_test_parameters.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. // STL
  18. #include <iostream>
  19. #include <fstream>
  20. #include <boost/test/detail/suppress_warnings.hpp>
  21. //____________________________________________________________________________//
  22. namespace boost {
  23. namespace unit_test {
  24. namespace runtime_config {
  25. // ************************************************************************** //
  26. // ************** runtime_config ************** //
  27. // ************************************************************************** //
  28. // UTF parameters
  29. BOOST_TEST_DECL extern std::string AUTO_START_DBG;
  30. BOOST_TEST_DECL extern std::string BREAK_EXEC_PATH;
  31. BOOST_TEST_DECL extern std::string BUILD_INFO;
  32. BOOST_TEST_DECL extern std::string CATCH_SYS_ERRORS;
  33. BOOST_TEST_DECL extern std::string COLOR_OUTPUT;
  34. BOOST_TEST_DECL extern std::string DETECT_FP_EXCEPT;
  35. BOOST_TEST_DECL extern std::string DETECT_MEM_LEAKS;
  36. BOOST_TEST_DECL extern std::string LIST_CONTENT;
  37. BOOST_TEST_DECL extern std::string LIST_LABELS;
  38. BOOST_TEST_DECL extern std::string LOG_FORMAT;
  39. BOOST_TEST_DECL extern std::string LOG_LEVEL;
  40. BOOST_TEST_DECL extern std::string LOG_SINK;
  41. BOOST_TEST_DECL extern std::string OUTPUT_FORMAT;
  42. BOOST_TEST_DECL extern std::string RANDOM_SEED;
  43. BOOST_TEST_DECL extern std::string REPORT_FORMAT;
  44. BOOST_TEST_DECL extern std::string REPORT_LEVEL;
  45. BOOST_TEST_DECL extern std::string REPORT_MEM_LEAKS;
  46. BOOST_TEST_DECL extern std::string REPORT_SINK;
  47. BOOST_TEST_DECL extern std::string RESULT_CODE;
  48. BOOST_TEST_DECL extern std::string RUN_FILTERS;
  49. BOOST_TEST_DECL extern std::string SAVE_TEST_PATTERN;
  50. BOOST_TEST_DECL extern std::string SHOW_PROGRESS;
  51. BOOST_TEST_DECL extern std::string USE_ALT_STACK;
  52. BOOST_TEST_DECL extern std::string WAIT_FOR_DEBUGGER;
  53. BOOST_TEST_DECL void init( int& argc, char** argv );
  54. // ************************************************************************** //
  55. // ************** runtime_param::get ************** //
  56. // ************************************************************************** //
  57. /// Access to arguments
  58. BOOST_TEST_DECL runtime::arguments_store const& argument_store();
  59. template<typename T>
  60. inline T const&
  61. get( runtime::cstring parameter_name )
  62. {
  63. return argument_store().get<T>( parameter_name );
  64. }
  65. /// For public access
  66. BOOST_TEST_DECL bool save_pattern();
  67. // ************************************************************************** //
  68. // ************** stream_holder ************** //
  69. // ************************************************************************** //
  70. class stream_holder {
  71. public:
  72. // Constructor
  73. explicit stream_holder( std::ostream& default_stream )
  74. : m_stream( &default_stream )
  75. {
  76. }
  77. void setup( runtime::cstring param_name )
  78. {
  79. if( !runtime_config::argument_store().has( param_name ) )
  80. return;
  81. std::string const& file_name = runtime_config::get<std::string>( param_name );
  82. if( file_name == "stderr" )
  83. m_stream = &std::cerr;
  84. else if( file_name == "stdout" )
  85. m_stream = &std::cout;
  86. else {
  87. m_file.open( file_name.c_str() );
  88. m_stream = &m_file;
  89. }
  90. }
  91. // Access methods
  92. std::ostream& ref() const { return *m_stream; }
  93. private:
  94. // Data members
  95. std::ofstream m_file;
  96. std::ostream* m_stream;
  97. };
  98. } // namespace runtime_config
  99. } // namespace unit_test
  100. } // namespace boost
  101. //____________________________________________________________________________//
  102. #include <boost/test/detail/enable_warnings.hpp>
  103. #endif // BOOST_TEST_UNIT_TEST_PARAMETERS_HPP_071894GER