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