]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/test/test-organization-ts/parameterized_test-test.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / test / test / test-organization-ts / parameterized_test-test.cpp
1 // (C) Copyright Gennadiy Rozental 2002-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 // Description : tests parameterized tests
9 // Note: this file should be compatible with C++03 compilers (features in boost.test v2)
10 // ***************************************************************************
11
12 // Boost.Test
13 #define BOOST_TEST_MAIN
14 #include <boost/test/unit_test.hpp>
15 #include <boost/test/parameterized_test.hpp>
16 #include <boost/test/unit_test_log.hpp>
17 #include <boost/test/results_collector.hpp>
18 #include <boost/test/utils/nullstream.hpp>
19 typedef boost::onullstream onullstream_type;
20
21 namespace ut = boost::unit_test;
22
23 // BOOST
24 #include <boost/scoped_ptr.hpp>
25
26 // STL
27 #include <list>
28 #include <iostream>
29
30 //____________________________________________________________________________//
31
32 void test0( int i )
33 {
34 BOOST_TEST( (i%2 == 0) ); // amounts to BOOST_CHECK, for backward compatibility wrt. boost.test v2
35 }
36
37 //____________________________________________________________________________//
38
39 void test1( int i )
40 {
41 BOOST_TEST( (i%2 == 0) );
42 if( i%3 == 0 ) {
43 throw 124;
44 }
45 }
46
47 //____________________________________________________________________________//
48
49 static void
50 setup_tree( ut::test_suite* master_tu )
51 {
52 master_tu->p_default_status.value = ut::test_unit::RS_ENABLED;
53 ut::framework::finalize_setup_phase( master_tu->p_id );
54 }
55
56 //____________________________________________________________________________//
57
58 struct logger_guard {
59 logger_guard(std::ostream& s_out) {
60 ut::unit_test_log.set_stream( s_out );
61 }
62 ~logger_guard() {
63 ut::unit_test_log.set_stream( std::cout );
64 }
65 };
66
67 BOOST_AUTO_TEST_CASE( test_case1 )
68 {
69 // if an exception is thrown in the test, this object is destructed when we reach the logger
70 // for logging the exception. This happens for instance if the test->add throws:
71 // - test case aborted, null_output destructed but still refered from the logger
72 // - exception caught by the framework, and exception content logged
73 // - reference to a non-existing log stream
74 onullstream_type null_output;
75 logger_guard G( null_output );
76
77 ut::test_suite* test = BOOST_TEST_SUITE( "" );
78 int test_data[] = { 2, 2, 2 };
79 test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
80
81 setup_tree( test );
82 ut::framework::run( test );
83 ut::test_results const& tr = ut::results_collector.results( test->p_id );
84
85 ut::unit_test_log.set_stream( std::cout );
86 BOOST_TEST( tr.p_assertions_failed == 0U );
87 BOOST_TEST( !tr.p_aborted );
88 }
89
90 //____________________________________________________________________________//
91
92 BOOST_AUTO_TEST_CASE( test_case2 )
93 {
94 onullstream_type null_output;
95 logger_guard G( null_output );
96
97 ut::test_suite* test = BOOST_TEST_SUITE( "" );
98 int test_data[] = { 1, 2, 2 };
99 test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
100
101 setup_tree( test );
102 ut::framework::run( test );
103 ut::test_results const& tr = ut::results_collector.results( test->p_id );
104
105 ut::unit_test_log.set_stream( std::cout );
106 BOOST_TEST( tr.p_assertions_failed == 1U );
107 BOOST_TEST( !tr.p_aborted );
108 }
109
110 //____________________________________________________________________________//
111
112 BOOST_AUTO_TEST_CASE( test_case3 )
113 {
114 onullstream_type null_output;
115 logger_guard G( null_output );
116
117 ut::test_suite* test = BOOST_TEST_SUITE( "" );
118 int test_data[] = { 1, 1, 2 };
119 test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
120
121 setup_tree( test );
122 ut::framework::run( test );
123 ut::test_results const& tr = ut::results_collector.results( test->p_id );
124
125 ut::unit_test_log.set_stream( std::cout );
126 BOOST_TEST( tr.p_assertions_failed == 2U );
127 BOOST_TEST( !tr.p_aborted );
128 }
129
130 //____________________________________________________________________________//
131
132 BOOST_AUTO_TEST_CASE( test_case4 )
133 {
134 onullstream_type null_output;
135 logger_guard G( null_output );
136
137 ut::test_suite* test = BOOST_TEST_SUITE( "" );
138 int test_data[] = { 1, 1, 1 };
139 test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
140
141 setup_tree( test );
142 ut::framework::run( test );
143 ut::test_results const& tr = ut::results_collector.results( test->p_id );
144
145 ut::unit_test_log.set_stream( std::cout );
146 BOOST_TEST( tr.p_assertions_failed == 3U );
147 BOOST_TEST( !tr.p_aborted );
148 }
149
150 //____________________________________________________________________________//
151
152 BOOST_AUTO_TEST_CASE( test_case5 )
153 {
154 onullstream_type null_output;
155 logger_guard G( null_output );
156
157 ut::test_suite* test = BOOST_TEST_SUITE( "" );
158 int test_data[] = { 6, 6, 6 };
159 test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
160
161 setup_tree( test );
162 ut::framework::run( test );
163 ut::test_results const& tr = ut::results_collector.results( test->p_id );
164
165 ut::unit_test_log.set_stream( std::cout );
166 BOOST_TEST( tr.p_assertions_failed == 3U );
167 BOOST_TEST( !tr.p_aborted );
168 BOOST_TEST( !tr.passed() );
169 }
170
171 //____________________________________________________________________________//
172
173 BOOST_AUTO_TEST_CASE( test_case6 )
174 {
175 onullstream_type null_output;
176 logger_guard G( null_output );
177
178 ut::test_suite* test = BOOST_TEST_SUITE( "" );
179 int test_data[] = { 0, 3, 9 };
180 test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
181
182 setup_tree( test );
183 ut::framework::run( test );
184 ut::test_results const& tr = ut::results_collector.results( test->p_id );
185
186 ut::unit_test_log.set_stream( std::cout );
187 BOOST_TEST( tr.p_assertions_failed == 5U );
188 BOOST_TEST( !tr.p_aborted );
189 }
190
191 //____________________________________________________________________________//
192
193 BOOST_AUTO_TEST_CASE( test_case7 )
194 {
195 onullstream_type null_output;
196 logger_guard G( null_output );
197
198 ut::test_suite* test = BOOST_TEST_SUITE( "" );
199 int test_data[] = { 2, 3, 9 };
200 test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
201
202 setup_tree( test );
203 ut::framework::run( test );
204 ut::test_results const& tr = ut::results_collector.results( test->p_id );
205
206 ut::unit_test_log.set_stream( std::cout );
207 BOOST_TEST( tr.p_assertions_failed == 4U );
208 BOOST_TEST( !tr.p_aborted );
209 }
210
211 //____________________________________________________________________________//
212
213 BOOST_AUTO_TEST_CASE( test_case8 )
214 {
215 onullstream_type null_output;
216 logger_guard G( null_output );
217
218 ut::test_suite* test = BOOST_TEST_SUITE( "" );
219 int test_data[] = { 3, 2, 6 };
220 test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
221
222 setup_tree( test );
223 ut::framework::run( test );
224 ut::test_results const& tr = ut::results_collector.results( test->p_id );
225
226 ut::unit_test_log.set_stream( std::cout );
227 BOOST_TEST( tr.p_assertions_failed == 3U );
228 BOOST_TEST( !tr.p_aborted );
229 }
230
231 //____________________________________________________________________________//
232
233 // EOF