Blame include/cppunit/TestPath.h

Packit Service e31359
#ifndef CPPUNIT_TESTPATH_H
Packit Service e31359
#define CPPUNIT_TESTPATH_H
Packit Service e31359
Packit Service e31359
#include <cppunit/Portability.h>
Packit Service e31359
Packit Service e31359
#if CPPUNIT_NEED_DLL_DECL
Packit Service e31359
#pragma warning( push )
Packit Service e31359
#pragma warning( disable: 4251 )  // X needs to have dll-interface to be used by clients of class Z
Packit Service e31359
#endif
Packit Service e31359
Packit Service e31359
#include <deque>
Packit Service e31359
#include <string>
Packit Service e31359
Packit Service e31359
CPPUNIT_NS_BEGIN
Packit Service e31359
Packit Service e31359
Packit Service e31359
class Test;
Packit Service e31359
Packit Service e31359
/*! \brief A List of Test representing a path to access a Test.
Packit Service e31359
 * \ingroup ExecutingTest
Packit Service e31359
 *
Packit Service e31359
 * The path can be converted to a string and resolved from a string with toString()
Packit Service e31359
 * and TestPath( Test *root, const std::string &pathAsString ).
Packit Service e31359
 *
Packit Service e31359
 * Pointed tests are not owned by the class.
Packit Service e31359
 *
Packit Service e31359
 * \see Test::resolvedTestPath()
Packit Service e31359
 */
