You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovtTestFixture.h 2.1KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*********************************************************************
  2. * Software License Agreement (AGPL-3 License)
  3. *
  4. * OpenViBE SDK Test Software
  5. * Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
  6. * Copyright (C) Inria, 2015-2017,V1.0
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program.
  19. * If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #pragma once
  22. #include <memory>
  23. namespace OpenViBE {
  24. namespace Test {
  25. /**
  26. * \struct TestFixture
  27. * \author cgarraud (INRIA)
  28. * \date 2016-02-08
  29. * \brief Base abstract struct for test fixture
  30. *
  31. * A test fixture is used when an environment has to be set for a specific test.
  32. * TestFixture implementation should not be used directly but through ScopedTest.
  33. */
  34. struct TestFixture
  35. {
  36. virtual ~TestFixture() = default;
  37. TestFixture() = default;
  38. /**
  39. * \brief Setup resources for the test
  40. */
  41. virtual void setUp() = 0;
  42. /**
  43. * \brief Release resources
  44. */
  45. virtual void tearDown() = 0;
  46. private:
  47. TestFixture& operator=(const TestFixture&) = delete;
  48. TestFixture(const TestFixture&) = delete;
  49. };
  50. /**
  51. * \struct ScopedTest
  52. * \author cgarraud (INRIA)
  53. * \date 2016-02-08
  54. * \brief Class used to ensure RAII when using TestFixture
  55. *
  56. * A scoped object is a wrapper around a test fixture used to
  57. * ensure RAII when running tests.
  58. */
  59. template <typename T>
  60. struct ScopedTest
  61. {
  62. template <typename... TArgs>
  63. explicit ScopedTest(TArgs&&... args) : fixture(new T(std::forward<TArgs>(args)...)) { fixture->setUp(); }
  64. ~ScopedTest() { fixture->tearDown(); }
  65. const T* operator->() const { return fixture.get(); }
  66. T* operator->() { return fixture.get(); }
  67. std::unique_ptr<T> fixture;
  68. };
  69. } // namespace Test
  70. } // namespace OpenViBE