diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-04-12 18:28:48 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-04-12 18:28:48 +0000 |
| commit | ed406a2966e62072fa6afaca8abc578db7c0c9fb (patch) | |
| tree | ab8d2ffb462c3c955b2e339e8cc19f1a6be8bd0f /include/cppunit | |
| parent | fc9c76622b19adfcdebce682d9d49db8fb9336ef (diff) | |
| download | cppunit-ed406a2966e62072fa6afaca8abc578db7c0c9fb.tar.gz | |
Makefile.
Makefile.am: added examples/qt to tar ball release.
* TODO: heavily updated.
* contrib/msvc/CppUnit*.wwtpl: changed base class for unit test to TestFixture.
* include/cppunit/Test.h: removed toString() method. Not used by the framework
and source of confusions with getName().
Added getChildTestCount() and getChildTestAt(), introducing the composite pattern
at top level. Added utility methods findTest() and findTestPath().
* src/cppunit/Test.cpp: added. Implementation of new utility methods.
* include/cppunit/TestCase.h:
* src/cppunit/TestCase.cpp: inherits TestLeaf. Removed toString(), run(void) and
defaultResult(). Removed default constructor.
* src/cppunit/TestCase.cpp:
* src/cppunit/TestSuite.cpp: fixed some includes that used "" instead of <>.
* include/cppunit/TestComposite.h:
* src/cppunit/TestComposite.cpp: added. Common implementation of Test for composite
tests (TestSuite).
* include/cppunit/TestFailure.h:
* src/cppunit/TestFailure.cpp: removed toString().
* include/cppunit/TestLeaf.h:
* src/cppunit/TestLeaf.cpp: added. Common implementation of Test for single test
(TestCase).
* include/cppunit/TestListener.h: added TimingListener example to documentation.
* include/cppunit/TestPath.h:
* src/cppunit/TestPath.cpp: added. List of test traversed to access a test in the
test hierarchy.
* include/cppunit/TestRunner.h: added. Generic TestRunner.
* src/cppunit/TestRunner.cpp: moved to TextTestRunner.cpp. Added new implementation
of includecppunit/TestRunner.h.
* include/cppunit/TestSuite.h:
* src/cppunit/TestSuite.cpp: inherits TestComposite and implements new Test
interface. Removed toString().
* src/cppunit/TextTestRunner.cpp: moved from TestRunner.cpp. Implementation of
include/cppunit/ui/text/TestRunner.h.
* include/cppunit/extensions/RepeatedTest.h:
* src/cppunit/RepeatedTest.cpp: removed toString().
* include/cppunit/extensions/TestDecorator.h: inherits TestLeaf.
Removed toString()
* include/cppunit/XmlOutputter.h:
* src/cppunit/XmlOutputter.cpp:
* examples/cppunittest/XmlOutputterTest.cpp:
* examples/cppunittest/XmlOutputterTest.h: XML outputter now escape node content.
Add unit test for that bug (#540944). Added style sheet support. Modified
XML structure: failure message as its own element.
* src/msvc/testrunner/TestRunnerModel.h:
* src/msvc/testrunner/TestRunnerModel.cpp: used Test::findTest() to find a test
by name instead of using RTTI. Added toAnsiString() for convertion when
compiling as UNICODE.
* src/msvc/testrunner/TreeHierarchyDlg.h:
* src/msvc/testrunner/TreeHierarchyDlg.cpp: used new composite interface of Test
to explorer the test hierarchy instead of RTTI.
* examples/cppunittest/TestPathTest.h:
* examples/cppunittest/TestPathTest.cpp: added, unit tests for TestPath.
* examples/cppunittest/TestCaseTest.h:
* examples/cppunittest/TestCaseTest.cpp: added test for TestLeaf.
* examples/cppunittest/TestSuiteTest.h:
* examples/cppunittest/TestSuiteTest.cpp: added test for TestComposite and
new Test interface.
Diffstat (limited to 'include/cppunit')
| -rw-r--r-- | include/cppunit/Makefile.am | 5 | ||||
| -rw-r--r-- | include/cppunit/Test.h | 107 | ||||
| -rw-r--r-- | include/cppunit/TestCase.h | 18 | ||||
| -rw-r--r-- | include/cppunit/TestComposite.h | 41 | ||||
| -rw-r--r-- | include/cppunit/TestFailure.h | 2 | ||||
| -rw-r--r-- | include/cppunit/TestLeaf.h | 43 | ||||
| -rw-r--r-- | include/cppunit/TestListener.h | 53 | ||||
| -rw-r--r-- | include/cppunit/TestPath.h | 198 | ||||
| -rw-r--r-- | include/cppunit/TestRunner.h | 134 | ||||
| -rw-r--r-- | include/cppunit/TestSuite.h | 36 | ||||
| -rw-r--r-- | include/cppunit/XmlOutputter.h | 8 | ||||
| -rw-r--r-- | include/cppunit/extensions/RepeatedTest.h | 22 | ||||
| -rw-r--r-- | include/cppunit/extensions/TestDecorator.h | 59 | ||||
| -rw-r--r-- | include/cppunit/ui/text/TestRunner.h | 6 |
14 files changed, 635 insertions, 97 deletions
diff --git a/include/cppunit/Makefile.am b/include/cppunit/Makefile.am index 01e0019..803f725 100644 --- a/include/cppunit/Makefile.am +++ b/include/cppunit/Makefile.am @@ -19,12 +19,17 @@ libcppunitinclude_HEADERS = \ TestAssert.h \ TestCase.h \ TestCaller.h \ + TestComposite.h \ TestFailure.h \ TestFixture.h \ + TestLeaf.h \ + TestPath.h \ TestResult.h \ TestResultCollector.h \ + TestRunner.h \ TestSucessListener.h \ TestSuite.h \ + TestTest.h \ TextOutputter.h \ TextTestProgressListener.h \ TextTestResult.h \ diff --git a/include/cppunit/Test.h b/include/cppunit/Test.h index 2ee2a48..dde4958 100644 --- a/include/cppunit/Test.h +++ b/include/cppunit/Test.h @@ -7,6 +7,7 @@ namespace CppUnit { class TestResult; +class TestPath; /*! \brief Base class for all test objects. * \ingroup BrowsingCollectedTestResult @@ -23,37 +24,85 @@ class TestResult; class CPPUNIT_API Test { public: - virtual ~Test () {}; - - /*! \brief Run the test, collecting results. - */ - virtual void run (TestResult *result) = 0; - - /*! \brief Return the number of test cases invoked by run(). - * - * The base unit of testing is the class TestCase. This - * method returns the number of TestCase objects invoked by - * the run() method. - */ - virtual int countTestCases () const = 0; - - /*! \brief Returns the test name. - * - * Each test has a name. This name may be used to find the - * test in a suite or registry of tests. - */ - virtual std::string getName () const = 0; - - /*! \brief Description of the test, for diagnostic output. - * - * The test description will typically include the test name, - * but may have additional description. For example, a test - * suite named <tt>complex_add</tt> may be described as - * <tt>suite complex_add</tt>. - */ - virtual std::string toString () const = 0; + virtual ~Test() {}; + /*! \brief Run the test, collecting results. + */ + virtual void run( TestResult *result ) =0; + /*! \brief Return the number of test cases invoked by run(). + * + * The base unit of testing is the class TestCase. This + * method returns the number of TestCase objects invoked by + * the run() method. + */ + virtual int countTestCases () const =0; + + /*! \brief Returns the number of direct child of the test. + */ + virtual int getChildTestCount() const =0; + + /*! \brief Returns the test name. + * + * Each test has a name. This name may be used to find the + * test in a suite or registry of tests. + */ + virtual std::string getName () const =0; + + /*! \brief Returns the child test of the specified index. + * + * This method test if the index is valid, then call doGetChildTestAt() if + * the index is valid. Otherwise std::out_of_range exception is thrown. + * + * You should override doGetChildTestAt() method. + * + * \param index Zero based index of the child test to return. + * \return Pointer on the test. Never \c NULL. + * \exception std::out_of_range is \a index is < 0 or >= getChildTestCount(). + */ + virtual Test *getChildTestAt( int index ) const; + + /*! \brief Finds the test with the specified name and its parents test. + * \param testName Name of the test to find. + * \return \c true if a test with the specified name is found, \c false otherwise. + */ + virtual bool findTestPath( const std::string &testName, + TestPath &testPath ); + + /*! \brief Finds the specified test and its parents test. + * \param test Test to find. + * \return \c true if the specified test is found, \c false otherwise. + */ + virtual bool findTestPath( const Test *test, + TestPath &testPath ); + + /*! \brief Finds the test with the specified name in the hierarchy. + * \param testName Name of the test to find. + * \return Pointer on the first test found that is named \a testName. Never \c NULL. + * \exception std::invalid_argument if no test named \a testName is found. + */ + virtual Test *findTest( const std::string &testName ) const; + + /*! \brief Resolved the specified test path with this test acting as 'root'. + * \param testPath Test path string to resolve. + * \return Resolved TestPath. + * \exception std::invalid_argument if \a testPath could not be resolved. + * \see TestPath. + */ + virtual TestPath resolveTestPath( const std::string &testPath ); + +protected: + /*! Throws an exception if the specified index is invalid. + * \param Zero base index of a child test. + * \exception std::out_of_range is \a index is < 0 or >= getChildTestCount(). + */ + virtual void checkIsValidIndex( int index ) const; + + /*! \brief Returns the child test of the specified valid index. + * \param index Zero based valid index of the child test to return. + * \return Pointer on the test. Never \c NULL. + */ + virtual Test *doGetChildTestAt( int index ) const =0; }; diff --git a/include/cppunit/TestCase.h b/include/cppunit/TestCase.h index f9cb1d9..0d319dc 100644 --- a/include/cppunit/TestCase.h +++ b/include/cppunit/TestCase.h @@ -2,7 +2,7 @@ #define CPPUNIT_TESTCASE_H #include <cppunit/Portability.h> -#include <cppunit/Test.h> +#include <cppunit/TestLeaf.h> #include <cppunit/TestAssert.h> #include <cppunit/TestFixture.h> #include <string> @@ -23,30 +23,24 @@ class TestResult; * You are expected to subclass TestCase is you need to write a class similiar * to TestCaller. */ -class CPPUNIT_API TestCase : public Test, +class CPPUNIT_API TestCase : public TestLeaf, public TestFixture { public: - TestCase( std::string Name ); - //! \internal + TestCase( const std::string &name ); + TestCase(); + ~TestCase(); virtual void run(TestResult *result); - virtual int countTestCases() const; + std::string getName() const; - std::string toString() const; - //! FIXME: what is this for? - virtual TestResult *run(); - protected: //! FIXME: this should probably be pure virtual. virtual void runTest(); - - //! Create TestResult for the run(void) method. - TestResult *defaultResult(); private: TestCase( const TestCase &other ); diff --git a/include/cppunit/TestComposite.h b/include/cppunit/TestComposite.h new file mode 100644 index 0000000..7faeea8 --- /dev/null +++ b/include/cppunit/TestComposite.h @@ -0,0 +1,41 @@ +#ifndef CPPUNIT_TESTCOMPSITE_H // -*- C++ -*- +#define CPPUNIT_TESTCOMPSITE_H + +#include <cppunit/Test.h> +#include <string> + +namespace CppUnit { + + +/*! \brief A Composite of Tests. + * + * Base class for all test composites. Subclass this class if you need to implement + * a custom TestSuite. + * + * \see Test, TestSuite. + */ +class CPPUNIT_API TestComposite : public Test +{ +public: + TestComposite( const std::string &name = "" ); + + ~TestComposite(); + + void run( TestResult *result ); + + int countTestCases() const; + + std::string getName() const; + +private: + TestComposite( const TestComposite &other ); + TestComposite &operator =( const TestComposite &other ); + +private: + const std::string m_name; +}; + + +} // namespace CppUnit + +#endif // CPPUNIT_TESTCOMPSITE_H diff --git a/include/cppunit/TestFailure.h b/include/cppunit/TestFailure.h index a610072..798d0c5 100644 --- a/include/cppunit/TestFailure.h +++ b/include/cppunit/TestFailure.h @@ -38,8 +38,6 @@ public: virtual bool isError() const; virtual std::string failedTestName() const; - - virtual std::string toString() const; virtual TestFailure *clone() const; diff --git a/include/cppunit/TestLeaf.h b/include/cppunit/TestLeaf.h new file mode 100644 index 0000000..393dda7 --- /dev/null +++ b/include/cppunit/TestLeaf.h @@ -0,0 +1,43 @@ +#ifndef CPPUNIT_TESTLEAF_H +#define CPPUNIT_TESTLEAF_H + +#include <cppunit/Test.h> + + +namespace CppUnit { + +/*! \brief A single test object. + * + * Base class for single test case: a test that doesn't have any children. + * + */ +class CPPUNIT_API TestLeaf: public Test +{ +public: + /*! Returns 1 as the default number of test cases invoked by run(). + * + * You may override this method when many test cases are invoked (RepeatedTest + * for example). + * + * \return 1. + * \see Test::countTestCases(). + */ + int countTestCases() const; + + /*! Returns the number of child of this test case: 0. + * + * You should never override this method: a TestLeaf as no children by definition. + * + * \return 0. + */ + int getChildTestCount() const; + + /*! Always throws std::out_of_range. + * \see Test::doGetChildTestAt(). + */ + Test *doGetChildTestAt( int index ) const; +}; + +} // namespace CppUnit + +#endif // CPPUNIT_TESTLEAF_H diff --git a/include/cppunit/TestListener.h b/include/cppunit/TestListener.h index 595bcb7..2140fe4 100644 --- a/include/cppunit/TestListener.h +++ b/include/cppunit/TestListener.h @@ -25,6 +25,59 @@ class TestFailure; * unanticipated problems signified by exceptions that are not generated * by the framework. * + * \code + * + * #include <cppunit/TestListener.h> + * #include <cppunit/Test.h> + * #include <time.h> // for clock() + * + * class TimingListener : public CppUnit::TestListener + * { + * public: + * void startTest( CppUnit::Test *test ) + * { + * _chronometer.start(); + * } + * + * void endTest( CppUnit::Test *test ) + * { + * _chronometer.end(); + * addTest( test, _chronometer.elapsedTime() ); + * } + * + * // ... (interface to add/read test timing result) + * + * private: + * + * class Clock + * { + * public: + * Clock() : _startTime( 0 ), _endTime(0) {} + * + * void start() + * { + * _startTime = clock(); + * } + * + * void end() + * { + * _endTime = clock(); + * } + * + * double elapsedTime() const + * { + * return double(_endTime - _startTime) / CLOCKS_PER_SEC; + * } + * + * private: + * clock_t _startTime, _endTime; + * }; + * + * Clock _chronometer; + * }; + * + * + * * \see TestResult */ class CPPUNIT_API TestListener diff --git a/include/cppunit/TestPath.h b/include/cppunit/TestPath.h new file mode 100644 index 0000000..02016ef --- /dev/null +++ b/include/cppunit/TestPath.h @@ -0,0 +1,198 @@ +#ifndef CPPUNIT_TESTPATH_H +#define CPPUNIT_TESTPATH_H + +#include <cppunit/Portability.h> + +#if CPPUNIT_NEED_DLL_DECL +#pragma warning( push ) +#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z +#endif + +#include <deque> + +namespace CppUnit { + +class Test; + +#if CPPUNIT_NEED_DLL_DECL + template class CPPUNIT_API std::deque<Test *>; +#endif + + +/*! \brief A List of Test representing a path to access a Test. + * \ingroup ExecutingTest + * + * The path can be converted to a string and resolved from a string with toString() + * and TestPath( Test *root, const std::string &pathAsString ). + * + * Pointed tests are not owned by the class. + * + * \see Test::resolvedTestPath() + */ +class CPPUNIT_API TestPath +{ +public: + /*! Constructs an invalid path. + * + * The path is invalid until a test is added with add(). + */ + TestPath(); + + /*! Constructs a valid path. + * + * \param root Test to add. + */ + TestPath( Test *root ); + + /*! Constructs a path using a slice of another path. + * \param otherPath Path the test are copied from. + * \param indexFirst Zero based index of the first test to copy. Adjusted to be in valid + * range. \a count is adjusted with \a indexFirst. + * \param count Number of tests to copy. If < 0 then all test starting from index + * \a indexFirst are copied. + */ + TestPath( const TestPath &otherPath, + int indexFirst, + int count = -1 ); + + /*! Resolves a path from a string returned by toString(). + * + * If \a pathAsString is an absolute path (begins with '/'), then the first test name + * of the path must be the name of \a searchRoot. Otherwise, \a pathAsString is a + * relative path, and the first test found using Test::findTest() matching the first + * test name is used as root. An empty string resolve to a path containing + * \a searchRoot. + * + * The resolved path is always valid. + * + * \param searchRoot Test used to resolve the path. + * \param pathAsString String that contains the path as a string created by toString(). + * \exception std::invalid_argument if one of the test names can not be resolved. + * \see toString(). + */ + TestPath( Test *searchRoot, + const std::string &pathAsString ); + + virtual ~TestPath(); + + /*! Tests if the path contains at least one test. + * \return \c true if the path contains at least one test, otherwise returns \c false. + */ + virtual bool isValid() const; + + /*! Adds a test to the path. + * \param test Pointer on the test to add. Must not be \c NULL. + */ + virtual void add( Test *test ); + + /*! Adds all the tests of the specified path. + * \param path Path that contains the test to add. + */ + virtual void add( const TestPath &path ); + + /*! Inserts a test at the specified index. + * \param test Pointer on the test to insert. Must not be \c NULL. + * \param index Zero based index indicating where the test is inserted. + * \exception std::out_of_range is \a index < 0 or \a index > getTestCount(). + */ + virtual void insert( Test *test, int index ); + + /*! Inserts all the tests at the specified path at a given index. + * \param path Path that contains the test to insert. + * \param index Zero based index indicating where the tests are inserted. + * \exception std::out_of_range is \a index < 0 or \a index > getTestCount(), and + * \a path is valid. + */ + virtual void insert( const TestPath &path, int index ); + + /*! Removes all the test from the path. + * + * The path becomes invalid after this call. + */ + virtual void removeTests(); + + /*! Removes the test at the specified index of the path. + * \param index Zero based index of the test to remove. + * \exception std::out_of_range is \a index < 0 or \a index >= getTestCount(). + */ + virtual void removeTest( int index ); + + /*! Removes the last test. + * \exception std::out_of_range is the path is invalid. + * \see isValid(). + */ + virtual void up(); + + /*! Returns the number of tests in the path. + * \return Number of tests in the path. + */ + virtual int getTestCount() const; + + /*! Returns the test of the specified index. + * \param index Zero based index of the test to return. + * \return Pointer on the test at index \a index. Never \c NULL. + * \exception std::out_of_range is \a index < 0 or \a index >= getTestCount(). + */ + virtual Test *getTestAt( int index ) const; + + /*! \brief Get the last test of the path. + * \return Pointer on the last test (test at the bottom of the hierarchy). Never \c NULL. + * \exception std::out_of_range if the path is not valid ( isValid() returns \c false ). + */ + virtual Test *getChildTest() const; + + /*! \brief Returns the path as a string. + * + * For example, if a path is composed of three tests named "All Tests", "Math" and + * "Math::testAdd", toString() will return: + * + * "All Tests/Math/Math::testAdd". + * + * \return A string composed of the test names separated with a '/'. It is a relative + * path. + */ + virtual std::string toString() const; + +protected: + /*! Checks that the specified test index is within valid range. + * \param index Zero based index to check. + * \exception std::out_of_range is \a index < 0 or \a index >= getTestCount(). + */ + void checkIndexValid( int index ) const; + + /// A list of test names. + typedef std::deque<std::string> PathTestNames; + + /*! Splits a path string into its test name components. + * \param pathAsString Path string created with toString(). + * \param testNames Test name components are added to that container. + * \return \c true if the path is relative (does not begin with '/'), \c false + * if it is absolute (begin with '/'). + */ + bool splitPathString( const std::string &pathAsString, + PathTestNames &testNames ); + + /*! Finds the actual root of a path string and get the path string name components. + * \param searchRoot Test used as root if the path string is absolute, or to search + * the root test if the path string is relative. + * \param pathAsString Path string. May be absolute or relative. + * \param testNames Test name components are added to that container. + * \return Pointer on the resolved root test. Never \c NULL. + * \exception std::invalid_argument if either the root name can not be resolved or if + * pathAsString contains no name components. + */ + Test *findActualRoot( Test *searchRoot, + const std::string &pathAsString, + PathTestNames &testNames ); + +protected: + typedef std::deque<Test *> Tests; + Tests _tests; + +}; + + +} // namespace CppUnit + +#endif // CPPUNIT_TESTPATH_H + diff --git a/include/cppunit/TestRunner.h b/include/cppunit/TestRunner.h new file mode 100644 index 0000000..7c7073e --- /dev/null +++ b/include/cppunit/TestRunner.h @@ -0,0 +1,134 @@ +#ifndef CPPUNIT_TESTRUNNER_H +#define CPPUNIT_TESTRUNNER_H + +#include <cppunit/TestSuite.h> +#include <string> + +namespace CppUnit +{ + +class Test; +class TestResult; + + +/*! \brief Generic test runner. + * \ingroup ExecutingTest + * + * The TestRunner assumes ownership of all added tests: you can not add test + * or suite that are local variable since they can't be deleted. + * + * Example of usage: + * \code + * #include <cppunit/extensions/TestFactoryRegistry.h> + * #include <cppunit/CompilerOutputter.h> + * #include <cppunit/TestResult.h> + * #include <cppunit/TestResultCollector.h> + * #include <cppunit/TestRunner.h> + * #include <cppunit/TextTestProgressListener.h> + * + * + * int + * main( int argc, char* argv[] ) + * { + * std::string testPath = (argc > 1) ? std::string(argv[1]) : ""; + * + * // Create the event manager and test controller + * CppUnit::TestResult controller; + * + * // Add a listener that colllects test result + * CppUnit::TestResultCollector result; + * controller.addListener( &result ); + * + * // Add a listener that print dots as test run. + * CppUnit::TextTestProgressListener progress; + * controller.addListener( &progress ); + * + * // Add the top suite to the test runner + * CppUnit::TestRunner runner; + * runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() ); + * try + * { + * std::cout << "Running " << testPath; + * runner.run( controller, testPath ); + * + * std::cerr << std::endl; + * + * // Print test in a compiler compatible format. + * CppUnit::CompilerOutputter outputter( &result, std::cerr ); + * outputter.write(); + * } + * catch ( std::invalid_argument &e ) // Test path not resolved + * { + * std::cerr << std::endl + * << "ERROR: " << e.what() + * << std::endl; + * return 0; + * } + * + * return result.wasSuccessful() ? 0 : 1; + * } + * \endcode + */ +class CPPUNIT_API TestRunner +{ +public: + /*! Constructs a TestRunner object. + */ + TestRunner( ); + + /// Destructor. + virtual ~TestRunner(); + + /*! Adds the specified test. + * \param test Test to add. The TestRunner takes ownership of the test. + */ + virtual void addTest( Test *test ); + + /*! Runs a test using the specified controller. + * \param controller Event manager and controller used for testing + * \param testPath Test path string. See Test::resolveTestPath() for detail. + * \exception std::invalid_argument if no test matching \a testPath is found. + * see TestPath::TestPath( Test*, const std::string &) + * for detail. + */ + virtual void run( TestResult &controller, + const std::string &testPath = "" ); + +protected: + class CPPUNIT_API WrappingSuite : public TestSuite + { + public: + WrappingSuite( const std::string &name = "All Tests" ); + + int getChildTestCount() const; + + std::string getName () const; + + void run( TestResult *result ); + + protected: + Test *doGetChildTestAt( int index ) const; + + bool hasOnlyOneTest() const; + + Test *getUniqueChildTest() const; + }; + +protected: + WrappingSuite *m_suite; + +private: + /// Prevents the use of the copy constructor. + TestRunner( const TestRunner © ); + + /// Prevents the use of the copy operator. + void operator =( const TestRunner © ); + +private: +}; + + +} // namespace CppUnit + + +#endif // CPPUNIT_TESTRUNNER_H diff --git a/include/cppunit/TestSuite.h b/include/cppunit/TestSuite.h index 3cd77cb..7fdafc9 100644 --- a/include/cppunit/TestSuite.h +++ b/include/cppunit/TestSuite.h @@ -8,14 +8,11 @@ #pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z #endif -#include <cppunit/Test.h> +#include <cppunit/TestComposite.h> #include <vector> -#include <string> namespace CppUnit { -class TestResult; - #if CPPUNIT_NEED_DLL_DECL template class CPPUNIT_API std::vector<Test *>; #endif @@ -32,34 +29,41 @@ class TestResult; * suite->addTest(new CppUnit::TestCaller<MathTest> ( * "testDivideByZero", testDivideByZero)); * \endcode - * Note that TestSuites assume lifetime + * Note that \link TestSuite TestSuites assume lifetime * control for any tests added to them. * * TestSuites do not register themselves in the TestRegistry. * \see Test * \see TestCaller */ - - -class CPPUNIT_API TestSuite : public Test +class CPPUNIT_API TestSuite : public TestComposite { public: + /*! Constructs a test suite with the specified name. + */ TestSuite( std::string name = "" ); - ~TestSuite(); - void run( TestResult *result ); - int countTestCases() const; - std::string getName() const; - std::string toString() const; + ~TestSuite(); + /*! Adds the specified test to the suite. + * \param test Test to add. Must not be \c NULL. + */ void addTest( Test *test ); + + /*! Returns the list of the tests (DEPRECATED). + * \deprecated Use getChildTestCount() & getChildTestAt() of the + * TestComposite interface instead. + * \return Reference on a vector that contains the tests of the suite. + */ const std::vector<Test *> &getTests() const; + /*! Destroys all the tests of the suite. + */ virtual void deleteContents(); -private: - TestSuite( const TestSuite &other ); - TestSuite &operator =( const TestSuite &other ); + int getChildTestCount() const; + + Test *doGetChildTestAt( int index ) const; private: std::vector<Test *> m_tests; diff --git a/include/cppunit/XmlOutputter.h b/include/cppunit/XmlOutputter.h index 80fbcee..e1b12f5 100644 --- a/include/cppunit/XmlOutputter.h +++ b/include/cppunit/XmlOutputter.h @@ -49,6 +49,13 @@ public: */ virtual void write(); + /*! Sets the XSL style sheet used. + * + * \param styleSheet Name of the style sheet used. If empty, then no style sheet + * is used (default). + */ + virtual void setStyleSheet( const std::string &styleSheet ); + /*! \brief An XML Element. * \warning This class will probably be replaced with an abstract * builder in future version. @@ -113,6 +120,7 @@ protected: TestResultCollector *m_result; std::ostream &m_stream; std::string m_encoding; + std::string m_styleSheet; private: /// Prevents the use of the copy constructor. diff --git a/include/cppunit/extensions/RepeatedTest.h b/include/cppunit/extensions/RepeatedTest.h index 067fd20..5db7dc2 100644 --- a/include/cppunit/extensions/RepeatedTest.h +++ b/include/cppunit/extensions/RepeatedTest.h @@ -17,20 +17,22 @@ class TestResult; class CPPUNIT_API RepeatedTest : public TestDecorator { public: - RepeatedTest( Test *test, - int timesRepeat ) : - TestDecorator( test ), - m_timesRepeat(timesRepeat) {} + RepeatedTest( Test *test, + int timesRepeat ) : + TestDecorator( test ), + m_timesRepeat(timesRepeat) + { + } - void run( TestResult *result ); - int countTestCases() const; - std::string toString() const; + void run( TestResult *result ); + + int countTestCases() const; private: - RepeatedTest( const RepeatedTest & ); - void operator=( const RepeatedTest & ); + RepeatedTest( const RepeatedTest & ); + void operator=( const RepeatedTest & ); - const int m_timesRepeat; + const int m_timesRepeat; }; diff --git a/include/cppunit/extensions/TestDecorator.h b/include/cppunit/extensions/TestDecorator.h index c3dc343..9777540 100644 --- a/include/cppunit/extensions/TestDecorator.h +++ b/include/cppunit/extensions/TestDecorator.h @@ -2,7 +2,7 @@ #define CPPUNIT_EXTENSIONS_TESTDECORATOR_H #include <cppunit/Portability.h> -#include <cppunit/Test.h> +#include <cppunit/TestLeaf.h> namespace CppUnit { @@ -17,48 +17,57 @@ class TestResult; * * Does not assume ownership of the test it decorates */ -class CPPUNIT_API TestDecorator : public Test +class CPPUNIT_API TestDecorator : public TestLeaf { public: - TestDecorator (Test *test); - ~TestDecorator (); + TestDecorator( Test *test ); + ~TestDecorator(); - void run (TestResult *result); - int countTestCases () const; - std::string getName () const; - std::string toString () const; + int countTestCases() const; + std::string getName() const; + void run( TestResult *result ); protected: - Test *m_test; + Test *m_test; private: - TestDecorator( const TestDecorator &); - void operator =( const TestDecorator & ); + TestDecorator( const TestDecorator &); + void operator =( const TestDecorator & ); }; -inline TestDecorator::TestDecorator (Test *test) -{ m_test = test; } +inline +TestDecorator::TestDecorator( Test *test ) +{ + m_test = test; +} -inline TestDecorator::~TestDecorator () -{} - - -inline int TestDecorator::countTestCases () const -{ return m_test->countTestCases (); } +inline +TestDecorator::~TestDecorator() +{ +} -inline void TestDecorator::run (TestResult *result) -{ m_test->run (result); } +inline int +TestDecorator::countTestCases() const +{ + return m_test->countTestCases(); +} -inline std::string TestDecorator::toString () const -{ return m_test->toString (); } +inline void +TestDecorator::run( TestResult *result ) +{ + m_test->run(result); +} -inline std::string TestDecorator::getName () const -{ return m_test->getName(); } +inline std::string +TestDecorator::getName() const +{ + return m_test->getName(); +} } // namespace CppUnit diff --git a/include/cppunit/ui/text/TestRunner.h b/include/cppunit/ui/text/TestRunner.h index 6bfa6c9..7b4588f 100644 --- a/include/cppunit/ui/text/TestRunner.h +++ b/include/cppunit/ui/text/TestRunner.h @@ -1,5 +1,5 @@ -#ifndef CPPUNITUI_TEXT_TESTRUNNER_H -#define CPPUNITUI_TEXT_TESTRUNNER_H +#ifndef CPPUNIT_UI_TEXT_TESTRUNNER_H +#define CPPUNIT_UI_TEXT_TESTRUNNER_H #include <cppunit/Portability.h> #include <string> @@ -100,4 +100,4 @@ protected: } // namespace CppUnit -#endif // CPPUNITUI_TEXT_TESTRUNNER_H +#endif // CPPUNIT_UI_TEXT_TESTRUNNER_H |
