1
#ifndef CPPUNIT_TESTPATH_H
2
#define CPPUNIT_TESTPATH_H
4
#include <cppunit/Portability.h>
6
#if CPPUNIT_NEED_DLL_DECL
7
#pragma warning( push )
8
#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
11
#include <cppunit/portability/CppUnitDeque.h>
18
#if CPPUNIT_NEED_DLL_DECL
19
// template class CPPUNIT_API std::deque<Test *>;
23
/*! \brief A List of Test representing a path to access a Test.
24
* \ingroup ExecutingTest
26
* The path can be converted to a string and resolved from a string with toString()
27
* and TestPath( Test *root, const std::string &pathAsString ).
29
* Pointed tests are not owned by the class.
31
* \see Test::resolvedTestPath()
33
class CPPUNIT_API TestPath
36
/*! \brief Constructs an invalid path.
38
* The path is invalid until a test is added with add().
42
/*! \brief Constructs a valid path.
44
* \param root Test to add.
46
TestPath( Test *root );
48
/*! \brief Constructs a path using a slice of another path.
49
* \param otherPath Path the test are copied from.
50
* \param indexFirst Zero based index of the first test to copy. Adjusted to be in valid
51
* range. \a count is adjusted with \a indexFirst.
52
* \param count Number of tests to copy. If < 0 then all test starting from index
53
* \a indexFirst are copied.
55
TestPath( const TestPath &otherPath,
59
/*! \brief Resolves a path from a string returned by toString().
61
* If \a pathAsString is an absolute path (begins with '/'), then the first test name
62
* of the path must be the name of \a searchRoot. Otherwise, \a pathAsString is a
63
* relative path, and the first test found using Test::findTest() matching the first
64
* test name is used as root. An empty string resolve to a path containing
67
* The resolved path is always valid.
69
* \param searchRoot Test used to resolve the path.
70
* \param pathAsString String that contains the path as a string created by toString().
71
* \exception std::invalid_argument if one of the test names can not be resolved.
74
TestPath( Test *searchRoot,
75
const std::string &pathAsString );
77
/*! \brief Copy constructor.
78
* \param other Object to copy.
80
TestPath( const TestPath &other );
84
/*! \brief Tests if the path contains at least one test.
85
* \return \c true if the path contains at least one test, otherwise returns \c false.
87
virtual bool isValid() const;
89
/*! \brief Adds a test to the path.
90
* \param test Pointer on the test to add. Must not be \c NULL.
92
virtual void add( Test *test );
94
/*! \brief Adds all the tests of the specified path.
95
* \param path Path that contains the test to add.
97
virtual void add( const TestPath &path );
99
/*! \brief Inserts a test at the specified index.
100
* \param test Pointer on the test to insert. Must not be \c NULL.
101
* \param index Zero based index indicating where the test is inserted.
102
* \exception std::out_of_range is \a index < 0 or \a index > getTestCount().
104
virtual void insert( Test *test, int index );
106
/*! \brief Inserts all the tests at the specified path at a given index.
107
* \param path Path that contains the test to insert.
108
* \param index Zero based index indicating where the tests are inserted.
109
* \exception std::out_of_range is \a index < 0 or \a index > getTestCount(), and
112
virtual void insert( const TestPath &path, int index );
114
/*! \brief Removes all the test from the path.
116
* The path becomes invalid after this call.
118
virtual void removeTests();
120
/*! \brief Removes the test at the specified index of the path.
121
* \param index Zero based index of the test to remove.
122
* \exception std::out_of_range is \a index < 0 or \a index >= getTestCount().
124
virtual void removeTest( int index );
126
/*! \brief Removes the last test.
127
* \exception std::out_of_range is the path is invalid.
132
/*! \brief Returns the number of tests in the path.
133
* \return Number of tests in the path.
135
virtual int getTestCount() const;
137
/*! \brief Returns the test of the specified index.
138
* \param index Zero based index of the test to return.
139
* \return Pointer on the test at index \a index. Never \c NULL.
140
* \exception std::out_of_range is \a index < 0 or \a index >= getTestCount().
142
virtual Test *getTestAt( int index ) const;
144
/*! \brief Get the last test of the path.
145
* \return Pointer on the last test (test at the bottom of the hierarchy). Never \c NULL.
146
* \exception std::out_of_range if the path is not valid ( isValid() returns \c false ).
148
virtual Test *getChildTest() const;
150
/*! \brief Returns the path as a string.
152
* For example, if a path is composed of three tests named "All Tests", "Math" and
153
* "Math::testAdd", toString() will return:
155
* "All Tests/Math/Math::testAdd".
157
* \return A string composed of the test names separated with a '/'. It is a relative
160
virtual std::string toString() const;
162
/*! \brief Assignment operator.
163
* \param other Object to copy.
164
* \return This object.
166
TestPath &operator =( const TestPath &other );
169
/*! \brief Checks that the specified test index is within valid range.
170
* \param index Zero based index to check.
171
* \exception std::out_of_range is \a index < 0 or \a index >= getTestCount().
173
void checkIndexValid( int index ) const;
175
/// A list of test names.
176
typedef CppUnitDeque<std::string> PathTestNames;
178
/*! \brief Splits a path string into its test name components.
179
* \param pathAsString Path string created with toString().
180
* \param testNames Test name components are added to that container.
181
* \return \c true if the path is relative (does not begin with '/'), \c false
182
* if it is absolute (begin with '/').
184
bool splitPathString( const std::string &pathAsString,
185
PathTestNames &testNames );
187
/*! \brief Finds the actual root of a path string and get the path string name components.
188
* \param searchRoot Test used as root if the path string is absolute, or to search
189
* the root test if the path string is relative.
190
* \param pathAsString Path string. May be absolute or relative.
191
* \param testNames Test name components are added to that container.
192
* \return Pointer on the resolved root test. Never \c NULL.
193
* \exception std::invalid_argument if either the root name can not be resolved or if
194
* pathAsString contains no name components.
196
Test *findActualRoot( Test *searchRoot,
197
const std::string &pathAsString,
198
PathTestNames &testNames );
201
typedef CppUnitDeque<Test *> Tests;
209
#endif // CPPUNIT_TESTPATH_H