summaryrefslogtreecommitdiff
path: root/include/cppunit/TestPath.h
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-04-12 18:28:48 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-04-12 18:28:48 +0000
commited406a2966e62072fa6afaca8abc578db7c0c9fb (patch)
treeab8d2ffb462c3c955b2e339e8cc19f1a6be8bd0f /include/cppunit/TestPath.h
parentfc9c76622b19adfcdebce682d9d49db8fb9336ef (diff)
downloadcppunit-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/TestPath.h')
-rw-r--r--include/cppunit/TestPath.h198
1 files changed, 198 insertions, 0 deletions
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
+