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: 74640 $
12 // Description : defines fixture interface and object makers
13 // ***************************************************************************
15 #ifndef BOOST_TEST_TREE_FIXTURE_HPP_100311GER
16 #define BOOST_TEST_TREE_FIXTURE_HPP_100311GER
19 #include <boost/test/detail/config.hpp>
22 #include <boost/shared_ptr.hpp>
23 #include <boost/scoped_ptr.hpp>
24 #include <boost/function/function0.hpp>
26 #include <boost/test/detail/suppress_warnings.hpp>
28 //____________________________________________________________________________//
33 // ************************************************************************** //
34 // ************** test_unit_fixture ************** //
35 // ************************************************************************** //
37 class BOOST_TEST_DECL test_unit_fixture {
39 virtual ~test_unit_fixture() {}
42 virtual void setup() = 0;
43 virtual void teardown() = 0;
46 typedef shared_ptr<test_unit_fixture> test_unit_fixture_ptr;
48 // ************************************************************************** //
49 // ************** class_based_fixture ************** //
50 // ************************************************************************** //
52 template<typename F, typename Arg=void>
53 class class_based_fixture : public test_unit_fixture {
56 explicit class_based_fixture( Arg const& arg ) : m_inst(), m_arg( arg ) {}
60 virtual void setup() { m_inst.reset( new F( m_arg ) ); }
61 virtual void teardown() { m_inst.reset(); }
68 //____________________________________________________________________________//
71 class class_based_fixture<F,void> : public test_unit_fixture {
74 class_based_fixture() : m_inst( 0 ) {}
78 virtual void setup() { m_inst.reset( new F ); }
79 virtual void teardown() { m_inst.reset(); }
85 //____________________________________________________________________________//
87 // ************************************************************************** //
88 // ************** function_based_fixture ************** //
89 // ************************************************************************** //
91 class function_based_fixture : public test_unit_fixture {
94 function_based_fixture( boost::function<void ()> const& setup_, boost::function<void ()> const& teardown_ )
96 , m_teardown( teardown_ )
102 virtual void setup() { if( m_setup ) m_setup(); }
103 virtual void teardown() { if( m_teardown ) m_teardown(); }
106 boost::function<void ()> m_setup;
107 boost::function<void ()> m_teardown;
110 } // namespace unit_test
113 #include <boost/test/detail/enable_warnings.hpp>
115 #endif // BOOST_TEST_TREE_FIXTURE_HPP_100311GER