Blame include/cppunit/extensions/HelperMacros.h

Packit 8c9aa0
// //////////////////////////////////////////////////////////////////////////
Packit 8c9aa0
// Header file HelperMacros.h
Packit 8c9aa0
// (c)Copyright 2000, Baptiste Lepilleur.
Packit 8c9aa0
// Created: 2001/04/15
Packit 8c9aa0
// //////////////////////////////////////////////////////////////////////////
Packit 8c9aa0
#ifndef CPPUNIT_EXTENSIONS_HELPERMACROS_H
Packit 8c9aa0
#define CPPUNIT_EXTENSIONS_HELPERMACROS_H
Packit 8c9aa0
Packit 8c9aa0
#include <cppunit/TestCaller.h>
Packit 8c9aa0
#include <cppunit/TestSuite.h>
Packit 8c9aa0
#include <cppunit/extensions/AutoRegisterSuite.h>
Packit 8c9aa0
#include <cppunit/extensions/ExceptionTestCaseDecorator.h>
Packit 8c9aa0
#include <cppunit/extensions/TestFixtureFactory.h>
Packit 8c9aa0
#include <cppunit/extensions/TestNamer.h>
Packit 8c9aa0
#include <cppunit/extensions/TestSuiteBuilderContext.h>
Packit 8c9aa0
#include <memory>
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
/*! \addtogroup WritingTestFixture Writing test fixture
Packit 8c9aa0
 */
