]> git.proxmox.com Git - ceph.git/blame - 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
CommitLineData
7c673cae
FG
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>
19typedef boost::onullstream onullstream_type;
20
21namespace 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
32void 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
39void test1( int i )
40{
41 BOOST_TEST( (i%2 == 0) );
42 if( i%3 == 0 ) {
43 throw 124;
44 }
45}
46
47//____________________________________________________________________________//
48
49static void
50setup_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
11fdf7f2
TL
58struct 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
7c673cae
FG
67BOOST_AUTO_TEST_CASE( test_case1 )
68{
11fdf7f2
TL
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 );
7c673cae 76
11fdf7f2 77 ut::test_suite* test = BOOST_TEST_SUITE( "" );
7c673cae
FG
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
92BOOST_AUTO_TEST_CASE( test_case2 )
93{
11fdf7f2
TL
94 onullstream_type null_output;
95 logger_guard G( null_output );
7c673cae 96
11fdf7f2 97 ut::test_suite* test = BOOST_TEST_SUITE( "" );
7c673cae
FG
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
112BOOST_AUTO_TEST_CASE( test_case3 )
113{
11fdf7f2
TL
114 onullstream_type null_output;
115 logger_guard G( null_output );
7c673cae 116
11fdf7f2 117 ut::test_suite* test = BOOST_TEST_SUITE( "" );
7c673cae
FG
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
132BOOST_AUTO_TEST_CASE( test_case4 )
133{
11fdf7f2
TL
134 onullstream_type null_output;
135 logger_guard G( null_output );
7c673cae 136
11fdf7f2 137 ut::test_suite* test = BOOST_TEST_SUITE( "" );
7c673cae
FG
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
152BOOST_AUTO_TEST_CASE( test_case5 )
153{
11fdf7f2
TL
154 onullstream_type null_output;
155 logger_guard G( null_output );
7c673cae 156
11fdf7f2 157 ut::test_suite* test = BOOST_TEST_SUITE( "" );
7c673cae
FG
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
173BOOST_AUTO_TEST_CASE( test_case6 )
174{
11fdf7f2
TL
175 onullstream_type null_output;
176 logger_guard G( null_output );
7c673cae 177
11fdf7f2 178 ut::test_suite* test = BOOST_TEST_SUITE( "" );
7c673cae
FG
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
193BOOST_AUTO_TEST_CASE( test_case7 )
194{
11fdf7f2
TL
195 onullstream_type null_output;
196 logger_guard G( null_output );
7c673cae 197
11fdf7f2 198 ut::test_suite* test = BOOST_TEST_SUITE( "" );
7c673cae
FG
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
213BOOST_AUTO_TEST_CASE( test_case8 )
214{
215 onullstream_type null_output;
11fdf7f2 216 logger_guard G( null_output );
7c673cae 217
11fdf7f2 218 ut::test_suite* test = BOOST_TEST_SUITE( "" );
7c673cae
FG
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