TestSuite.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // TestSuite.h
  3. //
  4. #ifndef CppUnit_TestSuite_INCLUDED
  5. #define CppUnit_TestSuite_INCLUDED
  6. #include "CppUnit/CppUnit.h"
  7. #include "CppUnit/Guards.h"
  8. #include "CppUnit/Test.h"
  9. #include <vector>
  10. #include <string>
  11. namespace CppUnit {
  12. class TestResult;
  13. /*
  14. * A TestSuite is a Composite of Tests.
  15. * It runs a collection of test cases. Here is an example.
  16. *
  17. * TestSuite *suite= new TestSuite();
  18. * suite->addTest(new TestCaller<MathTest> ("testAdd", testAdd));
  19. * suite->addTest(new TestCaller<MathTest> ("testDivideByZero", testDivideByZero));
  20. *
  21. * Note that TestSuites assume lifetime
  22. * control for any tests added to them.
  23. *
  24. * see Test and TestCaller
  25. */
  26. class CppUnit_API TestSuite: public Test
  27. {
  28. REFERENCEOBJECT (TestSuite)
  29. public:
  30. TestSuite(const std::string& name = "");
  31. ~TestSuite();
  32. void run(TestResult* result);
  33. int countTestCases();
  34. void addTest(Test* test);
  35. std::string toString();
  36. virtual void deleteContents();
  37. const std::vector<Test*> tests() const;
  38. private:
  39. std::vector<Test*> _tests;
  40. const std::string _name;
  41. };
  42. // Default constructor
  43. inline TestSuite::TestSuite(const std::string& name): _name(name)
  44. {
  45. }
  46. // Destructor
  47. inline TestSuite::~TestSuite()
  48. {
  49. deleteContents();
  50. }
  51. // Adds a test to the suite.
  52. inline void TestSuite::addTest(Test* test)
  53. {
  54. _tests.push_back(test);
  55. }
  56. // Returns a std::string representation of the test suite.
  57. inline std::string TestSuite::toString()
  58. {
  59. return "suite " + _name;
  60. }
  61. // Returns all tests
  62. inline const std::vector<Test*> TestSuite::tests() const
  63. {
  64. return _tests;
  65. }
  66. } // namespace CppUnit
  67. #endif // CppUnit_TestSuite_INCLUDED