Packit 8c9aa0
/** @{
Packit 8c9aa0
 */
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
/** \file
Packit 8c9aa0
 * Macros intended to ease the definition of test suites.
Packit 8c9aa0
 *
Packit 8c9aa0
 * The macros
Packit 8c9aa0
 * CPPUNIT_TEST_SUITE(), CPPUNIT_TEST(), and CPPUNIT_TEST_SUITE_END()
Packit 8c9aa0
 * are designed to facilitate easy creation of a test suite.
Packit 8c9aa0
 * For example,
Packit 8c9aa0
 *
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * #include <cppunit/extensions/HelperMacros.h>
Packit 8c9aa0
 * class MyTest : public CppUnit::TestFixture {
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE( MyTest );
Packit 8c9aa0
 *   CPPUNIT_TEST( testEquality );
Packit 8c9aa0
 *   CPPUNIT_TEST( testSetName );
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE_END();
Packit 8c9aa0
 * public:
Packit 8c9aa0
 *   void testEquality();
Packit 8c9aa0
 *   void testSetName();
Packit 8c9aa0
 * };
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 * 
Packit 8c9aa0
 * The effect of these macros is to define two methods in the
Packit 8c9aa0
 * class MyTest.  The first method is an auxiliary function
Packit 8c9aa0
 * named registerTests that you will not need to call directly.
Packit 8c9aa0
 * The second function
Packit 8c9aa0
 * \code static CppUnit::TestSuite *suite()\endcode
Packit 8c9aa0
 * returns a pointer to the suite of tests defined by the CPPUNIT_TEST()
Packit 8c9aa0
 * macros.  
Packit 8c9aa0
 *
Packit 8c9aa0
 * Rather than invoking suite() directly,
Packit 8c9aa0
 * the macro CPPUNIT_TEST_SUITE_REGISTRATION() is
Packit 8c9aa0
 * used to create a static variable that automatically
Packit 8c9aa0
 * registers its test suite in a global registry.
Packit 8c9aa0
 * The registry yields a Test instance containing all the
Packit 8c9aa0
 * registered suites.
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * CPPUNIT_TEST_SUITE_REGISTRATION( MyTest );
Packit 8c9aa0
 * CppUnit::Test* tp =
Packit 8c9aa0
 *   CppUnit::TestFactoryRegistry::getRegistry().makeTest();
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 * 
Packit 8c9aa0
 * The test suite macros can even be used with templated test classes.
Packit 8c9aa0
 * For example:
Packit 8c9aa0
 *
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * template<typename CharType>
Packit 8c9aa0
 * class StringTest : public CppUnit::TestFixture {
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE( StringTest );
Packit 8c9aa0
 *   CPPUNIT_TEST( testAppend );
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE_END();
Packit 8c9aa0
 * public:  
Packit 8c9aa0
 *   ...
Packit 8c9aa0
 * };
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 *
Packit 8c9aa0
 * You need to add in an implementation file:
Packit 8c9aa0
 *
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<char> );
Packit 8c9aa0
 * CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<wchar_t> );
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 */
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
/*! \brief Begin test suite
Packit 8c9aa0
 *
Packit 8c9aa0
 * This macro starts the declaration of a new test suite.
Packit 8c9aa0
 * Use CPPUNIT_TEST_SUB_SUITE() instead, if you wish to include the
Packit 8c9aa0
 * test suite of the parent class.
Packit 8c9aa0
 *
Packit 8c9aa0
 * \param ATestFixtureType Type of the test case class. This type \b MUST
Packit 8c9aa0
 *                         be derived from TestFixture.
Packit 8c9aa0
 * \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END, 
Packit 8c9aa0
 * \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_EXCEPTION, CPPUNIT_TEST_FAIL.
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST_SUITE( ATestFixtureType )                              \
Packit 8c9aa0
  public:                                                                   \
Packit 8c9aa0
    typedef ATestFixtureType TestFixtureType;                               \
Packit 8c9aa0
                                                                            \
Packit 8c9aa0
  private:                                                                  \
Packit 8c9aa0
    static const CPPUNIT_NS::TestNamer &getTestNamer__()                    \
Packit 8c9aa0
    {                                                                       \
Packit 8c9aa0
      static CPPUNIT_TESTNAMER_DECL( testNamer, ATestFixtureType );         \
Packit 8c9aa0
      return testNamer;                                                     \
Packit 8c9aa0
    }                                                                       \
Packit 8c9aa0
                                                                            \
Packit 8c9aa0
  public:                                                                   \
Packit 8c9aa0
    typedef CPPUNIT_NS::TestSuiteBuilderContext<TestFixtureType>            \
Packit 8c9aa0
                TestSuiteBuilderContextType;                                \
Packit 8c9aa0
                                                                            \
Packit 8c9aa0
    static void                                                             \
Packit 8c9aa0
    addTestsToSuite( CPPUNIT_NS::TestSuiteBuilderContextBase &baseContext ) \
Packit 8c9aa0
    {                                                                       \
Packit 8c9aa0
      TestSuiteBuilderContextType context( baseContext )
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
/*! \brief Begin test suite (includes parent suite)
Packit 8c9aa0
 * 
Packit 8c9aa0
 * This macro may only be used in a class whose parent class
Packit 8c9aa0
 * defines a test suite using CPPUNIT_TEST_SUITE() or CPPUNIT_TEST_SUB_SUITE().
Packit 8c9aa0
 *
Packit 8c9aa0
 * This macro begins the declaration of a test suite, in the same
Packit 8c9aa0
 * manner as CPPUNIT_TEST_SUITE().  In addition, the test suite of the
Packit 8c9aa0
 * parent is automatically inserted in the test suite being
Packit 8c9aa0
 * defined.
Packit 8c9aa0
 * 
Packit 8c9aa0
 * Here is an example:
Packit 8c9aa0
 *
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * #include <cppunit/extensions/HelperMacros.h>
Packit 8c9aa0
 * class MySubTest : public MyTest {
Packit 8c9aa0
 *   CPPUNIT_TEST_SUB_SUITE( MySubTest, MyTest );
Packit 8c9aa0
 *   CPPUNIT_TEST( testAdd );
Packit 8c9aa0
 *   CPPUNIT_TEST( testSub );
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE_END();
Packit 8c9aa0
 * public:
Packit 8c9aa0
 *   void testAdd();
Packit 8c9aa0
 *   void testSub();
Packit 8c9aa0
 * };
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 *
Packit 8c9aa0
 * \param ATestFixtureType Type of the test case class. This type \b MUST
Packit 8c9aa0
 *                         be derived from TestFixture.
Packit 8c9aa0
 * \param ASuperClass   Type of the parent class.
Packit 8c9aa0
 * \see CPPUNIT_TEST_SUITE.
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST_SUB_SUITE( ATestFixtureType, ASuperClass )  \
Packit 8c9aa0
  public:                                                        \
Packit 8c9aa0
    typedef ASuperClass ParentTestFixtureType;                   \
Packit 8c9aa0
  private:                                                       \
Packit 8c9aa0
    CPPUNIT_TEST_SUITE( ATestFixtureType );                      \
Packit 8c9aa0
      ParentTestFixtureType::addTestsToSuite( baseContext )
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
/*! \brief End declaration of the test suite.
Packit 8c9aa0
 *
Packit 8c9aa0
 * After this macro, member access is set to "private".
Packit 8c9aa0
 *
Packit 8c9aa0
 * \see  CPPUNIT_TEST_SUITE.
Packit 8c9aa0
 * \see  CPPUNIT_TEST_SUITE_REGISTRATION.
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST_SUITE_END()                                               \
Packit 8c9aa0
    }                                                                          \
Packit 8c9aa0
                                                                               \
Packit 8c9aa0
public:									       \
Packit 8c9aa0
    static CPPUNIT_NS::TestSuite *suite()                                      \
Packit 8c9aa0
    {                                                                          \
Packit 8c9aa0
      const CPPUNIT_NS::TestNamer &namer = getTestNamer__();                   \
Packit 8c9aa0
      std::unique_ptr<CPPUNIT_NS::TestSuite> guard(                            \
Packit 8c9aa0
              new CPPUNIT_NS::TestSuite( namer.getFixtureName() ));            \
Packit 8c9aa0
      CPPUNIT_NS::ConcretTestFixtureFactory<TestFixtureType> factory;          \
Packit 8c9aa0
      CPPUNIT_NS::TestSuiteBuilderContextBase context( *guard.get(),           \
Packit 8c9aa0
                                                       namer,                  \
Packit 8c9aa0
                                                       factory );              \
Packit 8c9aa0
      TestFixtureType::addTestsToSuite( context );                             \
Packit 8c9aa0
      return guard.release();                                                  \
Packit 8c9aa0
    }                                                                          \
Packit 8c9aa0
  private: /* dummy typedef so that the macro can still end with ';'*/         \
