File indexing completed on 2025-01-30 10:00:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_TEST_TREE_DECORATOR_IPP_091911GER
0012 #define BOOST_TEST_TREE_DECORATOR_IPP_091911GER
0013
0014
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
0035
0036
0037
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
0093
0094
0095 collector_t&
0096 base::operator*() const
0097 {
0098 return collector_t::instance() * *this;
0099 }
0100
0101
0102
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& )
0115 {
0116
0117 }
0118
0119
0120
0121
0122
0123 void
0124 label::apply( test_unit& tu )
0125 {
0126 tu.add_label( m_label );
0127 }
0128
0129
0130
0131
0132
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
0145
0146
0147 void
0148 timeout::apply( test_unit& tu )
0149 {
0150 tu.p_timeout.value = m_timeout;
0151 }
0152
0153
0154
0155
0156
0157
0158
0159 void
0160 description::apply( test_unit& tu )
0161 {
0162 tu.p_description.value += m_description;
0163 }
0164
0165
0166
0167
0168
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
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
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
0228
0229
0230 void
0231 precondition::apply( test_unit& tu )
0232 {
0233 tu.add_precondition( m_precondition );
0234 }
0235
0236
0237
0238 }
0239 }
0240 }
0241
0242 #include <boost/test/detail/enable_warnings.hpp>
0243
0244 #endif