| | 1 | // (C) Copyright Gennadiy Rozental 2001-2008. |
| | 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: 54633 $ |
| | 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 | #include <boost/test/framework.hpp> |
| | 21 | |
| | 22 | //____________________________________________________________________________// |
| | 23 | |
| | 24 | // ************************************************************************** // |
| | 25 | // ************** Non-auto (explicit) test case interface ************** // |
| | 26 | // ************************************************************************** // |
| | 27 | |
| | 28 | #define BOOST_TEST_CASE( test_function ) \ |
| | 29 | boost::unit_test::make_test_case( boost::unit_test::callback0<>(test_function), BOOST_TEST_STRINGIZE( test_function ) ) |
| | 30 | #define BOOST_CLASS_TEST_CASE( test_function, tc_instance ) \ |
| | 31 | boost::unit_test::make_test_case((test_function), BOOST_TEST_STRINGIZE( test_function ), tc_instance ) |
| | 32 | |
| | 33 | // ************************************************************************** // |
| | 34 | // ************** BOOST_TEST_SUITE ************** // |
| | 35 | // ************************************************************************** // |
| | 36 | |
| | 37 | #define BOOST_TEST_SUITE( testsuite_name ) \ |
| | 38 | ( new boost::unit_test::test_suite( testsuite_name ) ) |
| | 39 | |
| | 40 | // ************************************************************************** // |
| | 41 | // ************** BOOST_AUTO_TEST_SUITE ************** // |
| | 42 | // ************************************************************************** // |
| | 43 | |
| | 44 | #define BOOST_AUTO_TEST_SUITE( suite_name ) \ |
| | 45 | namespace suite_name { \ |
| | 46 | BOOST_AUTO_TU_REGISTRAR( suite_name )( 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_TU_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 | \ |
| | 74 | static struct BOOST_JOIN( test_name, _exp_fail_num_spec ) \ |
| | 75 | : boost::unit_test::ut_detail:: \ |
| | 76 | auto_tc_exp_fail<BOOST_AUTO_TC_UNIQUE_ID( test_name ) > \ |
| | 77 | { \ |
| | 78 | BOOST_JOIN( test_name, _exp_fail_num_spec )() \ |
| | 79 | : boost::unit_test::ut_detail:: \ |
| | 80 | auto_tc_exp_fail<BOOST_AUTO_TC_UNIQUE_ID( test_name ) >( n ) \ |
| | 81 | {} \ |
| | 82 | } BOOST_JOIN( test_name, _exp_fail_num_spec_inst ); \ |
| | 83 | \ |
| | 84 | /**/ |
| | 85 | |
| | 86 | // ************************************************************************** // |
| | 87 | // ************** BOOST_FIXTURE_TEST_CASE ************** // |
| | 88 | // ************************************************************************** // |
| | 89 | |
| | 90 | #define BOOST_FIXTURE_TEST_CASE( test_name, F ) \ |
| | 91 | struct test_name : public F { void test_method(); }; \ |
| | 92 | \ |
| | 93 | static void BOOST_AUTO_TC_INVOKER( test_name )() \ |
| | 94 | { \ |
| | 95 | BOOST_TEST_CHECKPOINT( #test_name << " fixture " << #F << " entry.");\ |
| | 96 | test_name t; \ |
| | 97 | BOOST_TEST_CHECKPOINT( #test_name << " entry."); \ |
| | 98 | t.test_method(); \ |
| | 99 | BOOST_TEST_CHECKPOINT( #test_name << " exit."); \ |
| | 100 | } \ |
| | 101 | \ |
| | 102 | struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \ |
| | 103 | \ |
| | 104 | BOOST_AUTO_TU_REGISTRAR( test_name )( \ |
| | 105 | boost::unit_test::make_test_case( \ |
| | 106 | &BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \ |
| | 107 | boost::unit_test::ut_detail::auto_tc_exp_fail< \ |
| | 108 | BOOST_AUTO_TC_UNIQUE_ID( test_name )>::instance()->value() ); \ |
| | 109 | \ |
| | 110 | void test_name::test_method() \ |
| | 111 | /**/ |
| | 112 | |
| | 113 | // ************************************************************************** // |
| | 114 | // ************** BOOST_AUTO_TEST_CASE ************** // |
| | 115 | // ************************************************************************** // |
| | 116 | |
| | 117 | #define BOOST_AUTO_TEST_CASE( test_name ) \ |
| | 118 | BOOST_FIXTURE_TEST_CASE( test_name, BOOST_AUTO_TEST_CASE_FIXTURE ) |
| | 119 | /**/ |
| | 120 | |
| | 121 | // ************************************************************************** // |
| | 122 | // ************** BOOST_AUTO_TEST_CASE_TEMPLATE ************** // |
| | 123 | // ************************************************************************** // |
| | 124 | |
| | 125 | #define BOOST_AUTO_TEST_CASE_TEMPLATE( test_name, type_name, TL ) \ |
| | 126 | template<typename type_name> \ |
| | 127 | struct test_name : public BOOST_AUTO_TEST_CASE_FIXTURE \ |
| | 128 | { void test_method(); }; \ |
| | 129 | \ |
| | 130 | struct BOOST_AUTO_TC_INVOKER( test_name ) { \ |
| | 131 | template<typename TestType> \ |
| | 132 | static void run( boost::type<TestType>* = 0 ) \ |
| | 133 | { \ |
| | 134 | BOOST_TEST_CHECKPOINT( #test_name << " fixture entry."); \ |
| | 135 | test_name<TestType> t; \ |
| | 136 | BOOST_TEST_CHECKPOINT( #test_name << " entry."); \ |
| | 137 | t.test_method(); \ |
| | 138 | BOOST_TEST_CHECKPOINT( #test_name << " exit."); \ |
| | 139 | } \ |
| | 140 | }; \ |
| | 141 | \ |
| | 142 | BOOST_AUTO_TU_REGISTRAR( test_name )( \ |
| | 143 | boost::unit_test::ut_detail::template_test_case_gen< \ |
| | 144 | BOOST_AUTO_TC_INVOKER( test_name ),TL >( \ |
| | 145 | BOOST_STRINGIZE( test_name ) ) ); \ |
| | 146 | \ |
| | 147 | template<typename type_name> \ |
| | 148 | void test_name<type_name>::test_method() \ |
| | 149 | /**/ |
| | 150 | |
| | 151 | // ************************************************************************** // |
| | 152 | // ************** BOOST_TEST_CASE_TEMPLATE ************** // |
| | 153 | // ************************************************************************** // |
| | 154 | |
| | 155 | #define BOOST_TEST_CASE_TEMPLATE( name, typelist ) \ |
| | 156 | boost::unit_test::ut_detail::template_test_case_gen<name,typelist >( \ |
| | 157 | BOOST_TEST_STRINGIZE( name ) ) \ |
| | 158 | /**/ |
| | 159 | |
| | 160 | // ************************************************************************** // |
| | 161 | // ************** BOOST_TEST_CASE_TEMPLATE_FUNCTION ************** // |
| | 162 | // ************************************************************************** // |
| | 163 | |
| | 164 | #define BOOST_TEST_CASE_TEMPLATE_FUNCTION( name, type_name ) \ |
| | 165 | template<typename type_name> \ |
| | 166 | void BOOST_JOIN( name, _impl )( boost::type<type_name>* ); \ |
| | 167 | \ |
| | 168 | struct name { \ |
| | 169 | template<typename TestType> \ |
| | 170 | static void run( boost::type<TestType>* frwrd = 0 ) \ |
| | 171 | { \ |
| | 172 | BOOST_JOIN( name, _impl )( frwrd ); \ |
| | 173 | } \ |
| | 174 | }; \ |
| | 175 | \ |
| | 176 | template<typename type_name> \ |
| | 177 | void BOOST_JOIN( name, _impl )( boost::type<type_name>* ) \ |
| | 178 | /**/ |
| | 179 | |
| | 180 | // ************************************************************************** // |
| | 181 | // ************** BOOST_GLOBAL_FIXURE ************** // |
| | 182 | // ************************************************************************** // |
| | 183 | |
| | 184 | #define BOOST_GLOBAL_FIXTURE( F ) \ |
| | 185 | static boost::unit_test::ut_detail::global_fixture_impl<F> BOOST_JOIN( gf_, F ) ; \ |
| | 186 | /**/ |
| | 187 | |
| | 188 | // ************************************************************************** // |
| | 189 | // ************** BOOST_AUTO_TEST_CASE_FIXTURE ************** // |
| | 190 | // ************************************************************************** // |
| | 191 | |
| | 192 | namespace boost { namespace unit_test { namespace ut_detail { |
| | 193 | |
| | 194 | struct nil_t {}; |
| | 195 | |
| | 196 | } // namespace ut_detail |
| | 197 | } // unit_test |
| | 198 | } // namespace boost |
| | 199 | |
| | 200 | // Intentionally is in global namespace, so that FIXURE_TEST_SUITE can reset it in user code. |
| | 201 | typedef ::boost::unit_test::ut_detail::nil_t BOOST_AUTO_TEST_CASE_FIXTURE; |
| | 202 | |
| | 203 | // ************************************************************************** // |
| | 204 | // ************** Auto registration facility helper macros ************** // |
| | 205 | // ************************************************************************** // |
| | 206 | |
| | 207 | #define BOOST_AUTO_TU_REGISTRAR( test_name ) \ |
| | 208 | static boost::unit_test::ut_detail::auto_test_unit_registrar BOOST_JOIN( BOOST_JOIN( test_name, _registrar ), __LINE__ ) |
| | 209 | #define BOOST_AUTO_TC_INVOKER( test_name ) BOOST_JOIN( test_name, _invoker ) |
| | 210 | #define BOOST_AUTO_TC_UNIQUE_ID( test_name ) BOOST_JOIN( test_name, _id ) |
| | 211 | |
| | 212 | // ************************************************************************** // |
| | 213 | // ************** BOOST_TEST_MAIN ************** // |
| | 214 | // ************************************************************************** // |
| | 215 | |
| | 216 | #if defined(BOOST_TEST_MAIN) |
| | 217 | |
| | 218 | #ifdef BOOST_TEST_ALTERNATIVE_INIT_API |
| | 219 | bool init_unit_test() { |
| | 220 | #else |
| | 221 | ::boost::unit_test::test_suite* |
| | 222 | init_unit_test_suite( int, char* [] ) { |
| | 223 | #endif |
| | 224 | |
| | 225 | #ifdef BOOST_TEST_MODULE |
| | 226 | using namespace ::boost::unit_test; |
| | 227 | assign_op( framework::master_test_suite().p_name.value, BOOST_TEST_STRINGIZE( BOOST_TEST_MODULE ).trim( "\"" ), 0 ); |
| | 228 | |
| | 229 | #endif |
| | 230 | |
| | 231 | #ifdef BOOST_TEST_ALTERNATIVE_INIT_API |
| | 232 | return true; |
| | 233 | } |
| | 234 | #else |
| | 235 | return 0; |
| | 236 | } |
| | 237 | #endif |
| | 238 | |
| | 239 | #endif |
| | 240 | |
| | 241 | //____________________________________________________________________________// |
| | 242 | |
| | 243 | #endif // BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER |
| | 244 | |