1 | // (C) Copyright Gennadiy Rozental 2001-2005. |
---|
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: unit_test_suite.hpp,v $ |
---|
9 | // |
---|
10 | // Version : $Revision: 1.36 $ |
---|
11 | // |
---|
12 | // Description : defines Unit Test Framework public API |
---|
13 | // *************************************************************************** |
---|
14 | |
---|
15 | #ifndef BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER |
---|
16 | #define BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER |
---|
17 | |
---|
18 | // Boost.Test |
---|
19 | #include <boost/test/unit_test_suite_impl.hpp> |
---|
20 | |
---|
21 | //____________________________________________________________________________// |
---|
22 | |
---|
23 | // ************************************************************************** // |
---|
24 | // ************** Non-auto (explicit) test case interface ************** // |
---|
25 | // ************************************************************************** // |
---|
26 | |
---|
27 | #define BOOST_TEST_CASE( function ) \ |
---|
28 | boost::unit_test::make_test_case( boost::unit_test::callback0<>(function), BOOST_TEST_STRINGIZE( function ) ) |
---|
29 | #define BOOST_CLASS_TEST_CASE( function, tc_instance ) \ |
---|
30 | boost::unit_test::make_test_case((function), BOOST_TEST_STRINGIZE( function ), tc_instance ) |
---|
31 | |
---|
32 | // ************************************************************************** // |
---|
33 | // ************** BOOST_TEST_SUITE ************** // |
---|
34 | // ************************************************************************** // |
---|
35 | |
---|
36 | #define BOOST_TEST_SUITE( testsuite_name ) \ |
---|
37 | ( new boost::unit_test::test_suite( testsuite_name ) ) |
---|
38 | |
---|
39 | // ************************************************************************** // |
---|
40 | // ************** BOOST_AUTO_TEST_SUITE ************** // |
---|
41 | // ************************************************************************** // |
---|
42 | |
---|
43 | #define BOOST_AUTO_TEST_SUITE( suite_name ) \ |
---|
44 | namespace suite_name { \ |
---|
45 | BOOST_AUTO_TC_REGISTRAR( suite_name )( BOOST_TEST_SUITE( \ |
---|
46 | BOOST_STRINGIZE( suite_name ) ) ); \ |
---|
47 | /**/ |
---|
48 | |
---|
49 | // ************************************************************************** // |
---|
50 | // ************** BOOST_FIXTURE_TEST_SUITE ************** // |
---|
51 | // ************************************************************************** // |
---|
52 | |
---|
53 | #define BOOST_FIXTURE_TEST_SUITE( suite_name, F ) \ |
---|
54 | BOOST_AUTO_TEST_SUITE( suite_name ) \ |
---|
55 | typedef F BOOST_AUTO_TEST_CASE_FIXTURE; \ |
---|
56 | /**/ |
---|
57 | |
---|
58 | // ************************************************************************** // |
---|
59 | // ************** BOOST_AUTO_TEST_SUITE_END ************** // |
---|
60 | // ************************************************************************** // |
---|
61 | |
---|
62 | #define BOOST_AUTO_TEST_SUITE_END() \ |
---|
63 | BOOST_AUTO_TC_REGISTRAR( BOOST_JOIN( end_suite, __LINE__ ) )( 1 ); \ |
---|
64 | } \ |
---|
65 | /**/ |
---|
66 | |
---|
67 | // ************************************************************************** // |
---|
68 | // ************** BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES ************** // |
---|
69 | // ************************************************************************** // |
---|
70 | |
---|
71 | #define BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( test_name, n ) \ |
---|
72 | struct BOOST_AUTO_TC_UNIQUE_ID( test_name ); \ |
---|
73 | namespace boost { namespace unit_test { namespace ut_detail { \ |
---|
74 | \ |
---|
75 | template<> \ |
---|
76 | struct auto_tc_exp_fail<BOOST_AUTO_TC_UNIQUE_ID( test_name ) > { \ |
---|
77 | enum { value = n }; \ |
---|
78 | }; \ |
---|
79 | \ |
---|
80 | }}} \ |
---|
81 | /**/ |
---|
82 | |
---|
83 | // ************************************************************************** // |
---|
84 | // ************** BOOST_FIXTURE_TEST_CASE ************** // |
---|
85 | // ************************************************************************** // |
---|
86 | |
---|
87 | #define BOOST_FIXTURE_TEST_CASE( test_name, F ) \ |
---|
88 | struct test_name : public F { void test_method(); }; \ |
---|
89 | \ |
---|
90 | static void BOOST_AUTO_TC_INVOKER( test_name )() \ |
---|
91 | { \ |
---|
92 | test_name t; \ |
---|
93 | t.test_method(); \ |
---|
94 | } \ |
---|
95 | \ |
---|
96 | struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \ |
---|
97 | \ |
---|
98 | BOOST_AUTO_TC_REGISTRAR( test_name )( \ |
---|
99 | boost::unit_test::make_test_case( \ |
---|
100 | &BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \ |
---|
101 | boost::unit_test::ut_detail::auto_tc_exp_fail< \ |
---|
102 | BOOST_AUTO_TC_UNIQUE_ID( test_name )>::value ); \ |
---|
103 | \ |
---|
104 | void test_name::test_method() \ |
---|
105 | /**/ |
---|
106 | |
---|
107 | // ************************************************************************** // |
---|
108 | // ************** BOOST_AUTO_TEST_CASE ************** // |
---|
109 | // ************************************************************************** // |
---|
110 | |
---|
111 | #define BOOST_AUTO_TEST_CASE( test_name ) \ |
---|
112 | BOOST_FIXTURE_TEST_CASE( test_name, BOOST_AUTO_TEST_CASE_FIXTURE ) |
---|
113 | /**/ |
---|
114 | |
---|
115 | // ************************************************************************** // |
---|
116 | // ************** BOOST_AUTO_TEST_CASE_TEMPLATE ************** // |
---|
117 | // ************************************************************************** // |
---|
118 | |
---|
119 | #define BOOST_AUTO_TEST_CASE_TEMPLATE( test_name, type_name, TL ) \ |
---|
120 | template<typename type_name> \ |
---|
121 | struct test_name : public BOOST_AUTO_TEST_CASE_FIXTURE \ |
---|
122 | { void test_method(); }; \ |
---|
123 | \ |
---|
124 | struct BOOST_AUTO_TC_INVOKER( test_name ) { \ |
---|
125 | template<typename TestType> \ |
---|
126 | static void run( boost::type<TestType>* = 0 ) \ |
---|
127 | { \ |
---|
128 | test_name<TestType> t; \ |
---|
129 | t.test_method(); \ |
---|
130 | } \ |
---|
131 | }; \ |
---|
132 | \ |
---|
133 | BOOST_AUTO_TC_REGISTRAR( test_name )( \ |
---|
134 | boost::unit_test::ut_detail::template_test_case_gen< \ |
---|
135 | BOOST_AUTO_TC_INVOKER( test_name ),TL >( \ |
---|
136 | BOOST_STRINGIZE( test_name ) ) ); \ |
---|
137 | \ |
---|
138 | template<typename type_name> \ |
---|
139 | void test_name<type_name>::test_method() \ |
---|
140 | /**/ |
---|
141 | |
---|
142 | // ************************************************************************** // |
---|
143 | // ************** BOOST_GLOBAL_FIXURE ************** // |
---|
144 | // ************************************************************************** // |
---|
145 | |
---|
146 | #define BOOST_GLOBAL_FIXTURE( F ) \ |
---|
147 | static boost::unit_test::ut_detail::global_fixture_impl<F> BOOST_JOIN( gf_, F ) ; \ |
---|
148 | /**/ |
---|
149 | |
---|
150 | // ************************************************************************** // |
---|
151 | // ************** BOOST_AUTO_TEST_CASE_FIXTURE ************** // |
---|
152 | // ************************************************************************** // |
---|
153 | |
---|
154 | namespace boost { namespace unit_test { namespace ut_detail { |
---|
155 | |
---|
156 | struct nil_t {}; |
---|
157 | |
---|
158 | } // namespace ut_detail |
---|
159 | } // unit_test |
---|
160 | } // namespace boost |
---|
161 | |
---|
162 | // Intentionally is in global namespace, so that FIXURE_TEST_SUITE could reset it in user code. |
---|
163 | typedef ::boost::unit_test::ut_detail::nil_t BOOST_AUTO_TEST_CASE_FIXTURE; |
---|
164 | |
---|
165 | // ************************************************************************** // |
---|
166 | // ************** Auto registration facility helper macros ************** // |
---|
167 | // ************************************************************************** // |
---|
168 | |
---|
169 | #define BOOST_AUTO_TC_REGISTRAR( test_name ) \ |
---|
170 | static boost::unit_test::ut_detail::auto_test_unit_registrar BOOST_JOIN( test_name, _registrar ) |
---|
171 | #define BOOST_AUTO_TC_INVOKER( test_name ) BOOST_JOIN( test_name, _invoker ) |
---|
172 | #define BOOST_AUTO_TC_UNIQUE_ID( test_name ) BOOST_JOIN( test_name, _id ) |
---|
173 | |
---|
174 | // ************************************************************************** // |
---|
175 | // ************** BOOST_TEST_MAIN ************** // |
---|
176 | // ************************************************************************** // |
---|
177 | |
---|
178 | #if defined(BOOST_TEST_MAIN) |
---|
179 | |
---|
180 | #ifdef BOOST_TEST_ALTERNATIVE_INIT_API |
---|
181 | bool init_unit_test() { |
---|
182 | #else |
---|
183 | ::boost::unit_test::test_suite* |
---|
184 | init_unit_test_suite( int, char* [] ) { |
---|
185 | #endif |
---|
186 | |
---|
187 | #ifdef BOOST_TEST_MODULE |
---|
188 | using namespace ::boost::unit_test; |
---|
189 | assign_op( framework::master_test_suite().p_name.value, BOOST_TEST_STRINGIZE( BOOST_TEST_MODULE ).trim( "\"" ), 0 ); |
---|
190 | |
---|
191 | #endif |
---|
192 | |
---|
193 | #ifdef BOOST_TEST_ALTERNATIVE_INIT_API |
---|
194 | return true; |
---|
195 | } |
---|
196 | #else |
---|
197 | return 0; |
---|
198 | } |
---|
199 | #endif |
---|
200 | |
---|
201 | #endif |
---|
202 | |
---|
203 | //____________________________________________________________________________// |
---|
204 | |
---|
205 | // *************************************************************************** |
---|
206 | // Revision History : |
---|
207 | // |
---|
208 | // $Log: unit_test_suite.hpp,v $ |
---|
209 | // Revision 1.36 2006/03/19 12:23:21 rogeeff |
---|
210 | // eliminate warning |
---|
211 | // |
---|
212 | // Revision 1.35 2006/02/06 10:04:55 rogeeff |
---|
213 | // BOOST_TEST_MODULE - master test suite name |
---|
214 | // |
---|
215 | // Revision 1.34 2006/01/28 07:02:57 rogeeff |
---|
216 | // allow multiple global fixtures |
---|
217 | // |
---|
218 | // Revision 1.33 2005/12/14 05:24:55 rogeeff |
---|
219 | // dll support introduced |
---|
220 | // split into 2 files |
---|
221 | // |
---|
222 | // *************************************************************************** |
---|
223 | |
---|
224 | #endif // BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER |
---|
225 | |
---|