global_fixture.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. // Dtor
  29. virtual ~global_configuration();
  30. // Happens after the framework global observer init has been done
  31. virtual int priority() { return 1; }
  32. };
  33. // ************************************************************************** //
  34. // ************** global_fixture ************** //
  35. // ************************************************************************** //
  36. class BOOST_TEST_DECL global_fixture : public test_unit_fixture {
  37. public:
  38. // Constructor
  39. global_fixture();
  40. // Dtor
  41. virtual ~global_fixture();
  42. };
  43. //____________________________________________________________________________//
  44. namespace ut_detail {
  45. template<typename F>
  46. struct global_configuration_impl : public global_configuration {
  47. // Constructor
  48. global_configuration_impl() : m_configuration_observer( 0 ) {
  49. }
  50. // test observer interface
  51. virtual void test_start( counter_t ) {
  52. m_configuration_observer = new F;
  53. }
  54. // test observer interface
  55. virtual void test_finish() {
  56. if(m_configuration_observer) {
  57. delete m_configuration_observer;
  58. m_configuration_observer = 0;
  59. }
  60. }
  61. private:
  62. // Data members
  63. F* m_configuration_observer;
  64. };
  65. template<typename F>
  66. struct global_fixture_impl : public global_fixture {
  67. // Constructor
  68. global_fixture_impl() : m_fixture( 0 ) {
  69. }
  70. // test fixture interface
  71. virtual void setup() {
  72. m_fixture = new F;
  73. setup_conditional(*m_fixture);
  74. }
  75. // test fixture interface
  76. virtual void teardown() {
  77. if(m_fixture) {
  78. teardown_conditional(*m_fixture);
  79. }
  80. delete m_fixture;
  81. m_fixture = 0;
  82. }
  83. private:
  84. // Data members
  85. F* m_fixture;
  86. };
  87. } // namespace ut_detail
  88. } // namespace unit_test
  89. } // namespace boost
  90. #include <boost/test/detail/enable_warnings.hpp>
  91. #endif // BOOST_TEST_TREE_GLOBAL_FIXTURE_HPP_091911GER