Test.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef CPPUNIT_TEST_H
  2. #define CPPUNIT_TEST_H
  3. #include <cppunit/Portability.h>
  4. #include <string>
  5. CPPUNIT_NS_BEGIN
  6. class TestResult;
  7. class TestPath;
  8. /*! \brief Base class for all test objects.
  9. * \ingroup BrowsingCollectedTestResult
  10. *
  11. * All test objects should be a subclass of Test. Some test objects,
  12. * TestCase for example, represent one individual test. Other test
  13. * objects, such as TestSuite, are comprised of several tests.
  14. *
  15. * When a Test is run, the result is collected by a TestResult object.
  16. *
  17. * \see TestCase
  18. * \see TestSuite
  19. */
  20. class CPPUNIT_API Test
  21. {
  22. public:
  23. virtual ~Test() {};
  24. /*! \brief Run the test, collecting results.
  25. */
  26. virtual void run( TestResult *result ) =0;
  27. /*! \brief Return the number of test cases invoked by run().
  28. *
  29. * The base unit of testing is the class TestCase. This
  30. * method returns the number of TestCase objects invoked by
  31. * the run() method.
  32. */
  33. virtual int countTestCases () const =0;
  34. /*! \brief Returns the number of direct child of the test.
  35. */
  36. virtual int getChildTestCount() const =0;
  37. /*! \brief Returns the child test of the specified index.
  38. *
  39. * This method test if the index is valid, then call doGetChildTestAt() if
  40. * the index is valid. Otherwise std::out_of_range exception is thrown.
  41. *
  42. * You should override doGetChildTestAt() method.
  43. *
  44. * \param index Zero based index of the child test to return.
  45. * \return Pointer on the test. Never \c NULL.
  46. * \exception std::out_of_range is \a index is < 0 or >= getChildTestCount().
  47. */
  48. virtual Test *getChildTestAt( int index ) const;
  49. /*! \brief Returns the test name.
  50. *
  51. * Each test has a name. This name may be used to find the
  52. * test in a suite or registry of tests.
  53. */
  54. virtual std::string getName () const =0;
  55. /*! \brief Finds the test with the specified name and its parents test.
  56. * \param testName Name of the test to find.
  57. * \param testPath If the test is found, then all the tests traversed to access
  58. * \a test are added to \a testPath, including \c this and \a test.
  59. * \return \c true if a test with the specified name is found, \c false otherwise.
  60. */
  61. virtual bool findTestPath( const std::string &testName,
  62. TestPath &testPath ) const;
  63. /*! \brief Finds the specified test and its parents test.
  64. * \param test Test to find.
  65. * \param testPath If the test is found, then all the tests traversed to access
  66. * \a test are added to \a testPath, including \c this and \a test.
  67. * \return \c true if the specified test is found, \c false otherwise.
  68. */
  69. virtual bool findTestPath( const Test *test,
  70. TestPath &testPath ) const;
  71. /*! \brief Finds the test with the specified name in the hierarchy.
  72. * \param testName Name of the test to find.
  73. * \return Pointer on the first test found that is named \a testName. Never \c NULL.
  74. * \exception std::invalid_argument if no test named \a testName is found.
  75. */
  76. virtual Test *findTest( const std::string &testName ) const;
  77. /*! \brief Resolved the specified test path with this test acting as 'root'.
  78. * \param testPath Test path string to resolve.
  79. * \return Resolved TestPath.
  80. * \exception std::invalid_argument if \a testPath could not be resolved.
  81. * \see TestPath.
  82. */
  83. virtual TestPath resolveTestPath( const std::string &testPath ) const;
  84. protected:
  85. /*! Throws an exception if the specified index is invalid.
  86. * \param index Zero base index of a child test.
  87. * \exception std::out_of_range is \a index is < 0 or >= getChildTestCount().
  88. */
  89. virtual void checkIsValidIndex( int index ) const;
  90. /*! \brief Returns the child test of the specified valid index.
  91. * \param index Zero based valid index of the child test to return.
  92. * \return Pointer on the test. Never \c NULL.
  93. */
  94. virtual Test *doGetChildTestAt( int index ) const =0;
  95. };
  96. CPPUNIT_NS_END
  97. #endif // CPPUNIT_TEST_H