throw_exception.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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
  8. //!@brief contains wrappers, which allows to build Boost.Test with no exception
  9. // ***************************************************************************
  10. #ifndef BOOST_TEST_DETAIL_THROW_EXCEPTION_HPP
  11. #define BOOST_TEST_DETAIL_THROW_EXCEPTION_HPP
  12. // Boost
  13. #include <boost/config.hpp> // BOOST_NO_EXCEPTIONS
  14. #ifdef BOOST_NO_EXCEPTIONS
  15. // C RUNTIME
  16. #include <stdlib.h>
  17. #endif
  18. #include <boost/test/detail/suppress_warnings.hpp>
  19. //____________________________________________________________________________//
  20. namespace boost {
  21. namespace unit_test {
  22. namespace ut_detail {
  23. #ifdef BOOST_NO_EXCEPTIONS
  24. template<typename E>
  25. BOOST_NORETURN inline void
  26. throw_exception(E const& /*e*/) { abort(); }
  27. #define BOOST_TEST_I_TRY
  28. #define BOOST_TEST_I_CATCH( T, var ) for(T const& var = *(T*)0; false;)
  29. #define BOOST_TEST_I_CATCH0( T ) if(0)
  30. #define BOOST_TEST_I_CATCHALL() if(0)
  31. #define BOOST_TEST_I_RETHROW
  32. #else
  33. template<typename E>
  34. BOOST_NORETURN inline void
  35. throw_exception(E const& e) { throw e; }
  36. #define BOOST_TEST_I_TRY try
  37. #define BOOST_TEST_I_CATCH( T, var ) catch( T const& var )
  38. #define BOOST_TEST_I_CATCH0( T ) catch( T const& )
  39. #define BOOST_TEST_I_CATCHALL() catch(...)
  40. #define BOOST_TEST_I_RETHROW throw
  41. #endif
  42. //____________________________________________________________________________//
  43. #define BOOST_TEST_I_THROW( E ) unit_test::ut_detail::throw_exception( E )
  44. #define BOOST_TEST_I_ASSRT( cond, ex ) if( cond ) {} else BOOST_TEST_I_THROW( ex )
  45. } // namespace ut_detail
  46. } // namespace unit_test
  47. } // namespace boost
  48. //____________________________________________________________________________//
  49. #include <boost/test/detail/enable_warnings.hpp>
  50. #endif // BOOST_TEST_DETAIL_THROW_EXCEPTION_HPP