Packit Service e31359
class CPPUNIT_API TestPath
Packit Service e31359
{
Packit Service e31359
public:
Packit Service e31359
  /*! \brief Constructs an invalid path.
Packit Service e31359
   * 
Packit Service e31359
   * The path is invalid until a test is added with add().
Packit Service e31359
   */
Packit Service e31359
  TestPath();
Packit Service e31359
Packit Service e31359
  /*! \brief Constructs a valid path.
Packit Service e31359
   *
Packit Service e31359
   * \param root Test to add.
Packit Service e31359
   */
Packit Service e31359
  TestPath( Test *root );
Packit Service e31359
Packit Service e31359
  /*! \brief Constructs a path using a slice of another path.
Packit Service e31359
   * \param otherPath Path the test are copied from.
Packit Service e31359
   * \param indexFirst Zero based index of the first test to copy. Adjusted to be in valid
Packit Service e31359
   *                   range. \a count is adjusted with \a indexFirst.
Packit Service e31359
   * \param count Number of tests to copy. If < 0 then all test starting from index
Packit Service e31359
   *              \a indexFirst are copied.
Packit Service e31359
   */
Packit Service e31359
  TestPath( const TestPath &otherPath, 
Packit Service e31359
            int indexFirst, 
Packit Service e31359
            int count = -1 );
Packit Service e31359
Packit Service e31359
  /*! \brief Resolves a path from a string returned by toString().
Packit Service e31359
   *
Packit Service e31359
   * If \a pathAsString is an absolute path (begins with '/'), then the first test name
Packit Service e31359
   * of the path must be the name of \a searchRoot. Otherwise, \a pathAsString is a 
Packit Service e31359
   * relative path, and the first test found using Test::findTest() matching the first
Packit Service e31359
   * test name is used as root. An empty string resolve to a path containing 
Packit Service e31359
   * \a searchRoot.
Packit Service e31359
   *
Packit Service e31359
   * The resolved path is always valid.
Packit Service e31359
   *
Packit Service e31359
   * \param searchRoot Test used to resolve the path.
Packit Service e31359
   * \param pathAsString String that contains the path as a string created by toString().
Packit Service e31359
   * \exception std::invalid_argument if one of the test names can not be resolved.
Packit Service e31359
   * \see toString().
Packit Service e31359
   */
Packit Service e31359
  TestPath( Test *searchRoot, 
Packit Service e31359
            const std::string &pathAsString );
Packit Service e31359
Packit Service e31359
  /*! \brief Copy constructor.
Packit Service e31359
   * \param other Object to copy.
Packit Service e31359
   */
Packit Service e31359
  TestPath( const TestPath &other );
Packit Service e31359
Packit Service e31359
  virtual ~TestPath();
Packit Service e31359
Packit Service e31359
  /*! \brief Tests if the path contains at least one test.
Packit Service e31359
   * \return \c true if the path contains at least one test, otherwise returns \c false.
Packit Service e31359
   */
Packit Service e31359
  virtual bool isValid() const;
Packit Service e31359
Packit Service e31359
  /*! \brief Adds a test to the path.
Packit Service e31359
   * \param test Pointer on the test to add. Must not be \c NULL.
Packit Service e31359
   */
Packit Service e31359
  virtual void add( Test *test );
Packit Service e31359
Packit Service e31359
  /*! \brief Adds all the tests of the specified path.
Packit Service e31359
   * \param path Path that contains the test to add.
Packit Service e31359
   */
Packit Service e31359
  virtual void add( const TestPath &path );
Packit Service e31359
Packit Service e31359
  /*! \brief Inserts a test at the specified index.
Packit Service e31359
   * \param test Pointer on the test to insert. Must not be \c NULL.
Packit Service e31359
   * \param index Zero based index indicating where the test is inserted.
Packit Service e31359
   * \exception std::out_of_range is \a index < 0 or \a index > getTestCount().
Packit Service e31359
   */
Packit Service e31359
  virtual void insert( Test *test, int index );
Packit Service e31359
Packit Service e31359
  /*! \brief Inserts all the tests at the specified path at a given index.
Packit Service e31359
   * \param path Path that contains the test to insert.
Packit Service e31359
   * \param index Zero based index indicating where the tests are inserted.
Packit Service e31359
   * \exception std::out_of_range is \a index < 0 or \a index > getTestCount(), and
Packit Service e31359
   *            \a path is valid.
Packit Service e31359
   */
Packit Service e31359
  virtual void insert( const TestPath &path, int index );
Packit Service e31359
Packit Service e31359
  /*! \brief Removes all the test from the path.
Packit Service e31359
   *
Packit Service e31359
   * The path becomes invalid after this call.
Packit Service e31359
   */
Packit Service e31359
  virtual void removeTests();
Packit Service e31359
Packit Service e31359
  /*! \brief Removes the test at the specified index of the path.
Packit Service e31359
   * \param index Zero based index of the test to remove.
Packit Service e31359
   * \exception std::out_of_range is \a index < 0 or \a index >= getTestCount().
Packit Service e31359
   */
Packit Service e31359
  virtual void removeTest( int index );
Packit Service e31359
Packit Service e31359
  /*! \brief Removes the last test.
Packit Service e31359
   * \exception std::out_of_range is the path is invalid.
Packit Service e31359
   * \see isValid().
Packit Service e31359
   */
Packit Service e31359
  virtual void up();
Packit Service e31359
Packit Service e31359
  /*! \brief Returns the number of tests in the path.
Packit Service e31359
   * \return Number of tests in the path.
Packit Service e31359
   */
Packit Service e31359
  virtual int getTestCount() const;
Packit Service e31359
Packit Service e31359
  /*! \brief Returns the test of the specified index.
Packit Service e31359
   * \param index Zero based index of the test to return.
Packit Service e31359
   * \return Pointer on the test at index \a index. Never \c NULL.
Packit Service e31359
   * \exception std::out_of_range is \a index < 0 or \a index >= getTestCount().
Packit Service e31359
   */
Packit Service e31359
  virtual Test *getTestAt( int index ) const;
Packit Service e31359
Packit Service e31359
  /*! \brief Get the last test of the path.
Packit Service e31359
   * \return Pointer on the last test (test at the bottom of the hierarchy). Never \c NULL.
Packit Service e31359
   * \exception std::out_of_range if the path is not valid ( isValid() returns \c false ).
Packit Service e31359
   */
Packit Service e31359
  virtual Test *getChildTest() const;
Packit Service e31359
Packit Service e31359
  /*! \brief Returns the path as a string.
Packit Service e31359
   *
Packit Service e31359
   * For example, if a path is composed of three tests named "All Tests", "Math" and
Packit Service e31359
   * "Math::testAdd", toString() will return:
Packit Service e31359
   *
Packit Service e31359
   * "All Tests/Math/Math::testAdd".
Packit Service e31359
   * 
Packit Service e31359
   * \return A string composed of the test names separated with a '/'. It is a relative
Packit Service e31359
   *         path.
Packit Service e31359
   */
Packit Service e31359
  virtual std::string toString() const;
Packit Service e31359
Packit Service e31359
  /*! \brief Assignment operator.
Packit Service e31359
   * \param other Object to copy.
Packit Service e31359
   * \return This object.
Packit Service e31359
   */
Packit Service e31359
  TestPath &operator =( const TestPath &other );
Packit Service e31359
Packit Service e31359
protected:
Packit Service e31359
  /*! \brief Checks that the specified test index is within valid range.
Packit Service e31359
   * \param index Zero based index to check.
Packit Service e31359
   * \exception std::out_of_range is \a index < 0 or \a index >= getTestCount().
Packit Service e31359
   */
Packit Service e31359
  void checkIndexValid( int index ) const;
Packit Service e31359
Packit Service e31359
  /// A list of test names.
Packit Service e31359
  typedef std::deque<std::string> PathTestNames;
Packit Service e31359
Packit Service e31359
  /*! \brief Splits a path string into its test name components.
Packit Service e31359
   * \param pathAsString Path string created with toString().
Packit Service e31359
   * \param testNames Test name components are added to that container.
Packit Service e31359
   * \return \c true if the path is relative (does not begin with '/'), \c false
Packit Service e31359
   *         if it is absolute (begin with '/').
Packit Service e31359
   */
Packit Service e31359
  bool splitPathString( const std::string &pathAsString,
Packit Service e31359
                        PathTestNames &testNames );
Packit Service e31359
Packit Service e31359
  /*! \brief Finds the actual root of a path string and get the path string name components.
Packit Service e31359
   * \param searchRoot Test used as root if the path string is absolute, or to search
Packit Service e31359
   *                   the root test if the path string is relative.
Packit Service e31359
   * \param pathAsString Path string. May be absolute or relative.
Packit Service e31359
   * \param testNames Test name components are added to that container.
Packit Service e31359
   * \return Pointer on the resolved root test. Never \c NULL.
Packit Service e31359
   * \exception std::invalid_argument if either the root name can not be resolved or if
Packit Service e31359
   *            pathAsString contains no name components.
Packit Service e31359
   */
Packit Service e31359
  Test *findActualRoot( Test *searchRoot,
Packit Service e31359
                        const std::string &pathAsString,
Packit Service e31359
                        PathTestNames &testNames );
Packit Service e31359
Packit Service e31359
protected:
Packit Service e31359
  typedef std::deque<Test *> Tests;
Packit Service e31359
  Tests m_tests;
Packit Service e31359
Packit Service e31359
};
Packit Service e31359
Packit Service e31359
Packit Service e31359
CPPUNIT_NS_END
Packit Service e31359
Packit Service e31359
#endif // CPPUNIT_TESTPATH_H
Packit Service e31359