CppUnit project page FAQ

Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
TestPath Class Reference

A List of Test representing a path to access a Test. More...

#include <TestPath.h>

Public Member Functions

 TestPath ()
 Constructs an invalid path. More...
 
 TestPath (Test *root)
 Constructs a valid path. More...
 
 TestPath (const TestPath &otherPath, int indexFirst, int count=-1)
 Constructs a path using a slice of another path. More...
 
 TestPath (Test *searchRoot, const std::string &pathAsString)
 Resolves a path from a string returned by toString(). More...
 
 TestPath (const TestPath &other)
 Copy constructor. More...
 
virtual ~TestPath ()
 
virtual bool isValid () const
 Tests if the path contains at least one test. More...
 
virtual void add (Test *test)
 Adds a test to the path. More...
 
virtual void add (const TestPath &path)
 Adds all the tests of the specified path. More...
 
virtual void insert (Test *test, int index)
 Inserts a test at the specified index. More...
 
virtual void insert (const TestPath &path, int index)
 Inserts all the tests at the specified path at a given index. More...
 
virtual void removeTests ()
 Removes all the test from the path. More...
 
virtual void removeTest (int index)
 Removes the test at the specified index of the path. More...
 
virtual void up ()
 Removes the last test. More...
 
virtual int getTestCount () const
 Returns the number of tests in the path. More...
 
virtual TestgetTestAt (int index) const
 Returns the test of the specified index. More...
 
virtual TestgetChildTest () const
 Get the last test of the path. More...
 
virtual std::string toString () const
 Returns the path as a string. More...
 
TestPathoperator= (const TestPath &other)
 Assignment operator. More...
 

Protected Types

typedef std::deque< std::string > PathTestNames
 A list of test names. More...
 
typedef std::deque< Test * > Tests
 

Protected Member Functions

void checkIndexValid (int index) const
 Checks that the specified test index is within valid range. More...
 
bool splitPathString (const std::string &pathAsString, PathTestNames &testNames)
 Splits a path string into its test name components. More...
 
TestfindActualRoot (Test *searchRoot, const std::string &pathAsString, PathTestNames &testNames)
 Finds the actual root of a path string and get the path string name components. More...
 

Protected Attributes

Tests m_tests
 

Detailed Description

A List of Test representing a path to access a Test.

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 also
Test::resolvedTestPath()

Member Typedef Documentation

◆ PathTestNames

typedef std::deque<std::string> TestPath::PathTestNames
protected

A list of test names.

◆ Tests

typedef std::deque<Test *> TestPath::Tests
protected

Constructor & Destructor Documentation

◆ TestPath() [1/5]

CPPUNIT_NS_BEGIN TestPath::TestPath ( )

Constructs an invalid path.

The path is invalid until a test is added with add().

◆ TestPath() [2/5]

TestPath::TestPath ( Test root)

Constructs a valid path.

Parameters
rootTest to add.

◆ TestPath() [3/5]

TestPath::TestPath ( const TestPath otherPath,
int  indexFirst,
int  count = -1 
)

Constructs a path using a slice of another path.

Parameters
otherPathPath the test are copied from.
indexFirstZero based index of the first test to copy. Adjusted to be in valid range. count is adjusted with indexFirst.
countNumber of tests to copy. If < 0 then all test starting from index indexFirst are copied.

◆ TestPath() [4/5]

TestPath::TestPath ( Test searchRoot,
const std::string &  pathAsString 
)

Resolves a path from a string returned by toString().

If pathAsString is an absolute path (begins with '/'), then the first test name of the path must be the name of searchRoot. Otherwise, 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 searchRoot.

The resolved path is always valid.

Parameters
searchRootTest used to resolve the path.
pathAsStringString that contains the path as a string created by toString().
Exceptions
std::invalid_argumentif one of the test names can not be resolved.
See also
toString().

◆ TestPath() [5/5]

TestPath::TestPath ( const TestPath other)

Copy constructor.

Parameters
otherObject to copy.

◆ ~TestPath()

TestPath::~TestPath ( )
virtual

