File indexing completed on 2025-01-18 09:52:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_TEST_TREE_DECORATOR_HPP_091911GER
0016 #define BOOST_TEST_TREE_DECORATOR_HPP_091911GER
0017
0018
0019 #include <boost/test/detail/config.hpp>
0020 #include <boost/test/detail/global_typedef.hpp>
0021
0022 #include <boost/test/tree/fixture.hpp>
0023
0024 #include <boost/test/tools/assertion_result.hpp>
0025 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
0026
0027
0028 #include <boost/shared_ptr.hpp>
0029 #include <boost/function/function0.hpp>
0030 #include <boost/function/function1.hpp>
0031
0032 #include <boost/test/detail/suppress_warnings.hpp>
0033
0034
0035 #include <vector>
0036
0037
0038
0039 namespace boost {
0040 namespace unit_test {
0041
0042 class test_unit;
0043
0044 namespace decorator {
0045
0046
0047
0048
0049
0050 class base;
0051 typedef boost::shared_ptr<base> base_ptr;
0052
0053 class BOOST_TEST_DECL collector_t {
0054
0055 public:
0056 collector_t& operator*( base const& d );
0057
0058 void store_in( test_unit& tu );
0059
0060 void reset();
0061
0062 void stack();
0063
0064 std::vector<base_ptr> get_lazy_decorators() const;
0065
0066
0067 BOOST_TEST_SINGLETON_CONS_NO_CTOR( collector_t )
0068
0069 private:
0070
0071 collector_t() : m_tu_decorators_stack(1) {}
0072
0073
0074 std::vector< std::vector<base_ptr> > m_tu_decorators_stack;
0075 };
0076
0077
0078
0079
0080
0081
0082 class BOOST_TEST_DECL base {
0083 public:
0084
0085 virtual collector_t& operator*() const;
0086
0087
0088 virtual void apply( test_unit& tu ) = 0;
0089
0090
0091 virtual base_ptr clone() const = 0;
0092
0093 protected:
0094 virtual ~base() {}
0095 };
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 class BOOST_TEST_DECL stack_decorator : public decorator::base {
0110 public:
0111 explicit stack_decorator() {}
0112
0113 collector_t& operator*() const BOOST_OVERRIDE;
0114
0115 private:
0116
0117 void apply( test_unit& tu ) BOOST_OVERRIDE;
0118 base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new stack_decorator()); }
0119 };
0120
0121
0122
0123
0124
0125 class BOOST_TEST_DECL label : public decorator::base {
0126 public:
0127 explicit label( const_string l ) : m_label( l ) {}
0128
0129 private:
0130
0131 void apply( test_unit& tu ) BOOST_OVERRIDE;
0132 base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new label( m_label )); }
0133
0134
0135 const_string m_label;
0136 };
0137
0138
0139
0140
0141
0142 class BOOST_TEST_DECL expected_failures : public decorator::base {
0143 public:
0144 explicit expected_failures( counter_t ef ) : m_exp_fail( ef ) {}
0145
0146 private:
0147
0148 void apply( test_unit& tu ) BOOST_OVERRIDE;
0149 base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new expected_failures( m_exp_fail )); }
0150
0151
0152 counter_t m_exp_fail;
0153 };
0154
0155
0156
0157
0158
0159 class BOOST_TEST_DECL timeout : public decorator::base {
0160 public:
0161 explicit timeout( unsigned t ) : m_timeout( t ) {}
0162
0163 private:
0164
0165 void apply( test_unit& tu ) BOOST_OVERRIDE;
0166 base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new timeout( m_timeout )); }
0167
0168
0169 unsigned m_timeout;
0170 };
0171
0172
0173
0174
0175
0176 class BOOST_TEST_DECL description : public decorator::base {
0177 public:
0178 explicit description( const_string descr ) : m_description( descr ) {}
0179
0180 private:
0181
0182 void apply( test_unit& tu ) BOOST_OVERRIDE;
0183 base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new description( m_description )); }
0184
0185
0186 const_string m_description;
0187 };
0188
0189
0190
0191
0192
0193 class BOOST_TEST_DECL depends_on : public decorator::base {
0194 public:
0195 explicit depends_on( const_string dependency ) : m_dependency( dependency ) {}
0196
0197 private:
0198
0199 void apply( test_unit& tu ) BOOST_OVERRIDE;
0200 base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new depends_on( m_dependency )); }
0201
0202
0203 const_string m_dependency;
0204 };
0205
0206
0207
0208
0209
0210 class BOOST_TEST_DECL enable_if_impl : public decorator::base {
0211 protected:
0212 void apply_impl( test_unit& tu, bool condition );
0213 };
0214
0215 template<bool condition>
0216 class enable_if : public enable_if_impl {
0217 private:
0218
0219 void apply( test_unit& tu ) BOOST_OVERRIDE { this->apply_impl( tu, condition ); }
0220 base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new enable_if<condition>()); }
0221 };
0222
0223 typedef enable_if<true> enabled;
0224 typedef enable_if<false> disabled;
0225
0226
0227
0228
0229
0230 class BOOST_TEST_DECL fixture_t : public decorator::base {
0231 public:
0232
0233 explicit fixture_t( test_unit_fixture_ptr impl ) : m_impl( impl ) {}
0234
0235 private:
0236
0237 void apply( test_unit& tu ) BOOST_OVERRIDE;
0238 base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new fixture_t( m_impl )); }
0239
0240
0241 test_unit_fixture_ptr m_impl;
0242 };
0243
0244
0245
0246 template<typename F>
0247 inline fixture_t
0248 fixture()
0249 {
0250 return fixture_t( test_unit_fixture_ptr( new unit_test::class_based_fixture<F>() ) );
0251 }
0252
0253
0254
0255 template<typename F, typename Arg>
0256 inline fixture_t
0257 fixture( Arg const& arg )
0258 {
0259 return fixture_t( test_unit_fixture_ptr( new unit_test::class_based_fixture<F,Arg>( arg ) ) );
0260 }
0261
0262
0263
0264 inline fixture_t
0265 fixture( boost::function<void()> const& setup, boost::function<void()> const& teardown = boost::function<void()>() )
0266 {
0267 return fixture_t( test_unit_fixture_ptr( new unit_test::function_based_fixture( setup, teardown ) ) );
0268 }
0269
0270
0271
0272
0273
0274
0275
0276 class BOOST_TEST_DECL precondition : public decorator::base {
0277 public:
0278 typedef boost::function<test_tools::assertion_result (test_unit_id)> predicate_t;
0279
0280 explicit precondition( predicate_t p ) : m_precondition( p ) {}
0281
0282 private:
0283
0284 void apply( test_unit& tu ) BOOST_OVERRIDE;
0285 base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new precondition( m_precondition )); }
0286
0287
0288 predicate_t m_precondition;
0289 };
0290
0291 }
0292
0293 using decorator::label;
0294 using decorator::expected_failures;
0295 using decorator::timeout;
0296 using decorator::description;
0297 using decorator::depends_on;
0298 using decorator::enable_if;
0299 using decorator::enabled;
0300 using decorator::disabled;
0301 using decorator::fixture;
0302 using decorator::precondition;
0303
0304 }
0305 }
0306
0307 #include <boost/test/detail/enable_warnings.hpp>
0308
0309 #endif