interface.hpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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 test toolbox
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_TOOLS_INTERFACE_HPP_111712GER
  14. #define BOOST_TEST_TOOLS_INTERFACE_HPP_111712GER
  15. // Boost.Test
  16. #include <boost/test/unit_test_log.hpp>
  17. #ifdef BOOST_TEST_TOOLS_DEBUGGABLE
  18. #include <boost/test/debug.hpp>
  19. #endif
  20. #include <boost/test/detail/pp_variadic.hpp>
  21. #ifdef BOOST_TEST_NO_OLD_TOOLS
  22. #include <boost/preprocessor/seq/to_tuple.hpp>
  23. #include <iterator>
  24. #endif // BOOST_TEST_NO_OLD_TOOLS
  25. #include <boost/test/detail/suppress_warnings.hpp>
  26. //____________________________________________________________________________//
  27. // ************************************************************************** //
  28. // ************** BOOST_TEST_<level> ************** //
  29. // ************************************************************************** //
  30. #define BOOST_TEST_BUILD_ASSERTION( P ) \
  31. (::boost::test_tools::assertion::seed()->*P) \
  32. /**/
  33. //____________________________________________________________________________//
  34. // Implementation based on direct predicate evaluation
  35. #define BOOST_TEST_TOOL_DIRECT_IMPL( P, level, M ) \
  36. do { \
  37. ::boost::test_tools::assertion_result res = (P); \
  38. report_assertion( \
  39. res, \
  40. BOOST_TEST_LAZY_MSG( M ), \
  41. BOOST_TEST_L(__FILE__), \
  42. static_cast<std::size_t>(__LINE__), \
  43. ::boost::test_tools::tt_detail::level, \
  44. ::boost::test_tools::tt_detail::CHECK_MSG, \
  45. 0 ); \
  46. } while( ::boost::test_tools::tt_detail::dummy_cond() ) \
  47. /**/
  48. //____________________________________________________________________________//
  49. // Implementation based on expression template construction
  50. #define BOOST_TEST_TOOL_ET_IMPL( P, level ) \
  51. do { \
  52. BOOST_TEST_PASSPOINT(); \
  53. \
  54. ::boost::test_tools::tt_detail:: \
  55. report_assertion( \
  56. BOOST_TEST_BUILD_ASSERTION( P ).evaluate(), \
  57. BOOST_TEST_LAZY_MSG( BOOST_TEST_STRINGIZE( P ) ), \
  58. BOOST_TEST_L(__FILE__), \
  59. static_cast<std::size_t>(__LINE__), \
  60. ::boost::test_tools::tt_detail::level, \
  61. ::boost::test_tools::tt_detail::CHECK_BUILT_ASSERTION, \
  62. 0 ); \
  63. } while( ::boost::test_tools::tt_detail::dummy_cond() ) \
  64. /**/
  65. //____________________________________________________________________________//
  66. // Implementation based on expression template construction with extra tool arguments
  67. #define BOOST_TEST_TOOL_ET_IMPL_EX( P, level, arg ) \
  68. do { \
  69. BOOST_TEST_PASSPOINT(); \
  70. \
  71. ::boost::test_tools::tt_detail:: \
  72. report_assertion( \
  73. ::boost::test_tools::tt_detail::assertion_evaluate( \
  74. BOOST_TEST_BUILD_ASSERTION( P ) ) \
  75. << arg, \
  76. ::boost::test_tools::tt_detail::assertion_text( \
  77. BOOST_TEST_LAZY_MSG( BOOST_TEST_STRINGIZE(P) ), \
  78. BOOST_TEST_LAZY_MSG( arg ) ), \
  79. BOOST_TEST_L(__FILE__), \
  80. static_cast<std::size_t>(__LINE__), \
  81. ::boost::test_tools::tt_detail::level, \
  82. ::boost::test_tools::tt_detail::assertion_type() \
  83. << arg, \
  84. 0 ); \
  85. } while( ::boost::test_tools::tt_detail::dummy_cond() ) \
  86. /**/
  87. //____________________________________________________________________________//
  88. #ifdef BOOST_TEST_TOOLS_UNDER_DEBUGGER
  89. #define BOOST_TEST_TOOL_UNIV( level, P ) \
  90. BOOST_TEST_TOOL_DIRECT_IMPL( P, level, BOOST_TEST_STRINGIZE( P ) ) \
  91. /**/
  92. #define BOOST_TEST_TOOL_UNIV_EX( level, P, ... ) \
  93. BOOST_TEST_TOOL_UNIV( level, P ) \
  94. /**/
  95. #elif defined(BOOST_TEST_TOOLS_DEBUGGABLE)
  96. #define BOOST_TEST_TOOL_UNIV( level, P ) \
  97. do { \
  98. if( ::boost::debug::under_debugger() ) \
  99. BOOST_TEST_TOOL_DIRECT_IMPL( P, level, BOOST_TEST_STRINGIZE( P ) ); \
  100. else \
  101. BOOST_TEST_TOOL_ET_IMPL( P, level ); \
  102. } while( ::boost::test_tools::tt_detail::dummy_cond() ) \
  103. /**/
  104. #define BOOST_TEST_TOOL_UNIV_EX( level, P, ... ) \
  105. BOOST_TEST_TOOL_UNIV( level, P ) \
  106. /**/
  107. #else
  108. #define BOOST_TEST_TOOL_UNIV( level, P ) \
  109. BOOST_TEST_TOOL_ET_IMPL( P, level ) \
  110. /**/
  111. #define BOOST_TEST_TOOL_UNIV_EX( level, P, ... ) \
  112. BOOST_TEST_TOOL_ET_IMPL_EX( P, level, __VA_ARGS__ ) \
  113. /**/
  114. #endif
  115. //____________________________________________________________________________//
  116. #define BOOST_TEST_WARN( ... ) BOOST_TEST_INVOKE_IF_N_ARGS( \
  117. 2, BOOST_TEST_TOOL_UNIV, BOOST_TEST_TOOL_UNIV_EX, WARN, __VA_ARGS__ ) \
  118. /**/
  119. #define BOOST_TEST_CHECK( ... ) BOOST_TEST_INVOKE_IF_N_ARGS( \
  120. 2, BOOST_TEST_TOOL_UNIV, BOOST_TEST_TOOL_UNIV_EX, CHECK, __VA_ARGS__ ) \
  121. /**/
  122. #define BOOST_TEST_REQUIRE( ... ) BOOST_TEST_INVOKE_IF_N_ARGS( \
  123. 2, BOOST_TEST_TOOL_UNIV, BOOST_TEST_TOOL_UNIV_EX, REQUIRE, __VA_ARGS__ )\
  124. /**/
  125. #define BOOST_TEST( ... ) BOOST_TEST_INVOKE_IF_N_ARGS( \
  126. 2, BOOST_TEST_TOOL_UNIV, BOOST_TEST_TOOL_UNIV_EX, CHECK, __VA_ARGS__ ) \
  127. /**/
  128. //____________________________________________________________________________//
  129. #define BOOST_TEST_ERROR( M ) BOOST_CHECK_MESSAGE( false, M )
  130. #define BOOST_TEST_FAIL( M ) BOOST_REQUIRE_MESSAGE( false, M )
  131. //____________________________________________________________________________//
  132. #define BOOST_TEST_IS_DEFINED( symb ) ::boost::test_tools::tt_detail::is_defined_impl( symb, BOOST_STRINGIZE(= symb) )
  133. //____________________________________________________________________________//
  134. #ifdef BOOST_TEST_NO_OLD_TOOLS
  135. #ifdef BOOST_TEST_TOOLS_UNDER_DEBUGGER
  136. #define BOOST_CHECK_THROW_IMPL(S, E, TL, Ppassed, Mpassed, Pcaught, Mcaught)\
  137. do { try { \
  138. S; \
  139. BOOST_TEST_TOOL_DIRECT_IMPL( Ppassed, TL, Mpassed ); \
  140. } catch( E ) { \
  141. BOOST_TEST_TOOL_DIRECT_IMPL( Pcaught, TL, Mcaught ); \
  142. }} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
  143. /**/
  144. #elif defined(BOOST_TEST_TOOLS_DEBUGGABLE)
  145. #define BOOST_CHECK_THROW_IMPL(S, E, TL, Ppassed, Mpassed, Pcaught, Mcaught)\
  146. do { try { \
  147. if( ::boost::debug::under_debugger() ) \
  148. BOOST_TEST_PASSPOINT(); \
  149. S; \
  150. BOOST_TEST_TOOL_DIRECT_IMPL( Ppassed, TL, Mpassed ); \
  151. } catch( E ) { \
  152. BOOST_TEST_TOOL_DIRECT_IMPL( Pcaught, TL, Mcaught ); \
  153. }} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
  154. /**/
  155. #else
  156. #define BOOST_CHECK_THROW_IMPL(S, E, TL, Ppassed, Mpassed, Pcaught, Mcaught)\
  157. do { try { \
  158. BOOST_TEST_PASSPOINT(); \
  159. S; \
  160. BOOST_TEST_TOOL_DIRECT_IMPL( Ppassed, TL, Mpassed ); \
  161. } catch( E ) { \
  162. BOOST_TEST_TOOL_DIRECT_IMPL( Pcaught, TL, Mcaught ); \
  163. }} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
  164. /**/
  165. #endif
  166. //____________________________________________________________________________//
  167. #define BOOST_WARN_THROW( S, E ) \
  168. BOOST_CHECK_THROW_IMPL(S, E const&, WARN, \
  169. false, "exception " BOOST_STRINGIZE(E) " is expected", \
  170. true , "exception " BOOST_STRINGIZE(E) " is caught" ) \
  171. /**/
  172. #define BOOST_CHECK_THROW( S, E ) \
  173. BOOST_CHECK_THROW_IMPL(S, E const&, CHECK, \
  174. false, "exception " BOOST_STRINGIZE(E) " is expected", \
  175. true , "exception " BOOST_STRINGIZE(E) " is caught" ) \
  176. /**/
  177. #define BOOST_REQUIRE_THROW( S, E ) \
  178. BOOST_CHECK_THROW_IMPL(S, E const&, REQUIRE, \
  179. false, "exception " BOOST_STRINGIZE(E) " is expected", \
  180. true , "exception " BOOST_STRINGIZE(E) " is caught" ) \
  181. /**/
  182. //____________________________________________________________________________//
  183. #define BOOST_WARN_EXCEPTION( S, E, P ) \
  184. BOOST_CHECK_THROW_IMPL(S, E const& ex, WARN, \
  185. false, "exception " BOOST_STRINGIZE(E) " is expected", \
  186. P(ex), "incorrect exception " BOOST_STRINGIZE(E) " is caught" ) \
  187. /**/
  188. #define BOOST_CHECK_EXCEPTION( S, E, P ) \
  189. BOOST_CHECK_THROW_IMPL(S, E const& ex, CHECK, \
  190. false, "exception " BOOST_STRINGIZE(E) " is expected", \
  191. P(ex), "incorrect exception " BOOST_STRINGIZE(E) " is caught" ) \
  192. /**/
  193. #define BOOST_REQUIRE_EXCEPTION( S, E, P ) \
  194. BOOST_CHECK_THROW_IMPL(S, E const& ex, REQUIRE, \
  195. false, "exception " BOOST_STRINGIZE(E) " is expected", \
  196. P(ex), "incorrect exception " BOOST_STRINGIZE(E) " is caught" ) \
  197. /**/
  198. //____________________________________________________________________________//
  199. #define BOOST_WARN_NO_THROW( S ) \
  200. BOOST_CHECK_THROW_IMPL(S, ..., WARN, \
  201. true , "no exceptions thrown by " BOOST_STRINGIZE( S ), \
  202. false, "exception thrown by " BOOST_STRINGIZE( S ) ) \
  203. /**/
  204. #define BOOST_CHECK_NO_THROW( S ) \
  205. BOOST_CHECK_THROW_IMPL(S, ..., CHECK, \
  206. true , "no exceptions thrown by " BOOST_STRINGIZE( S ), \
  207. false, "exception thrown by " BOOST_STRINGIZE( S ) ) \
  208. /**/
  209. #define BOOST_REQUIRE_NO_THROW( S ) \
  210. BOOST_CHECK_THROW_IMPL(S, ..., REQUIRE, \
  211. true , "no exceptions thrown by " BOOST_STRINGIZE( S ), \
  212. false, "exception thrown by " BOOST_STRINGIZE( S ) ) \
  213. /**/
  214. //____________________________________________________________________________//
  215. #define BOOST_WARN_MESSAGE( P, M ) BOOST_TEST_TOOL_DIRECT_IMPL( P, WARN, M )
  216. #define BOOST_CHECK_MESSAGE( P, M ) BOOST_TEST_TOOL_DIRECT_IMPL( P, CHECK, M )
  217. #define BOOST_REQUIRE_MESSAGE( P, M ) BOOST_TEST_TOOL_DIRECT_IMPL( P, REQUIRE, M )
  218. //____________________________________________________________________________//
  219. ////////////////////////////////////////////////////////////////////////////////
  220. ///////////////////////////// DEPRECATED TOOLS /////////////////////////////
  221. #define BOOST_WARN( P ) BOOST_TEST_WARN( P )
  222. #define BOOST_CHECK( P ) BOOST_TEST_CHECK( P )
  223. #define BOOST_REQUIRE( P ) BOOST_TEST_REQUIRE( P )
  224. //____________________________________________________________________________//
  225. #define BOOST_ERROR( M ) BOOST_TEST_ERROR( M )
  226. #define BOOST_FAIL( M ) BOOST_TEST_FAIL( M )
  227. //____________________________________________________________________________//
  228. #define BOOST_WARN_EQUAL( L, R ) BOOST_TEST_WARN( L == R )
  229. #define BOOST_CHECK_EQUAL( L, R ) BOOST_TEST_CHECK( L == R )
  230. #define BOOST_REQUIRE_EQUAL( L, R ) BOOST_TEST_REQUIRE( L == R )
  231. #define BOOST_WARN_NE( L, R ) BOOST_TEST_WARN( L != R )
  232. #define BOOST_CHECK_NE( L, R ) BOOST_TEST_CHECK( L != R )
  233. #define BOOST_REQUIRE_NE( L, R ) BOOST_TEST_REQUIRE( L != R )
  234. #define BOOST_WARN_LT( L, R ) BOOST_TEST_WARN( L < R )
  235. #define BOOST_CHECK_LT( L, R ) BOOST_TEST_CHECK( L < R )
  236. #define BOOST_REQUIRE_LT( L, R ) BOOST_TEST_REQUIRE( L < R )
  237. #define BOOST_WARN_LE( L, R ) BOOST_TEST_WARN( L <= R )
  238. #define BOOST_CHECK_LE( L, R ) BOOST_TEST_CHECK( L <= R )
  239. #define BOOST_REQUIRE_LE( L, R ) BOOST_TEST_REQUIRE( L <= R )
  240. #define BOOST_WARN_GT( L, R ) BOOST_TEST_WARN( L > R )
  241. #define BOOST_CHECK_GT( L, R ) BOOST_TEST_CHECK( L > R )
  242. #define BOOST_REQUIRE_GT( L, R ) BOOST_TEST_REQUIRE( L > R )
  243. #define BOOST_WARN_GE( L, R ) BOOST_TEST_WARN( L >= R )
  244. #define BOOST_CHECK_GE( L, R ) BOOST_TEST_CHECK( L >= R )
  245. #define BOOST_REQUIRE_GE( L, R ) BOOST_TEST_REQUIRE( L >= R )
  246. //____________________________________________________________________________//
  247. #define BOOST_WARN_CLOSE( L, R, T ) BOOST_TEST_WARN( L == R, T % ::boost::test_tools::tolerance() )
  248. #define BOOST_CHECK_CLOSE( L, R, T ) BOOST_TEST_CHECK( L == R, T % ::boost::test_tools::tolerance() )
  249. #define BOOST_REQUIRE_CLOSE( L, R, T ) BOOST_TEST_REQUIRE( L == R, T % ::boost::test_tools::tolerance() )
  250. #define BOOST_WARN_CLOSE_FRACTION(L, R, T) BOOST_TEST_WARN( L == R, ::boost::test_tools::tolerance( T ) )
  251. #define BOOST_CHECK_CLOSE_FRACTION(L, R, T) BOOST_TEST_CHECK( L == R, ::boost::test_tools::tolerance( T ) )
  252. #define BOOST_REQUIRE_CLOSE_FRACTION(L,R,T) BOOST_TEST_REQUIRE( L == R, ::boost::test_tools::tolerance( T ) )
  253. #define BOOST_WARN_SMALL( FPV, T ) BOOST_TEST_WARN( FPV == 0., ::boost::test_tools::tolerance( T ) )
  254. #define BOOST_CHECK_SMALL( FPV, T ) BOOST_TEST_CHECK( FPV == 0., ::boost::test_tools::tolerance( T ) )
  255. #define BOOST_REQUIRE_SMALL( FPV, T ) BOOST_TEST_REQUIRE( FPV == 0., ::boost::test_tools::tolerance( T ) )
  256. //____________________________________________________________________________//
  257. #define BOOST_WARN_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
  258. BOOST_TEST_WARN( ::boost::test_tools::tt_detail::make_it_pair(L_begin, L_end) ==\
  259. ::boost::test_tools::tt_detail::make_it_pair(R_begin, R_end), \
  260. ::boost::test_tools::per_element() ) \
  261. /**/
  262. #define BOOST_CHECK_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
  263. BOOST_TEST_CHECK( ::boost::test_tools::tt_detail::make_it_pair(L_begin, L_end) ==\
  264. ::boost::test_tools::tt_detail::make_it_pair(R_begin, R_end), \
  265. ::boost::test_tools::per_element() ) \
  266. /**/
  267. #define BOOST_REQUIRE_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
  268. BOOST_TEST_REQUIRE( ::boost::test_tools::tt_detail::make_it_pair(L_begin, L_end) ==\
  269. ::boost::test_tools::tt_detail::make_it_pair(R_begin, R_end), \
  270. ::boost::test_tools::per_element() ) \
  271. /**/
  272. //____________________________________________________________________________//
  273. #define BOOST_WARN_BITWISE_EQUAL( L, R ) BOOST_TEST_WARN( L == R, ::boost::test_tools::bitwise() )
  274. #define BOOST_CHECK_BITWISE_EQUAL( L, R ) BOOST_TEST_CHECK( L == R, ::boost::test_tools::bitwise() )
  275. #define BOOST_REQUIRE_BITWISE_EQUAL( L, R ) BOOST_TEST_REQUIRE( L == R, ::boost::test_tools::bitwise() )
  276. //____________________________________________________________________________//
  277. #define BOOST_WARN_PREDICATE( P, ARGS ) BOOST_TEST_WARN( P BOOST_PP_SEQ_TO_TUPLE(ARGS) )
  278. #define BOOST_CHECK_PREDICATE( P, ARGS ) BOOST_TEST_CHECK( P BOOST_PP_SEQ_TO_TUPLE(ARGS) )
  279. #define BOOST_REQUIRE_PREDICATE( P, ARGS ) BOOST_TEST_REQUIRE( P BOOST_PP_SEQ_TO_TUPLE(ARGS) )
  280. //____________________________________________________________________________//
  281. #define BOOST_IS_DEFINED( symb ) ::boost::test_tools::tt_detail::is_defined_impl( #symb, BOOST_STRINGIZE(= symb) )
  282. //____________________________________________________________________________//
  283. #endif // BOOST_TEST_NO_OLD_TOOLS
  284. #include <boost/test/detail/enable_warnings.hpp>
  285. #endif // BOOST_TEST_TOOLS_INTERFACE_HPP_111712GER