Member Function Documentation

◆ add() [1/2]

void TestPath::add ( const TestPath path)
virtual

Adds all the tests of the specified path.

Parameters
pathPath that contains the test to add.

◆ add() [2/2]

void TestPath::add ( Test test)
virtual

Adds a test to the path.

Parameters
testPointer on the test to add. Must not be NULL.

◆ checkIndexValid()

void TestPath::checkIndexValid ( int  index) const
protected

Checks that the specified test index is within valid range.

Parameters
indexZero based index to check.
Exceptions
std::out_of_rangeis index < 0 or index >= getTestCount().

◆ findActualRoot()

Test * TestPath::findActualRoot ( Test searchRoot,
const std::string &  pathAsString,
PathTestNames testNames 
)
protected

Finds the actual root of a path string and get the path string name components.

Parameters
searchRootTest used as root if the path string is absolute, or to search the root test if the path string is relative.
pathAsStringPath string. May be absolute or relative.
testNamesTest name components are added to that container.
Returns
Pointer on the resolved root test. Never NULL.
Exceptions
std::invalid_argumentif either the root name can not be resolved or if pathAsString contains no name components.

◆ getChildTest()

Test * TestPath::getChildTest ( ) const
virtual

Get the last test of the path.

Returns
Pointer on the last test (test at the bottom of the hierarchy). Never NULL.
Exceptions
std::out_of_rangeif the path is not valid ( isValid() returns false ).

◆ getTestAt()

Test * TestPath::getTestAt ( int  index) const
virtual

Returns the test of the specified index.

Parameters
indexZero based index of the test to return.
Returns
Pointer on the test at index index. Never NULL.
Exceptions
std::out_of_rangeis index < 0 or index >= getTestCount().

◆ getTestCount()

int TestPath::getTestCount ( ) const
virtual

Returns the number of tests in the path.

Returns
Number of tests in the path.

◆ insert() [1/2]

void TestPath::insert ( const TestPath path,
int  index 
)
virtual

Inserts all the tests at the specified path at a given index.

Parameters
pathPath that contains the test to insert.
indexZero based index indicating where the tests are inserted.
Exceptions
std::out_of_rangeis index < 0 or index > getTestCount(), and path is valid.

◆ insert() [2/2]

void TestPath::insert ( Test test,
int  index 
)
virtual

Inserts a test at the specified index.

Parameters
testPointer on the test to insert. Must not be NULL.
indexZero based index indicating where the test is inserted.
Exceptions
std::out_of_rangeis index < 0 or index > getTestCount().

◆ isValid()

bool TestPath::isValid ( ) const
virtual

Tests if the path contains at least one test.

Returns
true if the path contains at least one test, otherwise returns false.

◆ operator=()

TestPath & TestPath::operator= ( const TestPath other)

Assignment operator.

Parameters
otherObject to copy.
Returns
This object.

◆ removeTest()

void TestPath::removeTest ( int  index)
virtual

Removes the test at the specified index of the path.

Parameters
indexZero based index of the test to remove.
Exceptions
std::out_of_rangeis index < 0 or index >= getTestCount().

◆ removeTests()

void TestPath::removeTests ( )
virtual

Removes all the test from the path.

The path becomes invalid after this call.

◆ splitPathString()

bool TestPath::splitPathString ( const std::string &  pathAsString,
PathTestNames testNames 
)
protected

Splits a path string into its test name components.

Parameters
pathAsStringPath string created with toString().
testNamesTest name components are added to that container.
Returns
true if the path is relative (does not begin with '/'), false if it is absolute (begin with '/').

◆ toString()

std::string TestPath::toString ( ) const
virtual

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".

Returns
A string composed of the test names separated with a '/'. It is a relative path.

◆ up()

void TestPath::up ( )
virtual

Removes the last test.

Exceptions
std::out_of_rangeis the path is invalid.
See also
isValid().

Member Data Documentation

◆ m_tests

Tests TestPath::m_tests
protected

The documentation for this class was generated from the following files:

Send comments to:
CppUnit Developers