ctkTestRegistration.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * ctkTestRegistration.cpp
  3. * ctkTestSuiteEngine
  4. *
  5. * Created by Paolo Quadrani on 17/09/09.
  6. * Copyright 2009 B3C. All rights reserved.
  7. *
  8. * See Licence at: http://tiny.cc/QXJ4D
  9. *
  10. */
  11. #ifndef CTKTESTREGISTRATION_
  12. #define CTKTESTREGISTRATION_
  13. // Includes list
  14. #include "ctkTestRegistry.h"
  15. namespace ctkQA {
  16. /**
  17. * A macro to register a test class.
  18. *
  19. * This macro will create a static variable which registers the
  20. * testclass with the TestRegistry, and creates an instance of the
  21. * test class.
  22. *
  23. * Execute this macro in the body of your unit test's .cpp file, e.g.
  24. * class MyTest {
  25. * ...
  26. * };
  27. *
  28. * CTK_REGISTER_TEST(MyTest);
  29. */
  30. #define CTK_REGISTER_TEST(TestClass) \
  31. static ctkTestRegistration<TestClass> TestClass##Registration
  32. /**
  33. * A wrapper class around a test to manage registration and static
  34. * creation of an instance of the test class.
  35. * This class is used by CTK_REGISTER_TEST(), and you should not
  36. * use this class directly.
  37. */
  38. template<typename T>
  39. class ctkTestRegistration {
  40. public:
  41. ///!brief Registration class constructor.
  42. /** The constructor also register also the test passed as typename into the test suite registry. */
  43. ctkTestRegistration() {
  44. m_TestToRegister = new T();
  45. ctkTestRegistry::instance()->registerTest(m_TestToRegister);
  46. }
  47. ///!brief Registration class destructor
  48. ~ctkTestRegistration() {
  49. delete m_TestToRegister;
  50. }
  51. private:
  52. T* m_TestToRegister; ///< Test to be registered into the test suite.
  53. };
  54. }
  55. #endif //CTKTESTREGISTRATION_