source: trunk/contrib/cppunit-1.12.2/include/cppunit/extensions/TestNamer.h @ 876

Last change on this file since 876 was 876, checked in by sam, 9 years ago

contrib: add a precompiled Win32 version of CppUnit and update build system
accordingly.

File size: 2.3 KB
Line 
1#ifndef CPPUNIT_EXTENSIONS_TESTNAMER_H
2#define CPPUNIT_EXTENSIONS_TESTNAMER_H
3
4#include <cppunit/Portability.h>
5#include <string>
6
7#if CPPUNIT_HAVE_RTTI
8#  include <typeinfo>
9#endif
10
11
12
13/*! \def CPPUNIT_TESTNAMER_DECL( variableName, FixtureType )
14 * \brief Declares a TestNamer.
15 *
16 * Declares a TestNamer for the specified type, using RTTI if enabled, otherwise
17 * using macro string expansion.
18 *
19 * RTTI is used if CPPUNIT_USE_TYPEINFO_NAME is defined and not null.
20 *
21 * \code
22 * void someMethod()
23 * {
24 *   CPPUNIT_TESTNAMER_DECL( namer, AFixtureType );
25 *   std::string fixtureName = namer.getFixtureName();
26 *   ...
27 * \endcode
28 *
29 * \relates TestNamer
30 * \see TestNamer
31 */
32#if CPPUNIT_USE_TYPEINFO_NAME
33#  define CPPUNIT_TESTNAMER_DECL( variableName, FixtureType )       \
34              CPPUNIT_NS::TestNamer variableName( typeid(FixtureType) )
35#else
36#  define CPPUNIT_TESTNAMER_DECL( variableName, FixtureType )       \
37              CPPUNIT_NS::TestNamer variableName( std::string(#FixtureType) )
38#endif
39
40
41
42CPPUNIT_NS_BEGIN
43
44
45/*! \brief Names a test or a fixture suite.
46 *
47 * TestNamer is usually instantiated using CPPUNIT_TESTNAMER_DECL.
48 *
49 */
50class CPPUNIT_API TestNamer
51{
52public:
53#if CPPUNIT_HAVE_RTTI
54  /*! \brief Constructs a namer using the fixture's type-info.
55   * \param typeInfo Type-info of the fixture type. Use to name the fixture suite.
56   */
57  TestNamer( const std::type_info &typeInfo );
58#endif
59
60  /*! \brief Constructs a namer using the specified fixture name.
61   * \param fixtureName Name of the fixture suite. Usually extracted using a macro.
62   */
63  TestNamer( const std::string &fixtureName );
64
65  virtual ~TestNamer();
66
67  /*! \brief Returns the name of the fixture.
68   * \return Name of the fixture.
69   */
70  virtual std::string getFixtureName() const;
71
72  /*! \brief Returns the name of the test for the specified method.
73   * \param testMethodName Name of the method that implements a test.
74   * \return A string that is the concatenation of the test fixture name
75   *         (returned by getFixtureName()) and\a testMethodName,
76   *         separated using '::'. This provides a fairly unique name for a given
77   *         test.
78   */
79  virtual std::string getTestNameFor( const std::string &testMethodName ) const;
80
81protected:
82  std::string m_fixtureName;
83};
84
85
86CPPUNIT_NS_END
87
88#endif // CPPUNIT_EXTENSIONS_TESTNAMER_H
89
Note: See TracBrowser for help on using the repository browser.