]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/test/test-organization-ts/parameterized_test-test.cpp
add subtree-ish sources for 12.0.3
[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 BOOST_AUTO_TEST_CASE( test_case1 )
59 {
60 onullstream_type null_output;
61 ut::test_suite* test = BOOST_TEST_SUITE( "" );
62
63 ut::unit_test_log.set_stream( null_output );
64 int test_data[] = { 2, 2, 2 };
65 test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
66
67 setup_tree( test );
68 ut::framework::run( test );
69 ut::test_results const& tr = ut::results_collector.results( test->p_id );
70
71 ut::unit_test_log.set_stream( std::cout );
72 BOOST_TEST( tr.p_assertions_failed == 0U );
73 BOOST_TEST( !tr.p_aborted );
74 }
75
76 //____________________________________________________________________________//
77
78 BOOST_AUTO_TEST_CASE( test_case2 )
79 {
80 onullstream_type null_output;
81 ut::test_suite* test = BOOST_TEST_SUITE( "" );
82
83 ut::unit_test_log.set_stream( null_output );
84 int test_data[] = { 1, 2, 2 };
85 test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
86
87 setup_tree( test );
88 ut::framework::run( test );
89 ut::test_results const& tr = ut::results_collector.results( test->p_id );
90
91 ut::unit_test_log.set_stream( std::cout );
92 BOOST_TEST( tr.p_assertions_failed == 1U );
93 BOOST_TEST( !tr.p_aborted );
94 }
95
96 //____________________________________________________________________________//
97
98 BOOST_AUTO_TEST_CASE( test_case3 )
99 {
100 onullstream_type null_output;
101 ut::test_suite* test = BOOST_TEST_SUITE( "" );
102
103 ut::unit_test_log.set_stream( null_output );
104 int test_data[] = { 1, 1, 2 };
105 test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
106
107 setup_tree( test );
108 ut::framework::run( test );
109 ut::test_results const& tr = ut::results_collector.results( test->p_id );
110
111 ut::unit_test_log.set_stream( std::cout );
112 BOOST_TEST( tr.p_assertions_failed == 2U );
113 BOOST_TEST( !tr.p_aborted );
114 }
115
116 //____________________________________________________________________________//
117
118 BOOST_AUTO_TEST_CASE( test_case4 )
119 {
120 onullstream_type null_output;
121 ut::test_suite* test = BOOST_TEST_SUITE( "" );
122
123 ut::unit_test_log.set_stream( null_output );
124 int test_data[] = { 1, 1, 1 };
125 test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
126
127 setup_tree( test );
128 ut::framework::run( test );
129 ut::test_results const& tr = ut::results_collector.results( test->p_id );
130
131 ut::unit_test_log.set_stream( std::cout );
132 BOOST_TEST( tr.p_assertions_failed == 3U );
133 BOOST_TEST( !tr.p_aborted );
134 }
135
136 //____________________________________________________________________________//
137
138 BOOST_AUTO_TEST_CASE( test_case5 )
139 {
140 onullstream_type null_output;
141 ut::test_suite* test = BOOST_TEST_SUITE( "" );
142
143 ut::unit_test_log.set_stream( null_output );
144 int test_data[] = { 6, 6, 6 };
145 test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
146
147 setup_tree( test );
148 ut::framework::run( test );
149 ut::test_results const& tr = ut::results_collector.results( test->p_id );
150
151 ut::unit_test_log.set_stream( std::cout );
152 BOOST_TEST( tr.p_assertions_failed == 3U );
153 BOOST_TEST( !tr.p_aborted );
154 BOOST_TEST( !tr.passed() );
155 }
156
157 //____________________________________________________________________________//
158
159 BOOST_AUTO_TEST_CASE( test_case6 )
160 {
161 onullstream_type null_output;
162 ut::test_suite* test = BOOST_TEST_SUITE( "" );
163
164 ut::unit_test_log.set_stream( null_output );
165 int test_data[] = { 0, 3, 9 };
166 test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
167
168 setup_tree( test );
169 ut::framework::run( test );
170 ut::test_results const& tr = ut::results_collector.results( test->p_id );
171
172 ut::unit_test_log.set_stream( std::cout );
173 BOOST_TEST( tr.p_assertions_failed == 5U );
174 BOOST_TEST( !tr.p_aborted );
175 }
176
177 //____________________________________________________________________________//
178
179 BOOST_AUTO_TEST_CASE( test_case7 )
180 {
181 onullstream_type null_output;
182 ut::test_suite* test = BOOST_TEST_SUITE( "" );
183
184 ut::unit_test_log.set_stream( null_output );
185 int test_data[] = { 2, 3, 9 };
186 test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
187
188 setup_tree( test );
189 ut::framework::run( test );
190 ut::test_results const& tr = ut::results_collector.results( test->p_id );
191
192 ut::unit_test_log.set_stream( std::cout );
193 BOOST_TEST( tr.p_assertions_failed == 4U );
194 BOOST_TEST( !tr.p_aborted );
195 }
196
197 //____________________________________________________________________________//
198
199 BOOST_AUTO_TEST_CASE( test_case8 )
200 {
201 onullstream_type null_output;
202 ut::test_suite* test = BOOST_TEST_SUITE( "" );
203
204 ut::unit_test_log.set_stream( null_output );
205 int test_data[] = { 3, 2, 6 };
206 test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
207
208 setup_tree( test );
209 ut::framework::run( test );
210 ut::test_results const& tr = ut::results_collector.results( test->p_id );
211
212 ut::unit_test_log.set_stream( std::cout );
213 BOOST_TEST( tr.p_assertions_failed == 3U );
214 BOOST_TEST( !tr.p_aborted );
215 }
216
217 //____________________________________________________________________________//
218
219 // EOF