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