interface.hpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. // (C) Copyright Gennadiy Rozental 2001.
  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: 81247 $
  10. //
  11. // Description : contains definition for all test tools in old test toolbox
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_TOOLS_OLD_INTERFACE_HPP_111712GER
  14. #define BOOST_TEST_TOOLS_OLD_INTERFACE_HPP_111712GER
  15. // Boost
  16. #include <boost/preprocessor/seq/for_each.hpp>
  17. #include <boost/preprocessor/seq/size.hpp>
  18. #include <boost/preprocessor/seq/to_tuple.hpp>
  19. #include <boost/core/ignore_unused.hpp>
  20. #include <boost/test/detail/suppress_warnings.hpp>
  21. //____________________________________________________________________________//
  22. // ************************************************************************** //
  23. // ************** TOOL BOX ************** //
  24. // ************************************************************************** //
  25. // In macros below following argument abbreviations are used:
  26. // P - predicate
  27. // M - message
  28. // S - statement
  29. // E - exception
  30. // L - left argument
  31. // R - right argument
  32. // TL - tool level
  33. // CT - check type
  34. // ARGS - arguments list (as PP sequence)
  35. // frwd_type:
  36. // 0 - args exists and need to be forwarded; call check_frwd
  37. // 1 - args exists, but do not need to be forwarded; call report_assertion directly
  38. // 2 - no arguments; call report_assertion directly
  39. #define BOOST_TEST_TOOL_PASS_PRED0( P, ARGS ) P
  40. #define BOOST_TEST_TOOL_PASS_PRED1( P, ARGS ) P BOOST_PP_SEQ_TO_TUPLE(ARGS)
  41. #define BOOST_TEST_TOOL_PASS_PRED2( P, ARGS ) P
  42. #define BOOST_TEST_TOOL_PASS_ARG( r, _, arg ) , arg, BOOST_STRINGIZE( arg )
  43. #define BOOST_TEST_TOOL_PASS_ARG_DSCR( r, _, arg ) , BOOST_STRINGIZE( arg )
  44. #define BOOST_TEST_TOOL_PASS_ARGS0( ARGS ) \
  45. BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_TOOL_PASS_ARG, _, ARGS )
  46. #define BOOST_TEST_TOOL_PASS_ARGS1( ARGS ) \
  47. , BOOST_PP_SEQ_SIZE(ARGS) BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_TOOL_PASS_ARG_DSCR, _, ARGS )
  48. #define BOOST_TEST_TOOL_PASS_ARGS2( ARGS ) \
  49. , 0
  50. #define BOOST_TEST_TOOL_IMPL( frwd_type, P, assertion_descr, TL, CT, ARGS ) \
  51. do { \
  52. BOOST_TEST_PASSPOINT(); \
  53. ::boost::test_tools::tt_detail:: \
  54. BOOST_PP_IF( frwd_type, report_assertion, check_frwd ) ( \
  55. BOOST_JOIN( BOOST_TEST_TOOL_PASS_PRED, frwd_type )( P, ARGS ), \
  56. BOOST_TEST_LAZY_MSG( assertion_descr ), \
  57. BOOST_TEST_L(__FILE__), \
  58. static_cast<std::size_t>(__LINE__), \
  59. ::boost::test_tools::tt_detail::TL, \
  60. ::boost::test_tools::tt_detail::CT \
  61. BOOST_JOIN( BOOST_TEST_TOOL_PASS_ARGS, frwd_type )( ARGS ) ); \
  62. } while( ::boost::test_tools::tt_detail::dummy_cond() ) \
  63. /**/
  64. //____________________________________________________________________________//
  65. #define BOOST_WARN( P ) BOOST_TEST_TOOL_IMPL( 2, \
  66. (P), BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED, _ )
  67. #define BOOST_CHECK( P ) BOOST_TEST_TOOL_IMPL( 2, \
  68. (P), BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED, _ )
  69. #define BOOST_REQUIRE( P ) BOOST_TEST_TOOL_IMPL( 2, \
  70. (P), BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED, _ )
  71. //____________________________________________________________________________//
  72. #define BOOST_WARN_MESSAGE( P, M ) BOOST_TEST_TOOL_IMPL( 2, (P), M, WARN, CHECK_MSG, _ )
  73. #define BOOST_CHECK_MESSAGE( P, M ) BOOST_TEST_TOOL_IMPL( 2, (P), M, CHECK, CHECK_MSG, _ )
  74. #define BOOST_REQUIRE_MESSAGE( P, M ) BOOST_TEST_TOOL_IMPL( 2, (P), M, REQUIRE, CHECK_MSG, _ )
  75. //____________________________________________________________________________//
  76. #define BOOST_ERROR( M ) BOOST_CHECK_MESSAGE( false, M )
  77. #define BOOST_FAIL( M ) BOOST_REQUIRE_MESSAGE( false, M )
  78. //____________________________________________________________________________//
  79. #define BOOST_CHECK_THROW_IMPL( S, E, P, postfix, TL ) \
  80. do { \
  81. try { \
  82. BOOST_TEST_PASSPOINT(); \
  83. S; \
  84. BOOST_TEST_TOOL_IMPL( 2, false, "exception " BOOST_STRINGIZE(E) " expected but not raised", \
  85. TL, CHECK_MSG, _ ); \
  86. } catch( E const& ex ) { \
  87. boost::ignore_unused( ex ); \
  88. BOOST_TEST_TOOL_IMPL( 2, P, \
  89. "exception \"" BOOST_STRINGIZE( E )"\" raised as expected" postfix, \
  90. TL, CHECK_MSG, _ ); \
  91. } \
  92. } while( ::boost::test_tools::tt_detail::dummy_cond() ) \
  93. /**/
  94. //____________________________________________________________________________//
  95. #define BOOST_WARN_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "", WARN )
  96. #define BOOST_CHECK_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "", CHECK )
  97. #define BOOST_REQUIRE_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "", REQUIRE )
  98. //____________________________________________________________________________//
  99. #define BOOST_WARN_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), \
  100. ": validation on the raised exception through predicate \"" BOOST_STRINGIZE(P) "\"", WARN )
  101. #define BOOST_CHECK_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), \
  102. ": validation on the raised exception through predicate \"" BOOST_STRINGIZE(P) "\"", CHECK )
  103. #define BOOST_REQUIRE_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), \
  104. ": validation on the raised exception through predicate \"" BOOST_STRINGIZE(P) "\"", REQUIRE )
  105. //____________________________________________________________________________//
  106. #define BOOST_CHECK_NO_THROW_IMPL( S, TL ) \
  107. do { \
  108. try { \
  109. S; \
  110. BOOST_TEST_TOOL_IMPL( 2, true, "no exceptions thrown by " BOOST_STRINGIZE( S ), \
  111. TL, CHECK_MSG, _ ); \
  112. } catch( ... ) { \
  113. BOOST_TEST_TOOL_IMPL( 2, false, "unexpected exception thrown by " BOOST_STRINGIZE( S ), \
  114. TL, CHECK_MSG, _ ); \
  115. } \
  116. } while( ::boost::test_tools::tt_detail::dummy_cond() ) \
  117. /**/
  118. #define BOOST_WARN_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, WARN )
  119. #define BOOST_CHECK_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, CHECK )
  120. #define BOOST_REQUIRE_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, REQUIRE )
  121. //____________________________________________________________________________//
  122. #define BOOST_WARN_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  123. ::boost::test_tools::tt_detail::equal_impl_frwd(), "", WARN, CHECK_EQUAL, (L)(R) )
  124. #define BOOST_CHECK_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  125. ::boost::test_tools::tt_detail::equal_impl_frwd(), "", CHECK, CHECK_EQUAL, (L)(R) )
  126. #define BOOST_REQUIRE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  127. ::boost::test_tools::tt_detail::equal_impl_frwd(), "", REQUIRE, CHECK_EQUAL, (L)(R) )
  128. //____________________________________________________________________________//
  129. #define BOOST_WARN_NE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  130. ::boost::test_tools::tt_detail::ne_impl(), "", WARN, CHECK_NE, (L)(R) )
  131. #define BOOST_CHECK_NE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  132. ::boost::test_tools::tt_detail::ne_impl(), "", CHECK, CHECK_NE, (L)(R) )
  133. #define BOOST_REQUIRE_NE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  134. ::boost::test_tools::tt_detail::ne_impl(), "", REQUIRE, CHECK_NE, (L)(R) )
  135. //____________________________________________________________________________//
  136. #define BOOST_WARN_LT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  137. ::boost::test_tools::tt_detail::lt_impl(), "", WARN, CHECK_LT, (L)(R) )
  138. #define BOOST_CHECK_LT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  139. ::boost::test_tools::tt_detail::lt_impl(), "", CHECK, CHECK_LT, (L)(R) )
  140. #define BOOST_REQUIRE_LT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  141. ::boost::test_tools::tt_detail::lt_impl(), "", REQUIRE, CHECK_LT, (L)(R) )
  142. //____________________________________________________________________________//
  143. #define BOOST_WARN_LE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  144. ::boost::test_tools::tt_detail::le_impl(), "", WARN, CHECK_LE, (L)(R) )
  145. #define BOOST_CHECK_LE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  146. ::boost::test_tools::tt_detail::le_impl(), "", CHECK, CHECK_LE, (L)(R) )
  147. #define BOOST_REQUIRE_LE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  148. ::boost::test_tools::tt_detail::le_impl(), "", REQUIRE, CHECK_LE, (L)(R) )
  149. //____________________________________________________________________________//
  150. #define BOOST_WARN_GT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  151. ::boost::test_tools::tt_detail::gt_impl(), "", WARN, CHECK_GT, (L)(R) )
  152. #define BOOST_CHECK_GT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  153. ::boost::test_tools::tt_detail::gt_impl(), "", CHECK, CHECK_GT, (L)(R) )
  154. #define BOOST_REQUIRE_GT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  155. ::boost::test_tools::tt_detail::gt_impl(), "", REQUIRE, CHECK_GT, (L)(R) )
  156. //____________________________________________________________________________//
  157. #define BOOST_WARN_GE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  158. ::boost::test_tools::tt_detail::ge_impl(), "", WARN, CHECK_GE, (L)(R) )
  159. #define BOOST_CHECK_GE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  160. ::boost::test_tools::tt_detail::ge_impl(), "", CHECK, CHECK_GE, (L)(R) )
  161. #define BOOST_REQUIRE_GE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
  162. ::boost::test_tools::tt_detail::ge_impl(), "", REQUIRE, CHECK_GE, (L)(R) )
  163. //____________________________________________________________________________//
  164. #define BOOST_WARN_CLOSE( L, R, T ) BOOST_TEST_TOOL_IMPL( 0, \
  165. ::boost::test_tools::check_is_close_t(), "", WARN, CHECK_CLOSE, (L)(R)(::boost::math::fpc::percent_tolerance(T)) )
  166. #define BOOST_CHECK_CLOSE( L, R, T ) BOOST_TEST_TOOL_IMPL( 0, \
  167. ::boost::test_tools::check_is_close_t(), "", CHECK, CHECK_CLOSE, (L)(R)(::boost::math::fpc::percent_tolerance(T)) )
  168. #define BOOST_REQUIRE_CLOSE( L, R, T ) BOOST_TEST_TOOL_IMPL( 0, \
  169. ::boost::test_tools::check_is_close_t(), "", REQUIRE, CHECK_CLOSE, (L)(R)(::boost::math::fpc::percent_tolerance(T)) )
  170. //____________________________________________________________________________//
  171. #define BOOST_WARN_CLOSE_FRACTION(L, R, T) BOOST_TEST_TOOL_IMPL( 0, \
  172. ::boost::test_tools::check_is_close_t(), "", WARN, CHECK_CLOSE_FRACTION, (L)(R)(T) )
  173. #define BOOST_CHECK_CLOSE_FRACTION(L, R, T) BOOST_TEST_TOOL_IMPL( 0, \
  174. ::boost::test_tools::check_is_close_t(), "", CHECK, CHECK_CLOSE_FRACTION, (L)(R)(T) )
  175. #define BOOST_REQUIRE_CLOSE_FRACTION(L,R,T) BOOST_TEST_TOOL_IMPL( 0, \
  176. ::boost::test_tools::check_is_close_t(), "", REQUIRE, CHECK_CLOSE_FRACTION, (L)(R)(T) )
  177. //____________________________________________________________________________//
  178. #define BOOST_WARN_SMALL( FPV, T ) BOOST_TEST_TOOL_IMPL( 0, \
  179. ::boost::test_tools::check_is_small_t(), "", WARN, CHECK_SMALL, (FPV)(T) )
  180. #define BOOST_CHECK_SMALL( FPV, T ) BOOST_TEST_TOOL_IMPL( 0, \
  181. ::boost::test_tools::check_is_small_t(), "", CHECK, CHECK_SMALL, (FPV)(T) )
  182. #define BOOST_REQUIRE_SMALL( FPV, T ) BOOST_TEST_TOOL_IMPL( 0, \
  183. ::boost::test_tools::check_is_small_t(), "", REQUIRE, CHECK_SMALL, (FPV)(T) )
  184. //____________________________________________________________________________//
  185. #define BOOST_WARN_PREDICATE( P, ARGS ) BOOST_TEST_TOOL_IMPL( 0, \
  186. P, BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED_WITH_ARGS, ARGS )
  187. #define BOOST_CHECK_PREDICATE( P, ARGS ) BOOST_TEST_TOOL_IMPL( 0, \
  188. P, BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED_WITH_ARGS, ARGS )
  189. #define BOOST_REQUIRE_PREDICATE( P, ARGS ) BOOST_TEST_TOOL_IMPL( 0, \
  190. P, BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED_WITH_ARGS, ARGS )
  191. //____________________________________________________________________________//
  192. #define BOOST_WARN_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
  193. BOOST_TEST_TOOL_IMPL( 1, ::boost::test_tools::tt_detail::equal_coll_impl(), \
  194. "", WARN, CHECK_EQUAL_COLL, (L_begin)(L_end)(R_begin)(R_end) ) \
  195. /**/
  196. #define BOOST_CHECK_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
  197. BOOST_TEST_TOOL_IMPL( 1, ::boost::test_tools::tt_detail::equal_coll_impl(), \
  198. "", CHECK, CHECK_EQUAL_COLL, (L_begin)(L_end)(R_begin)(R_end) ) \
  199. /**/
  200. #define BOOST_REQUIRE_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
  201. BOOST_TEST_TOOL_IMPL( 1, ::boost::test_tools::tt_detail::equal_coll_impl(), \
  202. "", REQUIRE, CHECK_EQUAL_COLL, (L_begin)(L_end)(R_begin)(R_end) ) \
  203. /**/
  204. //____________________________________________________________________________//
  205. #define BOOST_WARN_BITWISE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 1, \
  206. ::boost::test_tools::tt_detail::bitwise_equal_impl(), "", WARN, CHECK_BITWISE_EQUAL, (L)(R) )
  207. #define BOOST_CHECK_BITWISE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 1, \
  208. ::boost::test_tools::tt_detail::bitwise_equal_impl(), "", CHECK, CHECK_BITWISE_EQUAL, (L)(R) )
  209. #define BOOST_REQUIRE_BITWISE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 1, \
  210. ::boost::test_tools::tt_detail::bitwise_equal_impl(), "", REQUIRE, CHECK_BITWISE_EQUAL, (L)(R) )
  211. //____________________________________________________________________________//
  212. #define BOOST_IS_DEFINED( symb ) ::boost::test_tools::tt_detail::is_defined_impl( #symb, BOOST_STRINGIZE(= symb) )
  213. //____________________________________________________________________________//
  214. #ifdef BOOST_TEST_NO_NEW_TOOLS
  215. #define BOOST_TEST_WARN( P ) BOOST_WARN( P )
  216. #define BOOST_TEST_CHECK( P ) BOOST_CHECK( P )
  217. #define BOOST_TEST_REQUIRE( P ) BOOST_REQUIRE( P )
  218. #define BOOST_TEST( P ) BOOST_CHECK( P )
  219. #endif
  220. //____________________________________________________________________________//
  221. #include <boost/test/detail/enable_warnings.hpp>
  222. #endif // BOOST_TEST_TOOLS_OLD_INTERFACE_HPP_111712GER