unit_test_suite.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision: 57992 $
  10. //
  11. // Description : defines Unit Test Framework public API
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER
  14. #define BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER
  15. // Boost.Test
  16. #include <boost/test/unit_test_suite_impl.hpp>
  17. #include <boost/test/framework.hpp>
  18. //____________________________________________________________________________//
  19. // ************************************************************************** //
  20. // ************** Non-auto (explicit) test case interface ************** //
  21. // ************************************************************************** //
  22. #define BOOST_TEST_CASE( test_function ) \
  23. boost::unit_test::make_test_case( boost::unit_test::callback0<>(test_function), BOOST_TEST_STRINGIZE( test_function ) )
  24. #define BOOST_CLASS_TEST_CASE( test_function, tc_instance ) \
  25. boost::unit_test::make_test_case((test_function), BOOST_TEST_STRINGIZE( test_function ), tc_instance )
  26. // ************************************************************************** //
  27. // ************** BOOST_TEST_SUITE ************** //
  28. // ************************************************************************** //
  29. #define BOOST_TEST_SUITE( testsuite_name ) \
  30. ( new boost::unit_test::test_suite( testsuite_name ) )
  31. // ************************************************************************** //
  32. // ************** BOOST_AUTO_TEST_SUITE ************** //
  33. // ************************************************************************** //
  34. #define BOOST_AUTO_TEST_SUITE( suite_name ) \
  35. namespace suite_name { \
  36. BOOST_AUTO_TU_REGISTRAR( suite_name )( BOOST_STRINGIZE( suite_name ) ); \
  37. /**/
  38. // ************************************************************************** //
  39. // ************** BOOST_FIXTURE_TEST_SUITE ************** //
  40. // ************************************************************************** //
  41. #define BOOST_FIXTURE_TEST_SUITE( suite_name, F ) \
  42. BOOST_AUTO_TEST_SUITE( suite_name ) \
  43. typedef F BOOST_AUTO_TEST_CASE_FIXTURE; \
  44. /**/
  45. // ************************************************************************** //
  46. // ************** BOOST_AUTO_TEST_SUITE_END ************** //
  47. // ************************************************************************** //
  48. #define BOOST_AUTO_TEST_SUITE_END() \
  49. BOOST_AUTO_TU_REGISTRAR( BOOST_JOIN( end_suite, __LINE__ ) )( 1 ); \
  50. } \
  51. /**/
  52. // ************************************************************************** //
  53. // ************** BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES ************** //
  54. // ************************************************************************** //
  55. #define BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( test_name, n ) \
  56. struct BOOST_AUTO_TC_UNIQUE_ID( test_name ); \
  57. \
  58. static struct BOOST_JOIN( test_name, _exp_fail_num_spec ) \
  59. : boost::unit_test::ut_detail:: \
  60. auto_tc_exp_fail<BOOST_AUTO_TC_UNIQUE_ID( test_name ) > \
  61. { \
  62. BOOST_JOIN( test_name, _exp_fail_num_spec )() \
  63. : boost::unit_test::ut_detail:: \
  64. auto_tc_exp_fail<BOOST_AUTO_TC_UNIQUE_ID( test_name ) >( n ) \
  65. {} \
  66. } BOOST_JOIN( test_name, _exp_fail_num_spec_inst ); \
  67. \
  68. /**/
  69. // ************************************************************************** //
  70. // ************** BOOST_FIXTURE_TEST_CASE ************** //
  71. // ************************************************************************** //
  72. #define BOOST_FIXTURE_TEST_CASE( test_name, F ) \
  73. struct test_name : public F { void test_method(); }; \
  74. \
  75. static void BOOST_AUTO_TC_INVOKER( test_name )() \
  76. { \
  77. test_name t; \
  78. t.test_method(); \
  79. } \
  80. \
  81. struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
  82. \
  83. BOOST_AUTO_TU_REGISTRAR( test_name )( \
  84. boost::unit_test::make_test_case( \
  85. &BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \
  86. boost::unit_test::ut_detail::auto_tc_exp_fail< \
  87. BOOST_AUTO_TC_UNIQUE_ID( test_name )>::instance()->value() ); \
  88. \
  89. void test_name::test_method() \
  90. /**/
  91. // ************************************************************************** //
  92. // ************** BOOST_AUTO_TEST_CASE ************** //
  93. // ************************************************************************** //
  94. #define BOOST_AUTO_TEST_CASE( test_name ) \
  95. BOOST_FIXTURE_TEST_CASE( test_name, BOOST_AUTO_TEST_CASE_FIXTURE )
  96. /**/
  97. // ************************************************************************** //
  98. // ************** BOOST_FIXTURE_TEST_CASE_TEMPLATE ************** //
  99. // ************************************************************************** //
  100. #define BOOST_FIXTURE_TEST_CASE_TEMPLATE( test_name, type_name, TL, F ) \
  101. template<typename type_name> \
  102. struct test_name : public F \
  103. { void test_method(); }; \
  104. \
  105. struct BOOST_AUTO_TC_INVOKER( test_name ) { \
  106. template<typename TestType> \
  107. static void run( boost::type<TestType>* = 0 ) \
  108. { \
  109. test_name<TestType> t; \
  110. t.test_method(); \
  111. } \
  112. }; \
  113. \
  114. BOOST_AUTO_TU_REGISTRAR( test_name )( \
  115. boost::unit_test::ut_detail::template_test_case_gen< \
  116. BOOST_AUTO_TC_INVOKER( test_name ),TL >( \
  117. BOOST_STRINGIZE( test_name ) ) ); \
  118. \
  119. template<typename type_name> \
  120. void test_name<type_name>::test_method() \
  121. /**/
  122. // ************************************************************************** //
  123. // ************** BOOST_AUTO_TEST_CASE_TEMPLATE ************** //
  124. // ************************************************************************** //
  125. #define BOOST_AUTO_TEST_CASE_TEMPLATE( test_name, type_name, TL ) \
  126. BOOST_FIXTURE_TEST_CASE_TEMPLATE( test_name, type_name, TL, BOOST_AUTO_TEST_CASE_FIXTURE )
  127. // ************************************************************************** //
  128. // ************** BOOST_TEST_CASE_TEMPLATE ************** //
  129. // ************************************************************************** //
  130. #define BOOST_TEST_CASE_TEMPLATE( name, typelist ) \
  131. boost::unit_test::ut_detail::template_test_case_gen<name,typelist >( \
  132. BOOST_TEST_STRINGIZE( name ) ) \
  133. /**/
  134. // ************************************************************************** //
  135. // ************** BOOST_TEST_CASE_TEMPLATE_FUNCTION ************** //
  136. // ************************************************************************** //
  137. #define BOOST_TEST_CASE_TEMPLATE_FUNCTION( name, type_name ) \
  138. template<typename type_name> \
  139. void BOOST_JOIN( name, _impl )( boost::type<type_name>* ); \
  140. \
  141. struct name { \
  142. template<typename TestType> \
  143. static void run( boost::type<TestType>* frwrd = 0 ) \
  144. { \
  145. BOOST_JOIN( name, _impl )( frwrd ); \
  146. } \
  147. }; \
  148. \
  149. template<typename type_name> \
  150. void BOOST_JOIN( name, _impl )( boost::type<type_name>* ) \
  151. /**/
  152. // ************************************************************************** //
  153. // ************** BOOST_GLOBAL_FIXURE ************** //
  154. // ************************************************************************** //
  155. #define BOOST_GLOBAL_FIXTURE( F ) \
  156. static boost::unit_test::ut_detail::global_fixture_impl<F> BOOST_JOIN( gf_, F ) ; \
  157. /**/
  158. // ************************************************************************** //
  159. // ************** BOOST_AUTO_TEST_CASE_FIXTURE ************** //
  160. // ************************************************************************** //
  161. namespace boost { namespace unit_test { namespace ut_detail {
  162. struct nil_t {};
  163. } // namespace ut_detail
  164. } // unit_test
  165. } // namespace boost
  166. // Intentionally is in global namespace, so that FIXURE_TEST_SUITE can reset it in user code.
  167. typedef ::boost::unit_test::ut_detail::nil_t BOOST_AUTO_TEST_CASE_FIXTURE;
  168. // ************************************************************************** //
  169. // ************** Auto registration facility helper macros ************** //
  170. // ************************************************************************** //
  171. #define BOOST_AUTO_TU_REGISTRAR( test_name ) \
  172. static boost::unit_test::ut_detail::auto_test_unit_registrar BOOST_JOIN( BOOST_JOIN( test_name, _registrar ), __LINE__ )
  173. #define BOOST_AUTO_TC_INVOKER( test_name ) BOOST_JOIN( test_name, _invoker )
  174. #define BOOST_AUTO_TC_UNIQUE_ID( test_name ) BOOST_JOIN( test_name, _id )
  175. // ************************************************************************** //
  176. // ************** BOOST_TEST_MAIN ************** //
  177. // ************************************************************************** //
  178. #if defined(BOOST_TEST_MAIN)
  179. #ifdef BOOST_TEST_ALTERNATIVE_INIT_API
  180. bool init_unit_test() {
  181. #else
  182. ::boost::unit_test::test_suite*
  183. init_unit_test_suite( int, char* [] ) {
  184. #endif
  185. #ifdef BOOST_TEST_MODULE
  186. using namespace ::boost::unit_test;
  187. assign_op( framework::master_test_suite().p_name.value, BOOST_TEST_STRINGIZE( BOOST_TEST_MODULE ).trim( "\"" ), 0 );
  188. #endif
  189. #ifdef BOOST_TEST_ALTERNATIVE_INIT_API
  190. return true;
  191. }
  192. #else
  193. return 0;
  194. }
  195. #endif
  196. #endif
  197. //____________________________________________________________________________//
  198. #endif // BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER