]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // (C) Copyright Gennadiy Rozental 2001-2015. |
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 : $RCSfile$ | |
9 | // | |
10 | // Version : $Revision$ | |
11 | // | |
12 | // Description : tests Unit Test Framework reporting facilities against | |
13 | // pattern file | |
14 | // *************************************************************************** | |
15 | ||
16 | // Boost.Test | |
17 | #define BOOST_TEST_MAIN | |
18 | #include <boost/test/unit_test.hpp> | |
19 | #include <boost/test/results_reporter.hpp> | |
20 | #include <boost/test/tools/output_test_stream.hpp> | |
21 | #include <boost/test/unit_test_log.hpp> | |
22 | #include <boost/test/unit_test_suite.hpp> | |
23 | #include <boost/test/framework.hpp> | |
24 | #include <boost/test/unit_test_parameters.hpp> | |
25 | #include <boost/test/utils/nullstream.hpp> | |
26 | typedef boost::onullstream onullstream_type; | |
27 | ||
28 | // BOOST | |
29 | #include <boost/lexical_cast.hpp> | |
30 | ||
31 | // STL | |
32 | #include <iostream> | |
33 | ||
34 | using boost::test_tools::output_test_stream; | |
35 | using namespace boost::unit_test; | |
36 | ||
37 | //____________________________________________________________________________// | |
38 | ||
39 | void good_foo() {} | |
40 | ||
41 | void almost_good_foo() { BOOST_TEST_WARN( 2>3 ); } | |
42 | ||
43 | void bad_foo() { | |
44 | onullstream_type null_out; | |
45 | unit_test_log.set_stream( null_out ); | |
46 | BOOST_ERROR( "" ); | |
47 | unit_test_log.set_stream( std::cout ); | |
48 | } | |
49 | ||
50 | struct log_guard { | |
51 | ~log_guard() | |
52 | { | |
53 | unit_test_log.set_stream( std::cout ); | |
54 | } | |
55 | }; | |
56 | ||
57 | void very_bad_foo() { | |
58 | log_guard lg; | |
59 | ut_detail::ignore_unused_variable_warning( lg ); | |
60 | onullstream_type null_out; | |
61 | unit_test_log.set_stream( null_out ); | |
62 | BOOST_FAIL( "" ); | |
63 | } | |
64 | ||
65 | //____________________________________________________________________________// | |
66 | ||
67 | void check( output_test_stream& output, output_format report_format, test_unit_id id ) | |
68 | { | |
69 | results_reporter::set_format( report_format ); | |
70 | ||
71 | results_reporter::confirmation_report( id ); | |
72 | output << "*************************************************************************\n"; | |
73 | BOOST_TEST( output.match_pattern() ); | |
74 | ||
75 | results_reporter::short_report( id ); | |
76 | output << "*************************************************************************\n"; | |
77 | BOOST_TEST( output.match_pattern() ); | |
78 | ||
79 | results_reporter::detailed_report( id ); | |
80 | output << "*************************************************************************\n"; | |
81 | BOOST_TEST( output.match_pattern() ); | |
82 | } | |
83 | ||
84 | //____________________________________________________________________________// | |
85 | ||
86 | void check( output_test_stream& output, test_suite* ts ) | |
87 | { | |
88 | ts->p_default_status.value = test_unit::RS_ENABLED; | |
89 | ||
90 | framework::finalize_setup_phase( ts->p_id ); | |
91 | framework::run( ts ); | |
92 | ||
93 | check( output, OF_CLF, ts->p_id ); | |
94 | check( output, OF_XML, ts->p_id ); | |
95 | } | |
96 | ||
97 | //____________________________________________________________________________// | |
98 | ||
99 | struct guard { | |
100 | ~guard() | |
101 | { | |
102 | results_reporter::set_stream( std::cerr ); | |
103 | results_reporter::set_format( runtime_config::get<output_format>( | |
b32b8144 | 104 | runtime_config::btrt_report_format ) ); |
7c673cae FG |
105 | } |
106 | }; | |
107 | ||
108 | //____________________________________________________________________________// | |
109 | ||
110 | BOOST_AUTO_TEST_CASE( test_result_reports ) | |
111 | { | |
112 | guard G; | |
113 | ut_detail::ignore_unused_variable_warning( G ); | |
114 | ||
115 | #define PATTERN_FILE_NAME "result_report_test.pattern" | |
116 | ||
117 | std::string pattern_file_name( | |
118 | framework::master_test_suite().argc == 1 | |
119 | ? (runtime_config::save_pattern() ? PATTERN_FILE_NAME : "./baseline-outputs/" PATTERN_FILE_NAME ) | |
120 | : framework::master_test_suite().argv[1] ); | |
121 | ||
122 | output_test_stream test_output( pattern_file_name, !runtime_config::save_pattern() ); | |
123 | results_reporter::set_stream( test_output ); | |
124 | ||
125 | test_suite* ts_0 = BOOST_TEST_SUITE( "0 test cases inside" ); | |
126 | ||
127 | test_suite* ts_1 = BOOST_TEST_SUITE( "1 test cases inside" ); | |
128 | ts_1->add( BOOST_TEST_CASE( good_foo ) ); | |
129 | ||
130 | test_suite* ts_1b = BOOST_TEST_SUITE( "1 bad test case inside" ); | |
131 | ts_1b->add( BOOST_TEST_CASE( bad_foo ), 1 ); | |
132 | ||
133 | test_suite* ts_1c = BOOST_TEST_SUITE( "1 almost good test case inside" ); | |
134 | ts_1c->add( BOOST_TEST_CASE( almost_good_foo ) ); | |
135 | ||
136 | test_suite* ts_2 = BOOST_TEST_SUITE( "2 test cases inside" ); | |
137 | ts_2->add( BOOST_TEST_CASE( good_foo ) ); | |
138 | ts_2->add( BOOST_TEST_CASE( bad_foo ), 1 ); | |
139 | ||
140 | test_suite* ts_3 = BOOST_TEST_SUITE( "3 test cases inside" ); | |
141 | ts_3->add( BOOST_TEST_CASE( bad_foo ) ); | |
142 | test_case* tc1 = BOOST_TEST_CASE( very_bad_foo ); | |
143 | ts_3->add( tc1 ); | |
144 | test_case* tc2 = BOOST_TEST_CASE( bad_foo ); | |
145 | ts_3->add( tc2 ); | |
146 | tc2->depends_on( tc1 ); | |
147 | ||
148 | test_suite* ts_main = BOOST_TEST_SUITE( "Fake Test Suite Hierarchy" ); | |
149 | ts_main->add( ts_0 ); | |
150 | ts_main->add( ts_1 ); | |
151 | ts_main->add( ts_2 ); | |
152 | ts_main->add( ts_3 ); | |
153 | ||
154 | test_suite* ts_char_escaping = BOOST_TEST_SUITE( "Char escaping" ); | |
155 | ts_char_escaping->add( BOOST_TEST_CASE( good_foo ) ); | |
156 | test_case * i_have_problems = BOOST_TEST_CASE( bad_foo ); | |
157 | i_have_problems->p_name.set("bad_foo<h>"); | |
158 | ts_char_escaping->add( i_have_problems ); | |
159 | ||
160 | check( test_output, ts_1 ); | |
161 | ||
162 | check( test_output, ts_1b ); | |
163 | ||
164 | check( test_output, ts_1c ); | |
165 | ||
166 | check( test_output, ts_2 ); | |
167 | ||
168 | check( test_output, ts_3 ); | |
169 | ts_1->add( BOOST_TEST_CASE( bad_foo ) ); | |
170 | ts_3->depends_on( ts_1 ); | |
171 | ||
172 | check( test_output, ts_main ); | |
173 | ||
174 | check( test_output, ts_char_escaping ); | |
175 | ||
176 | results_reporter::set_stream( std::cout ); | |
177 | } | |
178 | ||
179 | //____________________________________________________________________________// | |
180 | ||
181 | // EOF |