⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 helpermacros.h

📁 浙江大学的悟空嵌入式系统模拟器
💻 H
📖 第 1 页 / 共 2 页
字号:
 *   
 * class PerformanceTest : CppUnit::TestFixture
 * {
 * public:
 *   CPPUNIT_TEST_SUITE( PerformanceTest );
 *   CPPUNITEX_TEST_TIMELIMIT( testSortReverseOrder, 5.0 );
 *   CPPUNIT_TEST_SUITE_END();
 *
 *   void testSortReverseOrder();
 * };
 * \endcode
 *
 * \param test Test to add to the suite. Must be a subclass of Test. The test name
 *             should have been obtained using TestNamer::getTestNameFor().
 */
#define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \
      context.addTest( test )

/*! \brief Add a method to the suite.
 * \param testMethod Name of the method of the test case to add to the
 *                   suite. The signature of the method must be of
 *                   type: void testMethod();
 * \see  CPPUNIT_TEST_SUITE.
 */
#define CPPUNIT_TEST( testMethod )                        \
    CPPUNIT_TEST_SUITE_ADD_TEST(                           \
        ( new CPPUNIT_NS::TestCaller<TestFixtureType>(    \
                  context.getTestNameFor( #testMethod),   \
                  &TestFixtureType::testMethod,           \
                  context.makeFixture() ) ) )

/*! \brief Add a test which fail if the specified exception is not caught.
 *
 * Example:
 * \code
 * #include <cppunit/extensions/HelperMacros.h>
 * #include <vector>
 * class MyTest : public CppUnit::TestFixture {
 *   CPPUNIT_TEST_SUITE( MyTest );
 *   CPPUNIT_TEST_EXCEPTION( testVectorAtThrow, std::invalid_argument );
 *   CPPUNIT_TEST_SUITE_END();
 * public:
 *   void testVectorAtThrow()
 *   {
 *     std::vector<int> v;
 *     v.at( 1 );     // must throw exception std::invalid_argument
 *   }
 * };
 * \endcode
 *
 * \param testMethod Name of the method of the test case to add to the suite.
 * \param ExceptionType Type of the exception that must be thrown by the test 
 *                      method.
 * \deprecated Use the assertion macro CPPUNIT_ASSERT_THROW instead.
 */
#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType )          \
  CPPUNIT_TEST_SUITE_ADD_TEST(                                        \
      (new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >(  \
          new CPPUNIT_NS::TestCaller< TestFixtureType >(             \
                               context.getTestNameFor( #testMethod ),  \
                               &TestFixtureType::testMethod,         \
                               context.makeFixture() ) ) ) )

/*! \brief Adds a test case which is excepted to fail.
 *
 * The added test case expect an assertion to fail. You usually used that type
 * of test case when testing custom assertion macros.
 *
 * \code
 * CPPUNIT_TEST_FAIL( testAssertFalseFail );
 * 
 * void testAssertFalseFail()
 * {
 *   CPPUNIT_ASSERT( false );
 * }
 * \endcode
 * \see CreatingNewAssertions.
 * \deprecated Use the assertion macro CPPUNIT_ASSERT_ASSERTION_FAIL instead.
 */
#define CPPUNIT_TEST_FAIL( testMethod ) \
              CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )

/*! \brief Adds some custom test cases.
 *
 * Use this to add one or more test cases to the fixture suite. The specified
 * method is called with a context parameter that can be used to name, 
 * instantiate fixture, and add instantiated test case to the fixture suite.
 * The specified method must have the following signature:
 * \code
 * static void aMethodName( TestSuiteBuilderContextType &context );
 * \endcode
 *
 * \c TestSuiteBuilderContextType is typedef to 
 * TestSuiteBuilderContext<TestFixtureType> declared by CPPUNIT_TEST_SUITE().
 *
 * Here is an example that add two custom tests:
 *
 * \code
 * #include <cppunit/extensions/HelperMacros.h>
 *
 * class MyTest : public CppUnit::TestFixture {
 *   CPPUNIT_TEST_SUITE( MyTest );
 *   CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( addTimeOutTests );
 *   CPPUNIT_TEST_SUITE_END();
 * public:
 *   static void addTimeOutTests( TestSuiteBuilderContextType &context )
 *   {
 *     context.addTest( new TimeOutTestCaller( context.getTestNameFor( "test1" ) ),
 *                                             &MyTest::test1,
 *                                             context.makeFixture(),
 *                                             5.0 );
 *     context.addTest( new TimeOutTestCaller( context.getTestNameFor( "test2" ) ),
 *                                             &MyTest::test2,
 *                                             context.makeFixture(),
 *                                             5.0 );
 *   }
 *
 *   void test1()
 *   {
 *     // Do some test that may never end...
 *   }
 *
 *   void test2()
 *   {
 *     // Do some test that may never end...
 *   }
 * };
 * \endcode
 * @param testAdderMethod Name of the method called to add the test cases.
 */
#define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
      testAdderMethod( context )

/*! \brief Adds a property to the test suite builder context.
 * \param APropertyKey   Key of the property to add.
 * \param APropertyValue Value for the added property.
 * Example:
 * \code
 * CPPUNIT_TEST_SUITE_PROPERTY("XmlFileName", "paraTest.xml"); \endcode
 */
#define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
    context.addProperty( std::string(APropertyKey),                 \
                         std::string(APropertyValue) )

/** @}
 */


/*! Adds the specified fixture suite to the unnamed registry.
 * \ingroup CreatingTestSuite
 *
 * This macro declares a static variable whose construction
 * causes a test suite factory to be inserted in a global registry
 * of such factories.  The registry is available by calling
 * the static function CppUnit::TestFactoryRegistry::getRegistry().
 * 
 * \param ATestFixtureType Type of the test case class.
 * \warning This macro should be used only once per line of code (the line
 *          number is used to name a hidden static variable).
 * \see CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
 * \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT
 * \see CPPUNIT_REGISTRY_ADD
 * \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite, 
 *      CppUnit::TestFactoryRegistry.
 */
#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType )      \
  static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType >       \
             CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )


