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
33namespace boost {
34namespace unit_test {
35namespace runtime_config {
36
37// ************************************************************************** //
38// ************** runtime_config ************** //
39// ************************************************************************** //
40
41// UTF parameters
42BOOST_TEST_DECL extern std::string btrt_auto_start_dbg;
43BOOST_TEST_DECL extern std::string btrt_break_exec_path;
44BOOST_TEST_DECL extern std::string btrt_build_info;
45BOOST_TEST_DECL extern std::string btrt_catch_sys_errors;
46BOOST_TEST_DECL extern std::string btrt_color_output;
47BOOST_TEST_DECL extern std::string btrt_detect_fp_except;
48BOOST_TEST_DECL extern std::string btrt_detect_mem_leaks;
49BOOST_TEST_DECL extern std::string btrt_list_content;
50BOOST_TEST_DECL extern std::string btrt_list_labels;
51BOOST_TEST_DECL extern std::string btrt_log_format;
52BOOST_TEST_DECL extern std::string btrt_log_level;
53BOOST_TEST_DECL extern std::string btrt_log_sink;
54BOOST_TEST_DECL extern std::string btrt_combined_logger;
55BOOST_TEST_DECL extern std::string btrt_output_format;
56BOOST_TEST_DECL extern std::string btrt_random_seed;
57BOOST_TEST_DECL extern std::string btrt_report_format;
58BOOST_TEST_DECL extern std::string btrt_report_level;
59BOOST_TEST_DECL extern std::string btrt_report_mem_leaks;
60BOOST_TEST_DECL extern std::string btrt_report_sink;
61BOOST_TEST_DECL extern std::string btrt_result_code;
62BOOST_TEST_DECL extern std::string btrt_run_filters;
63BOOST_TEST_DECL extern std::string btrt_save_test_pattern;
64BOOST_TEST_DECL extern std::string btrt_show_progress;
65BOOST_TEST_DECL extern std::string btrt_use_alt_stack;
66BOOST_TEST_DECL extern std::string btrt_wait_for_debugger;
67BOOST_TEST_DECL extern std::string btrt_help;
68BOOST_TEST_DECL extern std::string btrt_usage;
69BOOST_TEST_DECL extern std::string btrt_version;
70
71BOOST_TEST_DECL void init( int& argc, char** argv );
72
73// ************************************************************************** //
74// ************** runtime_param::get ************** //
75// ************************************************************************** //
76
77/// Access to arguments
78BOOST_TEST_DECL runtime::arguments_store const& argument_store();
79
80template<typename T>
81inline T const&
82get( runtime::cstring parameter_name )
83{
84 return argument_store().get<T>( parameter_name );
85}
86
87inline bool has( runtime::cstring parameter_name )
88{
89 return argument_store().has( parameter_name );
90}
91
92/// For public access
93BOOST_TEST_DECL bool save_pattern();
94
95// ************************************************************************** //
96// ************** stream_holder ************** //
97// ************************************************************************** //
98
99class stream_holder {
100public:
101 // Constructor
102 explicit stream_holder( std::ostream& default_stream = std::cout )
103 : m_stream( &default_stream )
104 {
105 }
106
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>(args: 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>(args: cleaner_callback);
126 }
127 else {
128 m_cleaner.reset();
129 }
130 }
131 else {
132 m_cleaner = boost::make_shared<callback_cleaner>(args: cleaner_callback);
133 m_cleaner->m_file.open( s: std::string(stream_name.begin(), stream_name.end()).c_str() );
134 m_stream = &m_cleaner->m_file;
135 }
136 }
137
138 // Access methods
139 std::ostream& ref() const { return *m_stream; }
140
141private:
142 struct callback_cleaner {
143 callback_cleaner(boost::function<void ()> cleaner_callback)
144 : m_cleaner_callback(cleaner_callback)
145 , m_file() {
146 }
147 ~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

source code of include/boost/test/unit_test_parameters.hpp