decorator.ipp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. // Description : unit test decorators implementation
  8. // ***************************************************************************
  9. #ifndef BOOST_TEST_TREE_DECORATOR_IPP_091911GER
  10. #define BOOST_TEST_TREE_DECORATOR_IPP_091911GER
  11. // Boost.Test
  12. #include <boost/test/tree/decorator.hpp>
  13. #include <boost/test/tree/test_unit.hpp>
  14. #include <boost/test/framework.hpp>
  15. #if BOOST_TEST_SUPPORT_TOKEN_ITERATOR
  16. #include <boost/test/utils/iterator/token_iterator.hpp>
  17. #endif
  18. #include <boost/test/detail/throw_exception.hpp>
  19. #include <boost/test/detail/suppress_warnings.hpp>
  20. //____________________________________________________________________________//
  21. namespace boost {
  22. namespace unit_test {
  23. namespace decorator {
  24. // ************************************************************************** //
  25. // ************** decorator::collector_t ************** //
  26. // ************************************************************************** //
  27. // singleton pattern
  28. BOOST_TEST_SINGLETON_CONS_IMPL(collector_t)
  29. collector_t&
  30. collector_t::operator*( base const& d )
  31. {
  32. m_tu_decorators_stack.begin()->push_back( d.clone() );
  33. return *this;
  34. }
  35. //____________________________________________________________________________//
  36. void
  37. collector_t::store_in( test_unit& tu )
  38. {
  39. tu.p_decorators.value.insert(
  40. tu.p_decorators.value.end(),
  41. m_tu_decorators_stack.begin()->begin(),
  42. m_tu_decorators_stack.begin()->end() );
  43. }
  44. //____________________________________________________________________________//
  45. void
  46. collector_t::reset()
  47. {
  48. if(m_tu_decorators_stack.size() > 1) {
  49. m_tu_decorators_stack.erase(m_tu_decorators_stack.begin());
  50. }
  51. else {
  52. assert(m_tu_decorators_stack.size() == 1);
  53. m_tu_decorators_stack.begin()->clear();
  54. }
  55. }
  56. void
  57. collector_t::stack()
  58. {
  59. assert(m_tu_decorators_stack.size() >= 1);
  60. m_tu_decorators_stack.insert(m_tu_decorators_stack.begin(), std::vector<base_ptr>());
  61. }
  62. //____________________________________________________________________________//
  63. std::vector<base_ptr>
  64. collector_t::get_lazy_decorators() const
  65. {
  66. return *m_tu_decorators_stack.begin();
  67. }
  68. //____________________________________________________________________________//
  69. // ************************************************************************** //
  70. // ************** decorator::base ************** //
  71. // ************************************************************************** //
  72. collector_t&
  73. base::operator*() const
  74. {
  75. return collector_t::instance() * *this;
  76. }
  77. // ************************************************************************** //
  78. // ************** decorator::stack_decorator ************** //
  79. // ************************************************************************** //
  80. collector_t&
  81. stack_decorator::operator*() const
  82. {
  83. collector_t& instance = collector_t::instance();
  84. instance.stack();
  85. return instance * *this;
  86. }
  87. void
  88. stack_decorator::apply( test_unit& /*tu*/ )
  89. {
  90. // does nothing by definition
  91. }
  92. // ************************************************************************** //
  93. // ************** decorator::label ************** //
  94. // ************************************************************************** //
  95. void
  96. label::apply( test_unit& tu )
  97. {
  98. tu.add_label( m_label );
  99. }
  100. //____________________________________________________________________________//
  101. // ************************************************************************** //
  102. // ************** decorator::expected_failures ************** //
  103. // ************************************************************************** //
  104. void
  105. expected_failures::apply( test_unit& tu )
  106. {
  107. tu.increase_exp_fail( m_exp_fail );
  108. }
  109. //____________________________________________________________________________//
  110. // ************************************************************************** //
  111. // ************** decorator::timeout ************** //
  112. // ************************************************************************** //
  113. void
  114. timeout::apply( test_unit& tu )
  115. {
  116. tu.p_timeout.value = m_timeout;
  117. }
  118. //____________________________________________________________________________//
  119. // ************************************************************************** //
  120. // ************** decorator::description ************** //
  121. // ************************************************************************** //
  122. void
  123. description::apply( test_unit& tu )
  124. {
  125. tu.p_description.value += m_description;
  126. }
  127. //____________________________________________________________________________//
  128. // ************************************************************************** //
  129. // ************** decorator::depends_on ************** //
  130. // ************************************************************************** //
  131. void
  132. depends_on::apply( test_unit& tu )
  133. {
  134. #if !BOOST_TEST_SUPPORT_TOKEN_ITERATOR
  135. BOOST_TEST_SETUP_ASSERT( false, "depends_on decorator is not supported on this platform" );
  136. #else
  137. utils::string_token_iterator tit( m_dependency, (utils::dropped_delimeters = "/", utils::kept_delimeters = utils::dt_none) );
  138. test_unit* dep = &framework::master_test_suite();
  139. while( tit != utils::string_token_iterator() ) {
  140. BOOST_TEST_SETUP_ASSERT( dep->p_type == TUT_SUITE, std::string( "incorrect dependency specification " ) + m_dependency );
  141. test_unit_id next_id = static_cast<test_suite*>(dep)->get( *tit );
  142. BOOST_TEST_SETUP_ASSERT( next_id != INV_TEST_UNIT_ID,
  143. std::string( "incorrect dependency specification " ) + m_dependency );
  144. dep = &framework::get( next_id, TUT_ANY );
  145. ++tit;
  146. }
  147. tu.depends_on( dep );
  148. #endif
  149. }
  150. //____________________________________________________________________________//
  151. // ************************************************************************** //
  152. // ************** decorator::enable_if/enabled/disabled ************** //
  153. // ************************************************************************** //
  154. void
  155. enable_if_impl::apply_impl( test_unit& tu, bool condition )
  156. {
  157. BOOST_TEST_SETUP_ASSERT(tu.p_default_status == test_unit::RS_INHERIT,
  158. "Can't apply multiple enabled/disabled decorators "
  159. "to the same test unit " + tu.full_name());
  160. tu.p_default_status.value = condition ? test_unit::RS_ENABLED : test_unit::RS_DISABLED;
  161. }
  162. //____________________________________________________________________________//
  163. // ************************************************************************** //
  164. // ************** decorator::fixture ************** //
  165. // ************************************************************************** //
  166. void
  167. fixture_t::apply( test_unit& tu )
  168. {
  169. tu.p_fixtures.value.push_back( m_impl );
  170. }
  171. //____________________________________________________________________________//
  172. // ************************************************************************** //
  173. // ************** decorator::depends_on ************** //
  174. // ************************************************************************** //
  175. void
  176. precondition::apply( test_unit& tu )
  177. {
  178. tu.add_precondition( m_precondition );
  179. }
  180. //____________________________________________________________________________//
  181. } // namespace decorator
  182. } // namespace unit_test
  183. } // namespace boost
  184. #include <boost/test/detail/enable_warnings.hpp>
  185. #endif // BOOST_TEST_TREE_DECORATOR_IPP_091911GER