Packit 8c9aa0
    typedef int CppUnitDummyTypedefForSemiColonEnding__
Packit 8c9aa0
Packit 8c9aa0
/*! \brief End declaration of an abstract test suite.
Packit 8c9aa0
 *
Packit 8c9aa0
 * Use this macro to indicate that the %TestFixture is abstract. No
Packit 8c9aa0
 * static suite() method will be declared. 
Packit 8c9aa0
 *
Packit 8c9aa0
 * After this macro, member access is set to "private".
Packit 8c9aa0
 *
Packit 8c9aa0
 * Here is an example of usage:
Packit 8c9aa0
 *
Packit 8c9aa0
 * The abstract test fixture:
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * #include <cppunit/extensions/HelperMacros.h>
Packit 8c9aa0
 * class AbstractDocument;
Packit 8c9aa0
 * class AbstractDocumentTest : public CppUnit::TestFixture {
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE( AbstractDocumentTest );
Packit 8c9aa0
 *   CPPUNIT_TEST( testInsertText );
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE_END_ABSTRACT();
Packit 8c9aa0
 * public:
Packit 8c9aa0
 *   void testInsertText();
Packit 8c9aa0
 * 
Packit 8c9aa0
 *   void setUp()
Packit 8c9aa0
 *   {
Packit 8c9aa0
 *     m_document = makeDocument();
Packit 8c9aa0
 *   }
Packit 8c9aa0
 *
Packit 8c9aa0
 *   void tearDown()
Packit 8c9aa0
 *   {
Packit 8c9aa0
 *     delete m_document;
Packit 8c9aa0
 *   }
Packit 8c9aa0
 * protected:
Packit 8c9aa0
 *   virtual AbstractDocument *makeDocument() =0;
Packit 8c9aa0
 *
Packit 8c9aa0
 *   AbstractDocument *m_document;
Packit 8c9aa0
 * };\endcode
Packit 8c9aa0
 *
Packit 8c9aa0
 * The concret test fixture:
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * class RichTextDocumentTest : public AbstractDocumentTest {
Packit 8c9aa0
 *   CPPUNIT_TEST_SUB_SUITE( RichTextDocumentTest, AbstractDocumentTest );
Packit 8c9aa0
 *   CPPUNIT_TEST( testInsertFormatedText );
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE_END();
Packit 8c9aa0
 * public:
Packit 8c9aa0
 *   void testInsertFormatedText();
Packit 8c9aa0
 * protected:
Packit 8c9aa0
 *   AbstractDocument *makeDocument()
Packit 8c9aa0
 *   {
Packit 8c9aa0
 *     return new RichTextDocument();
Packit 8c9aa0
 *   }
Packit 8c9aa0
 * };\endcode
Packit 8c9aa0
 *
Packit 8c9aa0
 * \see  CPPUNIT_TEST_SUB_SUITE.
Packit 8c9aa0
 * \see  CPPUNIT_TEST_SUITE_REGISTRATION.
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST_SUITE_END_ABSTRACT()                                      \
Packit 8c9aa0
    }                                                                          \
Packit 8c9aa0
  private: /* dummy typedef so that the macro can still end with ';'*/         \
