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