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) 5 6 // See http://www.boost.org/libs/test for the library home page. 7 // 8 /// @file 9 /// Defines global_fixture 10 // *************************************************************************** 11 12 #ifndef BOOST_TEST_TREE_GLOBAL_FIXTURE_HPP_091911GER 13 #define BOOST_TEST_TREE_GLOBAL_FIXTURE_HPP_091911GER 14 15 // Boost.Test 16 #include <boost/test/detail/config.hpp> 17 #include <boost/test/detail/global_typedef.hpp> 18 19 #include <boost/test/tree/observer.hpp> 20 #include <boost/test/tree/fixture.hpp> 21 22 #include <boost/test/detail/suppress_warnings.hpp> 23 24 25 //____________________________________________________________________________// 26 27 namespace boost { 28 namespace unit_test { 29 30 // ************************************************************************** // 31 // ************** global_configuration ************** // 32 // ************************************************************************** // 33 34 class BOOST_TEST_DECL global_configuration : public test_observer { 35 36 public: 37 // Constructor 38 global_configuration(); 39 40 /// Unregisters the global fixture from the framework 41 /// 42 /// This is called by the framework at shutdown time 43 void unregister_from_framework(); 44 45 // Dtor 46 ~global_configuration() BOOST_OVERRIDE; 47 48 // Happens after the framework global observer init has been done priority()49 int priority() BOOST_OVERRIDE { return 1; } 50 51 private: 52 bool registered; 53 }; 54 55 56 57 // ************************************************************************** // 58 // ************** global_fixture ************** // 59 // ************************************************************************** // 60 61 class BOOST_TEST_DECL global_fixture : public test_unit_fixture { 62 63 public: 64 // Constructor 65 global_fixture(); 66 67 /// Unregisters the global fixture from the framework 68 /// 69 /// This is called by the framework at shutdown time 70 void unregister_from_framework(); 71 72 // Dtor 73 ~global_fixture() BOOST_OVERRIDE; 74 75 private: 76 bool registered; 77 }; 78 79 //____________________________________________________________________________// 80 81 namespace ut_detail { 82 83 template<typename F> 84 struct global_configuration_impl : public global_configuration { 85 // Constructor global_configuration_implboost::unit_test::ut_detail::global_configuration_impl86 global_configuration_impl() : m_configuration_observer( 0 ) { 87 } 88 89 // test observer interface test_startboost::unit_test::ut_detail::global_configuration_impl90 void test_start( counter_t, test_unit_id ) BOOST_OVERRIDE { 91 m_configuration_observer = new F; 92 } 93 94 // test observer interface test_finishboost::unit_test::ut_detail::global_configuration_impl95 void test_finish() BOOST_OVERRIDE { 96 if(m_configuration_observer) { 97 delete m_configuration_observer; 98 m_configuration_observer = 0; 99 } 100 } 101 private: 102 // Data members 103 F* m_configuration_observer; 104 }; 105 106 template<typename F> 107 struct global_fixture_impl : public global_fixture { 108 // Constructor global_fixture_implboost::unit_test::ut_detail::global_fixture_impl109 global_fixture_impl() : m_fixture( 0 ) { 110 } 111 112 // test fixture interface setupboost::unit_test::ut_detail::global_fixture_impl113 void setup() BOOST_OVERRIDE { 114 m_fixture = new F; 115 setup_conditional(*m_fixture); 116 } 117 118 // test fixture interface teardownboost::unit_test::ut_detail::global_fixture_impl119 void teardown() BOOST_OVERRIDE { 120 if(m_fixture) { 121 teardown_conditional(*m_fixture); 122 } 123 delete m_fixture; 124 m_fixture = 0; 125 } 126 127 private: 128 // Data members 129 F* m_fixture; 130 }; 131 132 } // namespace ut_detail 133 } // namespace unit_test 134 } // namespace boost 135 136 #include <boost/test/detail/enable_warnings.hpp> 137 138 #endif // BOOST_TEST_TREE_GLOBAL_FIXTURE_HPP_091911GER 139 140