Packit 8c9aa0
    typedef int CppUnitDummyTypedefForSemiColonEnding__
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
/*! \brief Add a test to the suite (for custom test macro).
Packit 8c9aa0
 *
Packit 8c9aa0
 * The specified test will be added to the test suite being declared. This macro
Packit 8c9aa0
 * is intended for \e advanced usage, to extend %CppUnit by creating new macro such
Packit 8c9aa0
 * as CPPUNIT_TEST_EXCEPTION()...
Packit 8c9aa0
 *
Packit 8c9aa0
 * Between macro CPPUNIT_TEST_SUITE() and CPPUNIT_TEST_SUITE_END(), you can assume
Packit 8c9aa0
 * that the following variables can be used:
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * typedef TestSuiteBuilder<TestFixtureType> TestSuiteBuilderType;
Packit 8c9aa0
 * TestSuiteBuilderType &context;
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 *
Packit 8c9aa0
 * \c context can be used to name test case, create new test fixture instance,
Packit 8c9aa0
 * or add test case to the test fixture suite.
Packit 8c9aa0
 *
Packit 8c9aa0
 * Below is an example that show how to use this macro to create new macro to add
Packit 8c9aa0
 * test to the fixture suite. The macro below show how you would add a new type
Packit 8c9aa0
 * of test case which fails if the execution last more than a given time limit.
Packit 8c9aa0
 * It relies on an imaginary TimeOutTestCaller class which has an interface similar
Packit 8c9aa0
 * to TestCaller.
Packit 8c9aa0
 * 
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * #define CPPUNITEX_TEST_TIMELIMIT( testMethod, timeLimit )            \
Packit 8c9aa0
 *      CPPUNIT_TEST_SUITE_ADD_TEST( (new TimeOutTestCaller<TestFixtureType>(  \
Packit 8c9aa0
 *                  namer.getTestNameFor( #testMethod ),                \
Packit 8c9aa0
 *                  &TestFixtureType::testMethod,                   \
Packit 8c9aa0
 *                  factory.makeFixture(),                              \
Packit 8c9aa0
 *                  timeLimit ) ) )
Packit 8c9aa0
 *   
Packit 8c9aa0
 * class PerformanceTest : CppUnit::TestFixture
Packit 8c9aa0
 * {
Packit 8c9aa0
 * public:
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE( PerformanceTest );
Packit 8c9aa0
 *   CPPUNITEX_TEST_TIMELIMIT( testSortReverseOrder, 5.0 );
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE_END();
Packit 8c9aa0
 *
Packit 8c9aa0
 *   void testSortReverseOrder();
Packit 8c9aa0
 * };
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 *
Packit 8c9aa0
 * \param test Test to add to the suite. Must be a subclass of Test. The test name
Packit 8c9aa0
 *             should have been obtained using TestNamer::getTestNameFor().
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \
Packit 8c9aa0
      context.addTest( test )
Packit 8c9aa0
Packit 8c9aa0
/*! \brief Add a method to the suite.
Packit 8c9aa0
 * \param testMethod Name of the method of the test case to add to the
Packit 8c9aa0
 *                   suite. The signature of the method must be of
Packit 8c9aa0
 *                   type: void testMethod();
Packit 8c9aa0
 * \see  CPPUNIT_TEST_SUITE.
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST( testMethod )                        \
Packit 8c9aa0
    CPPUNIT_TEST_SUITE_ADD_TEST(                           \
Packit 8c9aa0
        ( new CPPUNIT_NS::TestCaller<TestFixtureType>(    \
Packit 8c9aa0
                  context.getTestNameFor( #testMethod),   \
Packit 8c9aa0
                  &TestFixtureType::testMethod,           \
Packit 8c9aa0
                  context.makeFixture() ) ) )
Packit 8c9aa0
Packit 8c9aa0
#define CPPUNIT_TEST_PARAMETERIZED( testMethod, ... )    \
Packit 8c9aa0
    for (auto& i : __VA_ARGS__)                                  \
Packit 8c9aa0
    {                                                           \
Packit 8c9aa0
        TestFixtureType* fixture = context.makeFixture();       \
Packit 8c9aa0
        CPPUNIT_TEST_SUITE_ADD_TEST(                            \
Packit 8c9aa0
        ( new CPPUNIT_NS::TestCaller<TestFixtureType>(          \
Packit 8c9aa0
                    context.getTestNameFor(#testMethod, i),     \
Packit 8c9aa0
                    std::bind(&TestFixtureType::testMethod, fixture, i),          \
Packit 8c9aa0
                    fixture)));                                  \
Packit 8c9aa0
    }
Packit 8c9aa0
Packit 8c9aa0
/*! \brief Add a test which fail if the specified exception is not caught.
Packit 8c9aa0
 *
Packit 8c9aa0
 * Example:
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * #include <cppunit/extensions/HelperMacros.h>
Packit 8c9aa0
 * #include <vector>
Packit 8c9aa0
 * class MyTest : public CppUnit::TestFixture {
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE( MyTest );
Packit 8c9aa0
 *   CPPUNIT_TEST_EXCEPTION( testVectorAtThrow, std::out_of_range );
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE_END();
Packit 8c9aa0
 * public:
Packit 8c9aa0
 *   void testVectorAtThrow()
Packit 8c9aa0
 *   {
Packit 8c9aa0
 *     std::vector<int> v;
Packit 8c9aa0
 *     v.at( 1 );     // must throw exception std::out_of_range
Packit 8c9aa0
 *   }
Packit 8c9aa0
 * };
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 *
Packit 8c9aa0
 * \param testMethod Name of the method of the test case to add to the suite.
Packit 8c9aa0
 * \param ExceptionType Type of the exception that must be thrown by the test 
Packit 8c9aa0
 *                      method.
Packit 8c9aa0
 * \deprecated Use the assertion macro CPPUNIT_ASSERT_THROW instead.
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType )          \
Packit 8c9aa0
  CPPUNIT_TEST_SUITE_ADD_TEST(                                        \
Packit 8c9aa0
      (new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >(  \
Packit 8c9aa0
          new CPPUNIT_NS::TestCaller< TestFixtureType >(             \
Packit 8c9aa0
                               context.getTestNameFor( #testMethod ),  \
Packit 8c9aa0
                               &TestFixtureType::testMethod,         \
Packit 8c9aa0
                               context.makeFixture() ) ) ) )
Packit 8c9aa0
Packit 8c9aa0
/*! \brief Adds a test case which is excepted to fail.
Packit 8c9aa0
 *
Packit 8c9aa0
 * The added test case expect an assertion to fail. You usually used that type
Packit 8c9aa0
 * of test case when testing custom assertion macros.
Packit 8c9aa0
 *
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * CPPUNIT_TEST_FAIL( testAssertFalseFail );
Packit 8c9aa0
 * 
Packit 8c9aa0
 * void testAssertFalseFail()
Packit 8c9aa0
 * {
Packit 8c9aa0
 *   CPPUNIT_ASSERT( false );
Packit 8c9aa0
 * }
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 * \see CreatingNewAssertions.
Packit 8c9aa0
 * \deprecated Use the assertion macro CPPUNIT_ASSERT_ASSERTION_FAIL instead.
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST_FAIL( testMethod ) \
Packit 8c9aa0
              CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
Packit 8c9aa0
Packit 8c9aa0
/*! \brief Adds some custom test cases.
Packit 8c9aa0
 *
Packit 8c9aa0
 * Use this to add one or more test cases to the fixture suite. The specified
Packit 8c9aa0
 * method is called with a context parameter that can be used to name, 
Packit 8c9aa0
 * instantiate fixture, and add instantiated test case to the fixture suite.
Packit 8c9aa0
 * The specified method must have the following signature:
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * static void aMethodName( TestSuiteBuilderContextType &context );
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 *
Packit 8c9aa0
 * \c TestSuiteBuilderContextType is typedef to 
Packit 8c9aa0
 * TestSuiteBuilderContext<TestFixtureType> declared by CPPUNIT_TEST_SUITE().
Packit 8c9aa0
 *
Packit 8c9aa0
 * Here is an example that add two custom tests:
Packit 8c9aa0
 *
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * #include <cppunit/extensions/HelperMacros.h>
Packit 8c9aa0
 *
Packit 8c9aa0
 * class MyTest : public CppUnit::TestFixture {
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE( MyTest );
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( addTimeOutTests );
Packit 8c9aa0
 *   CPPUNIT_TEST_SUITE_END();
Packit 8c9aa0
 * public:
Packit 8c9aa0
 *   static void addTimeOutTests( TestSuiteBuilderContextType &context )
Packit 8c9aa0
 *   {
Packit 8c9aa0
 *     context.addTest( new TimeOutTestCaller( context.getTestNameFor( "test1" ) ),
Packit 8c9aa0
 *                                             &MyTest::test1,
Packit 8c9aa0
 *                                             context.makeFixture(),
Packit 8c9aa0
 *                                             5.0 );
Packit 8c9aa0
 *     context.addTest( new TimeOutTestCaller( context.getTestNameFor( "test2" ) ),
Packit 8c9aa0
 *                                             &MyTest::test2,
Packit 8c9aa0
 *                                             context.makeFixture(),
Packit 8c9aa0
 *                                             5.0 );
Packit 8c9aa0
 *   }
Packit 8c9aa0
 *
Packit 8c9aa0
 *   void test1()
Packit 8c9aa0
 *   {
Packit 8c9aa0
 *     // Do some test that may never end...
Packit 8c9aa0
 *   }
Packit 8c9aa0
 *
Packit 8c9aa0
 *   void test2()
Packit 8c9aa0
 *   {
Packit 8c9aa0
 *     // Do some test that may never end...
Packit 8c9aa0
 *   }
Packit 8c9aa0
 * };
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 * @param testAdderMethod Name of the method called to add the test cases.
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
Packit 8c9aa0
      testAdderMethod( context )
Packit 8c9aa0
Packit 8c9aa0
/*! \brief Adds a property to the test suite builder context.
Packit 8c9aa0
 * \param APropertyKey   Key of the property to add.
Packit 8c9aa0
 * \param APropertyValue Value for the added property.
Packit 8c9aa0
 * Example:
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * CPPUNIT_TEST_SUITE_PROPERTY("XmlFileName", "paraTest.xml"); \endcode
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
Packit 8c9aa0
    context.addProperty( std::string(APropertyKey),                 \
Packit 8c9aa0
                         std::string(APropertyValue) )
Packit 8c9aa0
Packit 8c9aa0
/** @}
Packit 8c9aa0
 */
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
/*! Adds the specified fixture suite to the unnamed registry.
Packit 8c9aa0
 * \ingroup CreatingTestSuite
Packit 8c9aa0
 *
Packit 8c9aa0
 * This macro declares a static variable whose construction
Packit 8c9aa0
 * causes a test suite factory to be inserted in a global registry
Packit 8c9aa0
 * of such factories.  The registry is available by calling
Packit 8c9aa0
 * the static function CppUnit::TestFactoryRegistry::getRegistry().
Packit 8c9aa0
 * 
Packit 8c9aa0
 * \param ATestFixtureType Type of the test case class.
Packit 8c9aa0
 * \warning This macro should be used only once per line of code (the line
Packit 8c9aa0
 *          number is used to name a hidden static variable).
Packit 8c9aa0
 * \see CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
Packit 8c9aa0
 * \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT
Packit 8c9aa0
 * \see CPPUNIT_REGISTRY_ADD
Packit 8c9aa0
 * \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite, 
Packit 8c9aa0
 *      CppUnit::TestFactoryRegistry.
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType )      \
Packit 8c9aa0
  static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType >       \
Packit 8c9aa0
             CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
/** Adds the specified fixture suite to the specified registry suite.
Packit 8c9aa0
 * \ingroup CreatingTestSuite
Packit 8c9aa0
 *
Packit 8c9aa0
 * This macro declares a static variable whose construction
Packit 8c9aa0
 * causes a test suite factory to be inserted in the global registry
Packit 8c9aa0
 * suite of the specified name. The registry is available by calling
Packit 8c9aa0
 * the static function CppUnit::TestFactoryRegistry::getRegistry().
Packit 8c9aa0
 * 
Packit 8c9aa0
 * For the suite name, use a string returned by a static function rather
Packit 8c9aa0
 * than a hardcoded string. That way, you can know what are the name of
Packit 8c9aa0
 * named registry and you don't risk mistyping the registry name.
Packit 8c9aa0
 *
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * // MySuites.h
Packit 8c9aa0
 * namespace MySuites {
Packit 8c9aa0
 *   std::string math() { 
Packit 8c9aa0
 *     return "Math";
Packit 8c9aa0
 *   }
Packit 8c9aa0
 * }
Packit 8c9aa0
 *
Packit 8c9aa0
 * // ComplexNumberTest.cpp
Packit 8c9aa0
 * #include "MySuites.h"
Packit 8c9aa0
 * 
Packit 8c9aa0
 * CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComplexNumberTest, MySuites::math() );
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 *
Packit 8c9aa0
 * \param ATestFixtureType Type of the test case class.
Packit 8c9aa0
 * \param suiteName Name of the global registry suite the test suite is 
Packit 8c9aa0
 *                  registered into.
Packit 8c9aa0
 * \warning This macro should be used only once per line of code (the line
Packit 8c9aa0
 *          number is used to name a hidden static variable).
Packit 8c9aa0
 * \see CPPUNIT_TEST_SUITE_REGISTRATION
Packit 8c9aa0
 * \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT
Packit 8c9aa0
 * \see CPPUNIT_REGISTRY_ADD
Packit 8c9aa0
 * \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite, 
Packit 8c9aa0
 *      CppUnit::TestFactoryRegistry..
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
Packit 8c9aa0
  static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType >                   \
Packit 8c9aa0
             CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
Packit 8c9aa0
Packit 8c9aa0
/*! Adds that the specified registry suite to another registry suite.
Packit 8c9aa0
 * \ingroup CreatingTestSuite
Packit 8c9aa0
 *
Packit 8c9aa0
 * Use this macros to automatically create test registry suite hierarchy. For example,
Packit 8c9aa0
 * if you want to create the following hierarchy:
Packit 8c9aa0
 * - Math
Packit 8c9aa0
 *   - IntegerMath
Packit 8c9aa0
 *   - FloatMath
Packit 8c9aa0
 *     - FastFloat
Packit 8c9aa0
 *     - StandardFloat
Packit 8c9aa0
 * 
Packit 8c9aa0
 * You can do this automatically with:
Packit 8c9aa0
 * \code
Packit 8c9aa0
 * CPPUNIT_REGISTRY_ADD( "FastFloat", "FloatMath" );
Packit 8c9aa0
 * CPPUNIT_REGISTRY_ADD( "IntegerMath", "Math" );
Packit 8c9aa0
 * CPPUNIT_REGISTRY_ADD( "FloatMath", "Math" );
Packit 8c9aa0
 * CPPUNIT_REGISTRY_ADD( "StandardFloat", "FloatMath" );
Packit 8c9aa0
 * \endcode
Packit 8c9aa0
 *
Packit 8c9aa0
 * There is no specific order of declaration. Think of it as declaring links.
Packit 8c9aa0
 *
Packit 8c9aa0
 * You register the test in each suite using CPPUNIT_TEST_SUITE_NAMED_REGISTRATION.
Packit 8c9aa0
 *
Packit 8c9aa0
 * \param which Name of the registry suite to add to the registry suite named \a to.
Packit 8c9aa0
 * \param to Name of the registry suite \a which is added to.
Packit 8c9aa0
 * \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION.
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_REGISTRY_ADD( which, to )                                     \
Packit 8c9aa0
  static CPPUNIT_NS::AutoRegisterRegistry                                     \
Packit 8c9aa0
             CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
Packit 8c9aa0
Packit 8c9aa0
/*! Adds that the specified registry suite to the default registry suite.
Packit 8c9aa0
 * \ingroup CreatingTestSuite
Packit 8c9aa0
 *
Packit 8c9aa0
 * This macro is just like CPPUNIT_REGISTRY_ADD except the specified registry
Packit 8c9aa0
 * suite is added to the default suite (root suite).
Packit 8c9aa0
 *
Packit 8c9aa0
 * \param which Name of the registry suite to add to the default registry suite.
Packit 8c9aa0
 * \see CPPUNIT_REGISTRY_ADD.
Packit 8c9aa0
 */
Packit 8c9aa0
#define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which )                         \
Packit 8c9aa0
  static CPPUNIT_NS::AutoRegisterRegistry                                \
Packit 8c9aa0
             CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
Packit 8c9aa0
Packit 8c9aa0
// Backwards compatibility
Packit 8c9aa0
// (Not tested!)
Packit 8c9aa0
Packit 8c9aa0
#if CPPUNIT_ENABLE_CU_TEST_MACROS
Packit 8c9aa0
Packit 8c9aa0
#define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
Packit 8c9aa0
#define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
Packit 8c9aa0
#define CU_TEST(tm) CPPUNIT_TEST(tm)
Packit 8c9aa0
#define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
Packit 8c9aa0
#define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
Packit 8c9aa0
Packit 8c9aa0
#endif
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
#endif  // CPPUNIT_EXTENSIONS_HELPERMACROS_H