~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to lib/cppunit-1.10.0/include/cppunit/TestPath.h

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2006-11-11 10:32:06 UTC
  • Revision ID: james.westby@ubuntu.com-20061111103206-f3p0r9g0vq44rp3r
Tags: upstream-3.0.PRE5
ImportĀ upstreamĀ versionĀ 3.0.PRE5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef CPPUNIT_TESTPATH_H
 
2
#define CPPUNIT_TESTPATH_H
 
3
 
 
4
#include <cppunit/Portability.h>
 
5
 
 
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
 
9
#endif
 
10
 
 
11
#include <cppunit/portability/CppUnitDeque.h>
 
12
 
 
13
CPPUNIT_NS_BEGIN
 
14
 
 
15
 
 
16
class Test;
 
17
 
 
18
#if CPPUNIT_NEED_DLL_DECL
 
19
//  template class CPPUNIT_API std::deque<Test *>;
 
20
#endif
 
21
 
 
22
 
 
23
/*! \brief A List of Test representing a path to access a Test.
 
24
 * \ingroup ExecutingTest
 
25
 *
 
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 ).
 
28
 *
 
29
 * Pointed tests are not owned by the class.
 
30
 *
 
31
 * \see Test::resolvedTestPath()
 
32
 */
 
33
class CPPUNIT_API TestPath
 
34
{
 
35
public:
 
36
  /*! \brief Constructs an invalid path.
 
37
   * 
 
38
   * The path is invalid until a test is added with add().
 
39
   */
 
40
  TestPath();
 
41
 
 
42
  /*! \brief Constructs a valid path.
 
43
   *
 
44
   * \param root Test to add.
 
45
   */
 
46
  TestPath( Test *root );
 
47
 
 
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.
 
54
   */
 
55
  TestPath( const TestPath &otherPath, 
 
56
            int indexFirst, 
 
57
            int count = -1 );
 
58
 
 
59
  /*! \brief Resolves a path from a string returned by toString().
 
60
   *
 
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 
 
65
   * \a searchRoot.
 
66
   *
 
67
   * The resolved path is always valid.
 
68
   *
 
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.
 
72
   * \see toString().
 
73
   */
 
74
  TestPath( Test *searchRoot, 
 
75
            const std::string &pathAsString );
 
76
 
 
77
  /*! \brief Copy constructor.
 
78
   * \param other Object to copy.
 
79
   */
 
80
  TestPath( const TestPath &other );
 
81
 
 
82
  virtual ~TestPath();
 
83
 
 
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.
 
86
   */
 
87
  virtual bool isValid() const;
 
88
 
 
89
  /*! \brief Adds a test to the path.
 
90
   * \param test Pointer on the test to add. Must not be \c NULL.
 
91
   */
 
92
  virtual void add( Test *test );
 
93
 
 
94
  /*! \brief Adds all the tests of the specified path.
 
95
   * \param path Path that contains the test to add.
 
96
   */
 
97
  virtual void add( const TestPath &path );
 
98
 
 
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().
 
103
   */
 
104
  virtual void insert( Test *test, int index );
 
105
 
 
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
 
110
   *            \a path is valid.
 
111
   */
 
112
  virtual void insert( const TestPath &path, int index );
 
113
 
 
114
  /*! \brief Removes all the test from the path.
 
115
   *
 
116
   * The path becomes invalid after this call.
 
117
   */
 
118
  virtual void removeTests();
 
119
 
 
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().
 
123
   */
 
124
  virtual void removeTest( int index );
 
125
 
 
126
  /*! \brief Removes the last test.
 
127
   * \exception std::out_of_range is the path is invalid.
 
128
   * \see isValid().
 
129
   */
 
130
  virtual void up();
 
131
 
 
132
  /*! \brief Returns the number of tests in the path.
 
133
   * \return Number of tests in the path.
 
134
   */
 
135
  virtual int getTestCount() const;
 
136
 
 
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().
 
141
   */
 
142
  virtual Test *getTestAt( int index ) const;
 
143
 
 
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 ).
 
147
   */
 
148
  virtual Test *getChildTest() const;
 
149
 
 
150
  /*! \brief Returns the path as a string.
 
151
   *
 
152
   * For example, if a path is composed of three tests named "All Tests", "Math" and
 
153
   * "Math::testAdd", toString() will return:
 
154
   *
 
155
   * "All Tests/Math/Math::testAdd".
 
156
   * 
 
157
   * \return A string composed of the test names separated with a '/'. It is a relative
 
158
   *         path.
 
159
   */
 
160
  virtual std::string toString() const;
 
161
 
 
162
  /*! \brief Assignment operator.
 
163
   * \param other Object to copy.
 
164
   * \return This object.
 
165
   */
 
166
  TestPath &operator =( const TestPath &other );
 
167
 
 
168
protected:
 
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().
 
172
   */
 
173
  void checkIndexValid( int index ) const;
 
174
 
 
175
  /// A list of test names.
 
176
  typedef CppUnitDeque<std::string> PathTestNames;
 
177
 
 
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 '/').
 
183
   */
 
184
  bool splitPathString( const std::string &pathAsString,
 
185
                        PathTestNames &testNames );
 
186
 
 
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.
 
195
   */
 
196
  Test *findActualRoot( Test *searchRoot,
 
197
                        const std::string &pathAsString,
 
198
                        PathTestNames &testNames );
 
199
 
 
200
protected:
 
201
  typedef CppUnitDeque<Test *> Tests;
 
202
  Tests m_tests;
 
203
 
 
204
};
 
205
 
 
206
 
 
207
CPPUNIT_NS_END
 
208
 
 
209
#endif // CPPUNIT_TESTPATH_H
 
210