Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:00:58

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 //  Description : unit test decorators implementation
0009 // ***************************************************************************
0010 
0011 #ifndef BOOST_TEST_TREE_DECORATOR_IPP_091911GER
0012 #define BOOST_TEST_TREE_DECORATOR_IPP_091911GER
0013 
0014 // Boost.Test
0015 #include <boost/test/tree/decorator.hpp>
0016 #include <boost/test/tree/test_unit.hpp>
0017 
0018 #include <boost/test/framework.hpp>
0019 #if BOOST_TEST_SUPPORT_TOKEN_ITERATOR
0020 #include <boost/test/utils/iterator/token_iterator.hpp>
0021 #endif
0022 
0023 #include <boost/test/detail/throw_exception.hpp>
0024 
0025 #include <boost/test/detail/suppress_warnings.hpp>
0026 
0027 //____________________________________________________________________________//
0028 
0029 namespace boost {
0030 namespace unit_test {
0031 namespace decorator {
0032 
0033 // ************************************************************************** //
0034 // **************             decorator::collector_t           ************** //
0035 // ************************************************************************** //
0036 
0037 // singleton pattern
0038 BOOST_TEST_SINGLETON_CONS_IMPL(collector_t)
0039 
0040 
0041 collector_t&
0042 collector_t::operator*( base const& d )
0043 {
0044     m_tu_decorators_stack.begin()->push_back( d.clone() );
0045 
0046     return *this;
0047 }
0048 
0049 //____________________________________________________________________________//
0050 
0051 void
0052 collector_t::store_in( test_unit& tu )
0053 {
0054     tu.p_decorators.value.insert(
0055         tu.p_decorators.value.end(),
0056         m_tu_decorators_stack.begin()->begin(),
0057         m_tu_decorators_stack.begin()->end() );
0058 }
0059 
0060 //____________________________________________________________________________//
0061 
0062 void
0063 collector_t::reset()
0064 {
0065     if(m_tu_decorators_stack.size() > 1) {
0066         m_tu_decorators_stack.erase(m_tu_decorators_stack.begin());
0067     }
0068     else {
0069         assert(m_tu_decorators_stack.size() == 1);
0070         m_tu_decorators_stack.begin()->clear();
0071     }
0072 }
0073 
0074 void
0075 collector_t::stack()
0076 {
0077     assert(m_tu_decorators_stack.size() >= 1);
0078     m_tu_decorators_stack.insert(m_tu_decorators_stack.begin(), std::vector<base_ptr>());
0079 }
0080 
0081 //____________________________________________________________________________//
0082 
0083 std::vector<base_ptr>
0084 collector_t::get_lazy_decorators() const
0085 {
0086     return *m_tu_decorators_stack.begin();
0087 }
0088 
0089 //____________________________________________________________________________//
0090 
0091 // ************************************************************************** //
0092 // **************               decorator::base                ************** //
0093 // ************************************************************************** //
0094 
0095 collector_t&
0096 base::operator*() const
0097 {
0098     return collector_t::instance() * *this;
0099 }
0100 
0101 // ************************************************************************** //
0102 // **************           decorator::stack_decorator         ************** //
0103 // ************************************************************************** //
0104 
0105 collector_t&
0106 stack_decorator::operator*() const
0107 {
0108     collector_t& instance = collector_t::instance();
0109     instance.stack();
0110     return instance * *this;
0111 }
0112 
0113 void
0114 stack_decorator::apply( test_unit& /*tu*/ )
0115 {
0116     // does nothing by definition
0117 }
0118 
0119 // ************************************************************************** //
0120 // **************               decorator::label               ************** //
0121 // ************************************************************************** //
0122 
0123 void
0124 label::apply( test_unit& tu )
0125 {
0126     tu.add_label( m_label );
0127 }
0128 
0129 //____________________________________________________________________________//
0130 
0131 // ************************************************************************** //
0132 // **************         decorator::expected_failures         ************** //
0133 // ************************************************************************** //
0134 
0135 void
0136 expected_failures::apply( test_unit& tu )
0137 {
0138     tu.increase_exp_fail( m_exp_fail );
0139 }
0140 
0141 //____________________________________________________________________________//
0142 
0143 // ************************************************************************** //
0144 // **************              decorator::timeout              ************** //
0145 // ************************************************************************** //
0146 
0147 void
0148 timeout::apply( test_unit& tu )
0149 {
0150     tu.p_timeout.value = m_timeout;
0151 }
0152 
0153 //____________________________________________________________________________//
0154 
0155 // ************************************************************************** //
0156 // **************            decorator::description            ************** //
0157 // ************************************************************************** //
0158 
0159 void
0160 description::apply( test_unit& tu )
0161 {
0162     tu.p_description.value += m_description;
0163 }
0164 
0165 //____________________________________________________________________________//
0166 
0167 // ************************************************************************** //
0168 // **************             decorator::depends_on            ************** //
0169 // ************************************************************************** //
0170 
0171 void
0172 depends_on::apply( test_unit& tu )
0173 {
0174 #if !BOOST_TEST_SUPPORT_TOKEN_ITERATOR
0175     BOOST_TEST_SETUP_ASSERT( false, "depends_on decorator is not supported on this platform" );
0176 #else
0177     utils::string_token_iterator tit( m_dependency, (utils::dropped_delimeters = "/", utils::kept_delimeters = utils::dt_none) );
0178 
0179     test_unit* dep = &framework::master_test_suite();
0180     while( tit != utils::string_token_iterator() ) {
0181         BOOST_TEST_SETUP_ASSERT( dep->p_type == TUT_SUITE, std::string( "incorrect dependency specification " ) + m_dependency );
0182 
0183         test_unit_id next_id = static_cast<test_suite*>(dep)->get( *tit );
0184 
0185         BOOST_TEST_SETUP_ASSERT( next_id != INV_TEST_UNIT_ID,
0186                                  std::string( "incorrect dependency specification " ) + m_dependency );
0187 
0188         dep = &framework::get( next_id, TUT_ANY );
0189         ++tit;
0190     }
0191 
0192     tu.depends_on( dep );
0193 #endif
0194 }
0195 
0196 //____________________________________________________________________________//
0197 
0198 // ************************************************************************** //
0199 // **************    decorator::enable_if/enabled/disabled     ************** //
0200 // ************************************************************************** //
0201 
0202 void
0203 enable_if_impl::apply_impl( test_unit& tu, bool condition )
0204 {
0205     BOOST_TEST_SETUP_ASSERT(tu.p_default_status == test_unit::RS_INHERIT,
0206                             "Can't apply multiple enabled/disabled decorators "
0207                             "to the same test unit " + tu.full_name());
0208 
0209     tu.p_default_status.value = condition ? test_unit::RS_ENABLED : test_unit::RS_DISABLED;
0210 }
0211 
0212 //____________________________________________________________________________//
0213 
0214 // ************************************************************************** //
0215 // **************              decorator::fixture              ************** //
0216 // ************************************************************************** //
0217 
0218 void
0219 fixture_t::apply( test_unit& tu )
0220 {
0221     tu.p_fixtures.value.push_back( m_impl );
0222 }
0223 
0224 //____________________________________________________________________________//
0225 
0226 // ************************************************************************** //
0227 // **************            decorator::depends_on             ************** //
0228 // ************************************************************************** //
0229 
0230 void
0231 precondition::apply( test_unit& tu )
0232 {
0233     tu.add_precondition( m_precondition );
0234 }
0235 
0236 //____________________________________________________________________________//
0237 
0238 } // namespace decorator
0239 } // namespace unit_test
0240 } // namespace boost
0241 
0242 #include <boost/test/detail/enable_warnings.hpp>
0243 
0244 #endif // BOOST_TEST_TREE_DECORATOR_IPP_091911GER