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 29namespace boost { 30namespace unit_test { 31namespace decorator { 32 33// ************************************************************************** // 34// ************** decorator::collector_t ************** // 35// ************************************************************************** // 36 37// singleton pattern 38BOOST_TEST_SINGLETON_CONS_IMPL(collector_t) 39 40 41collector_t& 42collector_t::operator*( base const& d ) 43{ 44 m_tu_decorators_stack.begin()->push_back( d.clone() ); 45 46 return *this; 47} 48 49//____________________________________________________________________________// 50 51void 52collector_t::store_in( test_unit& tu ) 53{ 54 tu.p_decorators.value.insert( 55 tu.p_decorators.value.end(), 56 m_tu_decorators_stack.begin()->begin(), 57 m_tu_decorators_stack.begin()->end() ); 58} 59 60//____________________________________________________________________________// 61 62void 63collector_t::reset() 64{ 65 if(m_tu_decorators_stack.size() > 1) { 66 m_tu_decorators_stack.erase(m_tu_decorators_stack.begin()); 67 } 68 else { 69 assert(m_tu_decorators_stack.size() == 1); 70 m_tu_decorators_stack.begin()->clear(); 71 } 72} 73 74void 75collector_t::stack() 76{ 77 assert(m_tu_decorators_stack.size() >= 1); 78 m_tu_decorators_stack.insert(m_tu_decorators_stack.begin(), std::vector<base_ptr>()); 79} 80 81//____________________________________________________________________________// 82 83std::vector<base_ptr> 84collector_t::get_lazy_decorators() const 85{ 86 return *m_tu_decorators_stack.begin(); 87} 88 89//____________________________________________________________________________// 90 91// ************************************************************************** // 92// ************** decorator::base ************** // 93// ************************************************************************** // 94 95collector_t& 96base::operator*() const 97{ 98 return collector_t::instance() * *this; 99} 100 101// ************************************************************************** // 102// ************** decorator::stack_decorator ************** // 103// ************************************************************************** // 104 105collector_t& 106stack_decorator::operator*() const 107{ 108 collector_t& instance = collector_t::instance(); 109 instance.stack(); 110 return instance * *this; 111} 112 113void 114stack_decorator::apply( test_unit& /*tu*/ ) 115{ 116 // does nothing by definition 117} 118 119// ************************************************************************** // 120// ************** decorator::label ************** // 121// ************************************************************************** // 122 123void 124label::apply( test_unit& tu ) 125{ 126 tu.add_label( m_label ); 127} 128 129//____________________________________________________________________________// 130 131// ************************************************************************** // 132// ************** decorator::expected_failures ************** // 133// ************************************************************************** // 134 135void 136expected_failures::apply( test_unit& tu ) 137{ 138 tu.increase_exp_fail( m_exp_fail ); 139} 140 141//____________________________________________________________________________// 142 143// ************************************************************************** // 144// ************** decorator::timeout ************** // 145// ************************************************************************** // 146 147void 148timeout::apply( test_unit& tu ) 149{ 150 tu.p_timeout.value = m_timeout; 151} 152 153//____________________________________________________________________________// 154 155// ************************************************************************** // 156// ************** decorator::description ************** // 157// ************************************************************************** // 158 159void 160description::apply( test_unit& tu ) 161{ 162 tu.p_description.value += m_description; 163} 164 165//____________________________________________________________________________// 166 167// ************************************************************************** // 168// ************** decorator::depends_on ************** // 169// ************************************************************************** // 170 171void 172depends_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 utils::string_token_iterator tit( m_dependency, (utils::dropped_delimeters = "/", utils::kept_delimeters = utils::dt_none) ); 178 179 test_unit* dep = &framework::master_test_suite(); 180 while( tit != utils::string_token_iterator() ) { 181 BOOST_TEST_SETUP_ASSERT( dep->p_type == TUT_SUITE, std::string( "incorrect dependency specification " ) + m_dependency ); 182 183 test_unit_id next_id = static_cast<test_suite*>(dep)->get( *tit ); 184 185 BOOST_TEST_SETUP_ASSERT( next_id != INV_TEST_UNIT_ID, 186 std::string( "incorrect dependency specification " ) + m_dependency ); 187 188 dep = &framework::get( next_id, TUT_ANY ); 189 ++tit; 190 } 191 192 tu.depends_on( dep ); 193#endif 194} 195 196//____________________________________________________________________________// 197 198// ************************************************************************** // 199// ************** decorator::enable_if/enabled/disabled ************** // 200// ************************************************************************** // 201 202void 203enable_if_impl::apply_impl( test_unit& tu, bool condition ) 204{ 205 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 tu.p_default_status.value = condition ? test_unit::RS_ENABLED : test_unit::RS_DISABLED; 210} 211 212//____________________________________________________________________________// 213 214// ************************************************************************** // 215// ************** decorator::fixture ************** // 216// ************************************************************************** // 217 218void 219fixture_t::apply( test_unit& tu ) 220{ 221 tu.p_fixtures.value.push_back( m_impl ); 222} 223 224//____________________________________________________________________________// 225 226// ************************************************************************** // 227// ************** decorator::depends_on ************** // 228// ************************************************************************** // 229 230void 231precondition::apply( test_unit& tu ) 232{ 233 tu.add_precondition( m_precondition ); 234} 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 245