TestNamer.h 2.3 KB

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