Blame include/cppunit/extensions/TestNamer.h

Packit 8c9aa0
#ifndef CPPUNIT_EXTENSIONS_TESTNAMER_H
Packit 8c9aa0
#define CPPUNIT_EXTENSIONS_TESTNAMER_H
Packit 8c9aa0
Packit 8c9aa0
#include <cppunit/Portability.h>
Packit 8c9aa0
#include <string>
Packit 8c9aa0
#include <cppunit/tools/StringHelper.h>
Packit 8c9aa0
Packit 8c9aa0
#include <typeinfo>
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
/*! \def CPPUNIT_TESTNAMER_DECL( variableName, FixtureType )
Packit 8c9aa0
 * \brief Declares a TestNamer.
Packit 8c9aa0
 *
Packit 8c9aa0
 * Declares a TestNamer for the specified type
Packit 8c9aa0
 *
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * void someMethod() 
Packit 8c9aa0
 * {
Packit 8c9aa0
 *   CPPUNIT_TESTNAMER_DECL( namer, AFixtureType );
Packit 8c9aa0
 *   std::string fixtureName = namer.getFixtureName();
Packit 8c9aa0
 *   ...
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 *
Packit 8c9aa0
 * \relates TestNamer
Packit 8c9aa0
 * \see TestNamer
Packit 8c9aa0
 */
Packit 8c9aa0
#  define CPPUNIT_TESTNAMER_DECL( variableName, FixtureType )       \
Packit 8c9aa0
              CPPUNIT_NS::TestNamer variableName( typeid(FixtureType) )
Packit 8c9aa0
Packit 8c9aa0
CPPUNIT_NS_BEGIN
Packit 8c9aa0
Packit 8c9aa0
/*! \brief Names a test or a fixture suite.
Packit 8c9aa0
 *
Packit 8c9aa0
 * TestNamer is usually instantiated using CPPUNIT_TESTNAMER_DECL.
Packit 8c9aa0
 *
Packit 8c9aa0
 */
Packit 8c9aa0
class CPPUNIT_API TestNamer
Packit 8c9aa0
{
Packit 8c9aa0
public:
Packit 8c9aa0
  /*! \brief Constructs a namer using the fixture's type-info.
Packit 8c9aa0
   * \param typeInfo Type-info of the fixture type. Use to name the fixture suite.
Packit 8c9aa0
   */
Packit 8c9aa0
  TestNamer( const std::type_info &typeInfo );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Constructs a namer using the specified fixture name.
Packit 8c9aa0
   * \param fixtureName Name of the fixture suite. Usually extracted using a macro.
Packit 8c9aa0
   */
Packit 8c9aa0
  TestNamer( const std::string &fixtureName );
Packit 8c9aa0
Packit 8c9aa0
  virtual ~TestNamer();
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Returns the name of the fixture.
Packit 8c9aa0
   * \return Name of the fixture.
Packit 8c9aa0
   */
Packit 8c9aa0
  virtual std::string getFixtureName() const;
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Returns the name of the test for the specified method.
Packit 8c9aa0
   * \param testMethodName Name of the method that implements a test.
Packit 8c9aa0
   * \return A string that is the concatenation of the test fixture name 
Packit 8c9aa0
   *         (returned by getFixtureName()) and\a testMethodName, 
Packit 8c9aa0
   *         separated using '::'. This provides a fairly unique name for a given
Packit 8c9aa0
   *         test.
Packit 8c9aa0
   */
Packit 8c9aa0
  virtual std::string getTestNameFor( const std::string &testMethodName ) const;
Packit 8c9aa0
Packit 8c9aa0
  template<typename E>
Packit 8c9aa0
  std::string getTestNameFor( const std::string& testMethodName, const E& val) const
Packit 8c9aa0
  {
Packit 8c9aa0
      return getTestNameFor(testMethodName) + " with parameter: " + CPPUNIT_NS::StringHelper::toString(val);
Packit 8c9aa0
  }
Packit 8c9aa0
Packit 8c9aa0
protected:
Packit 8c9aa0
  std::string m_fixtureName;
Packit 8c9aa0
};
Packit 8c9aa0
Packit 8c9aa0
CPPUNIT_NS_END
Packit 8c9aa0
Packit 8c9aa0
#endif // CPPUNIT_EXTENSIONS_TESTNAMER_H
Packit 8c9aa0