/** Adds the specified fixture suite to the specified registry suite.
 * \ingroup CreatingTestSuite
 *
 * This macro declares a static variable whose construction
 * causes a test suite factory to be inserted in the global registry
 * suite of the specified name. The registry is available by calling
 * the static function CppUnit::TestFactoryRegistry::getRegistry().
 * 
 * For the suite name, use a string returned by a static function rather
 * than a hardcoded string. That way, you can know what are the name of
 * named registry and you don't risk mistyping the registry name.
 *
 * \code
 * // MySuites.h
 * namespace MySuites {
 *   std::string math() { 
 *     return "Math";
 *   }
 * }
 *
 * // ComplexNumberTest.cpp
 * #include "MySuites.h"
 * 
 * CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComplexNumberTest, MySuites::math() );
 * \endcode
 *
 * \param ATestFixtureType Type of the test case class.
 * \param suiteName Name of the global registry suite the test suite is 
 *                  registered into.
 * \warning This macro should be used only once per line of code (the line
 *          number is used to name a hidden static variable).
 * \see CPPUNIT_TEST_SUITE_REGISTRATION
 * \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT
 * \see CPPUNIT_REGISTRY_ADD
 * \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite, 
 *      CppUnit::TestFactoryRegistry..
 */
#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
  static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType >                   \
             CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)

/*! Adds that the specified registry suite to another registry suite.
 * \ingroup CreatingTestSuite
 *
 * Use this macros to automatically create test registry suite hierarchy. For example,
 * if you want to create the following hierarchy:
 * - Math
 *   - IntegerMath
 *   - FloatMath
 *     - FastFloat
 *     - StandardFloat
 * 
 * You can do this automatically with:
 * \code
 * CPPUNIT_REGISTRY_ADD( "FastFloat", "FloatMath" );
 * CPPUNIT_REGISTRY_ADD( "IntegerMath", "Math" );
 * CPPUNIT_REGISTRY_ADD( "FloatMath", "Math" );
 * CPPUNIT_REGISTRY_ADD( "StandardFloat", "FloatMath" );
 * \endcode
 *
 * There is no specific order of declaration. Think of it as declaring links.
 *
 * You register the test in each suite using CPPUNIT_TEST_SUITE_NAMED_REGISTRATION.
 *
 * \param which Name of the registry suite to add to the registry suite named \a to.
 * \param to Name of the registry suite \a which is added to.
 * \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION.
 */
#define CPPUNIT_REGISTRY_ADD( which, to )                                     \
  static CPPUNIT_NS::AutoRegisterRegistry                                     \
             CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )

/*! Adds that the specified registry suite to the default registry suite.
 * \ingroup CreatingTestSuite
 *
 * This macro is just like CPPUNIT_REGISTRY_ADD except the specified registry
 * suite is added to the default suite (root suite).
 *
 * \param which Name of the registry suite to add to the default registry suite.
 * \see CPPUNIT_REGISTRY_ADD.
 */
#define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which )                         \
  static CPPUNIT_NS::AutoRegisterRegistry                                \
             CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )

// Backwards compatibility
// (Not tested!)

#if CPPUNIT_ENABLE_CU_TEST_MACROS

#define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
#define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
#define CU_TEST(tm) CPPUNIT_TEST(tm)
#define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
#define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)

#endif


#endif  // CPPUNIT_EXTENSIONS_HELPERMACROS_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -