global_fixture.hpp 3.6 KB

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