indirections.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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: 74248 $
  10. //
  11. // Description : inidiration interfaces to support manipulators and message output
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_TOOLS_DETAIL_INDIRECTIONS_HPP_112812GER
  14. #define BOOST_TEST_TOOLS_DETAIL_INDIRECTIONS_HPP_112812GER
  15. // Boost.Test
  16. #include <boost/test/tools/detail/fwd.hpp>
  17. #include <boost/test/tools/assertion_result.hpp>
  18. #include <boost/test/utils/lazy_ostream.hpp>
  19. #include <boost/shared_ptr.hpp>
  20. #include <list>
  21. #include <boost/test/detail/suppress_warnings.hpp>
  22. //____________________________________________________________________________//
  23. namespace boost {
  24. namespace test_tools {
  25. namespace tt_detail {
  26. struct assertion_evaluation_context
  27. {
  28. assertion_evaluation_context(bool has_report = false)
  29. : m_has_report(has_report)
  30. {}
  31. bool m_has_report;
  32. };
  33. // ************************************************************************** //
  34. // ************** assertion_evaluate indirection ************** //
  35. // ************************************************************************** //
  36. template<typename E>
  37. struct assertion_evaluate_t {
  38. typedef shared_ptr<assertion_evaluation_context> context_holder;
  39. assertion_evaluate_t( E const& e ) : m_e( e ), m_evaluate( true )
  40. {}
  41. operator assertion_result() { return m_e.evaluate( m_evaluate ); }
  42. assertion_evaluate_t<E>
  43. stack_context(context_holder context) const {
  44. assertion_evaluate_t<E> added_context(*this);
  45. added_context.m_context_holder.push_back(context);
  46. added_context.m_evaluate = !context->m_has_report;
  47. return added_context;
  48. }
  49. E const& m_e;
  50. std::list< context_holder > m_context_holder;
  51. bool m_evaluate;
  52. };
  53. //____________________________________________________________________________//
  54. template<typename E>
  55. inline assertion_evaluate_t<E>
  56. assertion_evaluate( E const& e ) { return assertion_evaluate_t<E>( e ); }
  57. //____________________________________________________________________________//
  58. template<typename E, typename T>
  59. inline assertion_evaluate_t<E>
  60. operator<<( assertion_evaluate_t<E> const& ae, T const& ) { return ae; }
  61. //____________________________________________________________________________//
  62. // ************************************************************************** //
  63. // ************** assertion_text indirection ************** //
  64. // ************************************************************************** //
  65. inline unit_test::lazy_ostream const&
  66. assertion_text( unit_test::lazy_ostream const& et, unit_test::lazy_ostream const& s) {
  67. if(!s.empty())
  68. return s;
  69. return et;
  70. }
  71. //____________________________________________________________________________//
  72. // ************************************************************************** //
  73. // ************** assertion_evaluate indirection ************** //
  74. // ************************************************************************** //
  75. struct assertion_type {
  76. assertion_type(check_type ct = CHECK_MSG) : m_check_type(ct)
  77. {}
  78. operator check_type() { return m_check_type; }
  79. check_type m_check_type;
  80. };
  81. //____________________________________________________________________________//
  82. template<typename T>
  83. inline assertion_type
  84. operator<<( assertion_type const& at, T const& ) { return at; }
  85. //____________________________________________________________________________//
  86. } // namespace tt_detail
  87. } // namespace test_tools
  88. } // namespace boost
  89. #include <boost/test/detail/enable_warnings.hpp>
  90. #endif // BOOST_TEST_TOOLS_DETAIL_INDIRECTIONS_HPP_112812GER