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)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : unit test decorators implementation
13 // ***************************************************************************
15 #ifndef BOOST_TEST_TREE_DECORATOR_IPP_091911GER
16 #define BOOST_TEST_TREE_DECORATOR_IPP_091911GER
19 #include <boost/test/tree/decorator.hpp>
20 #include <boost/test/tree/test_unit.hpp>
22 #include <boost/test/framework.hpp>
23 #if BOOST_TEST_SUPPORT_TOKEN_ITERATOR
24 #include <boost/test/utils/iterator/token_iterator.hpp>
27 #include <boost/test/detail/throw_exception.hpp>
29 #include <boost/test/detail/suppress_warnings.hpp>
31 //____________________________________________________________________________//
37 // ************************************************************************** //
38 // ************** decorator::collector ************** //
39 // ************************************************************************** //
42 collector::operator*( base const& d )
44 m_tu_decorators.push_back( d.clone() );
49 //____________________________________________________________________________//
52 collector::store_in( test_unit& tu )
54 tu.p_decorators.value.insert( tu.p_decorators.value.end(), m_tu_decorators.begin(), m_tu_decorators.end() );
57 //____________________________________________________________________________//
62 m_tu_decorators.clear();
65 //____________________________________________________________________________//
67 // ************************************************************************** //
68 // ************** decorator::base ************** //
69 // ************************************************************************** //
72 base::operator*() const
74 return collector::instance() * *this;
77 // ************************************************************************** //
78 // ************** decorator::label ************** //
79 // ************************************************************************** //
82 label::apply( test_unit& tu )
84 tu.add_label( m_label );
87 //____________________________________________________________________________//
89 // ************************************************************************** //
90 // ************** decorator::expected_failures ************** //
91 // ************************************************************************** //
94 expected_failures::apply( test_unit& tu )
96 tu.increase_exp_fail( m_exp_fail );
99 //____________________________________________________________________________//
101 // ************************************************************************** //
102 // ************** decorator::timeout ************** //
103 // ************************************************************************** //
106 timeout::apply( test_unit& tu )
108 tu.p_timeout.value = m_timeout;
111 //____________________________________________________________________________//
113 // ************************************************************************** //
114 // ************** decorator::description ************** //
115 // ************************************************************************** //
118 description::apply( test_unit& tu )
120 tu.p_description.value += m_description;
123 //____________________________________________________________________________//
125 // ************************************************************************** //
126 // ************** decorator::depends_on ************** //
127 // ************************************************************************** //
130 depends_on::apply( test_unit& tu )
132 #if !BOOST_TEST_SUPPORT_TOKEN_ITERATOR
133 BOOST_TEST_SETUP_ASSERT( false, "depends_on decorator is not supported on this platform" );
135 utils::string_token_iterator tit( m_dependency, (utils::dropped_delimeters = "/", utils::kept_delimeters = utils::dt_none) );
137 test_unit* dep = &framework::master_test_suite();
138 while( tit != utils::string_token_iterator() ) {
139 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 );
143 BOOST_TEST_SETUP_ASSERT( next_id != INV_TEST_UNIT_ID,
144 std::string( "incorrect dependency specification " ) + m_dependency );
146 dep = &framework::get( next_id, TUT_ANY );
150 tu.depends_on( dep );
154 //____________________________________________________________________________//
156 // ************************************************************************** //
157 // ************** decorator::enable_if/enabled/disabled ************** //
158 // ************************************************************************** //
161 enable_if_impl::apply_impl( test_unit& tu, bool condition )
163 BOOST_TEST_SETUP_ASSERT(tu.p_default_status == test_unit::RS_INHERIT,
164 "Can't apply multiple enabled/disabled decorators "
165 "to the same test unit " + tu.full_name());
167 tu.p_default_status.value = condition ? test_unit::RS_ENABLED : test_unit::RS_DISABLED;
170 //____________________________________________________________________________//
172 // ************************************************************************** //
173 // ************** decorator::fixture ************** //
174 // ************************************************************************** //
177 fixture_t::apply( test_unit& tu )
179 tu.p_fixtures.value.push_back( m_impl );
182 //____________________________________________________________________________//
184 // ************************************************************************** //
185 // ************** decorator::depends_on ************** //
186 // ************************************************************************** //
189 precondition::apply( test_unit& tu )
191 tu.add_precondition( m_precondition );
194 //____________________________________________________________________________//
196 } // namespace decorator
197 } // namespace unit_test
200 #include <boost/test/detail/enable_warnings.hpp>
202 #endif // BOOST_TEST_TREE_DECORATOR_IPP_091911GER