summaryrefslogtreecommitdiff
path: root/include/cppunit/extensions
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-03-27 16:56:47 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-03-27 16:56:47 +0000
commit41e210a888ae68e1d908e60d903a65672f068b14 (patch)
tree993f2fccd68aec0993c89e7fa610047b4abd8953 /include/cppunit/extensions
parentfba5df08cb90d511e536f53d0aea57b547e2b6ef (diff)
downloadcppunit-41e210a888ae68e1d908e60d903a65672f068b14.tar.gz
Makefile.
makefile.am: added src/CppUnitLibraries.dsw, new contribution, and src/qttestrunner. * TODO: updated (doc). * contrib/msvc/AddingUnitTestMethod.dsm: added, submitted by bloodchen@hotmail.com. * constrib/msvc/readme.txt: updated. * include/cppunit/TestAsserter.h: * include/cppunit/SourceLine.h: updated doc. * include/cppunit/TestCaller.h: reindented. updated doc. * include/cppunit/extensions/HelperMacros.h: relaxed constraint on fixture. Fixture base class may be TestFixture instead of TestCase. * include/cppunit/TestCase.h: * src/cppunit/TestCase.h: TestCase inherits TestFixture for setUp() and tearDown() definition. Moved documentation to TestFixture. * include/cppunit/TestFixture.h: updated documentation. * include/cppunit/TestRegistry.h: * src/cppunit/TestRegistry.cpp: Removed. Replaced by TestFactoryRegistry. * include/cppunit/TextTestRunner.h: * src/cppunit/TextTestRunner.cpp: made printing progress using a TextTestProgressListener optional. * examples\cppunittest\ExceptionTest.h: * examples\cppunittest\HelperMacrosTest.h: * examples\cppunittest\HelperMacrosTest.cpp: * examples\cppunittest\NotEqualException.h: * examples\cppunittest\OrthodoxTest.h: * examples\cppunittest\RepeatedTest.h: * examples\cppunittest\TestAssertTest.h: * examples\cppunittest\TestCallerTest.h: * examples\cppunittest\TestDecoratorTest.h: * examples\cppunittest\TestFailureTest.h: * examples\cppunittest\TestResultCollectorTest.h: * examples\cppunittest\TestResultTest.h: * examples\cppunittest\TestSetUpTest.h: * examples\cppunittest\TestSuiteTest.h: * examples\cppunittest\XmlOutputterTest.h: * examples\cppunittest\XmlOutputterTest.cpp: * examples\cppunittest\XmlUniformizerTest.h: * examples\cppunittest\XmlUniformizerTest.cpp: changed base class for fixture from TestCase to TestFixture. * examples\hierarchy\BoardGameTest.h: * examples\hierarchy\ChessTest.h: * examples\hierarchy\main.cpp: updated to use HelperMacros for correct fixture instantiation (the ChessBoard::testReset test case was using BoardGame fixture instance instead of ChessBoard).
Diffstat (limited to 'include/cppunit/extensions')
-rw-r--r--include/cppunit/extensions/HelperMacros.h99
1 files changed, 56 insertions, 43 deletions
diff --git a/include/cppunit/extensions/HelperMacros.h b/include/cppunit/extensions/HelperMacros.h
index 637268d..a5415fe 100644
--- a/include/cppunit/extensions/HelperMacros.h
+++ b/include/cppunit/extensions/HelperMacros.h
@@ -11,6 +11,18 @@
#include <cppunit/extensions/TestSuiteBuilder.h>
#include <string>
+namespace CppUnit
+{
+ class TestFixture;
+
+ class TestFixtureFactory
+ {
+ public:
+ virtual CppUnit::TestFixture *makeFixture() =0;
+ };
+} // namespace CppUnit
+
+
// The macro __CPPUNIT_SUITE_CTOR_ARGS expand to an expression used to construct
// the TestSuiteBuilder with macro CPPUNIT_TEST_SUITE.
//
@@ -19,9 +31,9 @@
//
// This macro is for cppunit internal and should not be use otherwise.
#if CPPUNIT_USE_TYPEINFO_NAME
-# define __CPPUNIT_SUITE_CTOR_ARGS( ATestCaseType )
+# define __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType )
#else
-# define __CPPUNIT_SUITE_CTOR_ARGS( ATestCaseType ) (std::string(#ATestCaseType))
+# define __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType ) (std::string(#ATestFixtureType))
#endif
@@ -95,25 +107,26 @@
* Use CPPUNIT_TEST_SUB_SUITE() instead, if you wish to include the
* test suite of the parent class.
*
- * \param ATestCaseType Type of the test case class.
- * \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END, CPPUNIT_TEST_SUITE_REGISTRATION.
+ * \param ATestFixtureType Type of the test case class.
+ * \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END,
+ * \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_EXCEPTION, CPPUNIT_TEST_FAIL.
*/
-#define CPPUNIT_TEST_SUITE( ATestCaseType ) \
+#define CPPUNIT_TEST_SUITE( ATestFixtureType ) \
private: \
- typedef ATestCaseType __ThisTestCaseType; \
- class ThisTestCaseFactory : public CppUnit::TestFactory \
+ typedef ATestFixtureType __ThisTestFixtureType; \
+ class ThisTestFixtureFactory : public CppUnit::TestFixtureFactory \
{ \
- virtual CppUnit::Test *makeTest() \
+ virtual CppUnit::TestFixture *makeFixture() \
{ \
- return new ATestCaseType(); \
+ return new ATestFixtureType(); \
} \
}; \
public: \
static void \
registerTests( CppUnit::TestSuite *suite, \
- CppUnit::TestFactory *factory ) \
+ CppUnit::TestFixtureFactory *factory ) \
{ \
- CppUnit::TestSuiteBuilder<__ThisTestCaseType> builder( suite );
+ CppUnit::TestSuiteBuilder<__ThisTestFixtureType> builder( suite );
/** Begin test suite (includes parent suite)
@@ -141,14 +154,14 @@
* };
* \endcode
*
- * \param ATestCaseType Type of the test case class.
+ * \param ATestFixtureType Type of the test case class.
* \param ASuperClass Type of the parent class.
* \see CPPUNIT_TEST_SUITE.
*/
-#define CPPUNIT_TEST_SUB_SUITE( ATestCaseType, ASuperClass ) \
- private: \
- typedef ASuperClass __ThisSuperClassType; \
- CPPUNIT_TEST_SUITE( ATestCaseType ); \
+#define CPPUNIT_TEST_SUB_SUITE( ATestFixtureType, ASuperClass ) \
+ private: \
+ typedef ASuperClass __ThisSuperClassType; \
+ CPPUNIT_TEST_SUITE( ATestFixtureType ); \
__ThisSuperClassType::registerTests( suite, factory )
@@ -158,10 +171,10 @@
* type: void testMethod();
* \see CPPUNIT_TEST_SUITE.
*/
-#define CPPUNIT_TEST( testMethod ) \
- builder.addTestCaller( #testMethod, \
- &__ThisTestCaseType::testMethod , \
- (__ThisTestCaseType*)factory->makeTest() )
+#define CPPUNIT_TEST( testMethod ) \
+ builder.addTestCaller( #testMethod, \
+ &__ThisTestFixtureType::testMethod , \
+ (__ThisTestFixtureType*)factory->makeFixture() )
/*! Add a test which fail if the specified exception is not caught.
@@ -187,10 +200,10 @@
* \param ExceptionType Type of the exception that must be thrown by the test
* method.
*/
-#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
- builder.addTestCallerForException( #testMethod, \
- &__ThisTestCaseType::testMethod , \
- (__ThisTestCaseType*)factory->makeTest(), \
+#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
+ builder.addTestCallerForException( #testMethod, \
+ &__ThisTestFixtureType::testMethod , \
+ (__ThisTestFixtureType*)factory->makeFixture(), \
(ExceptionType *)NULL );
/*! Add a test which is excepted to fail.
@@ -208,19 +221,19 @@
* \see CPPUNIT_TEST_SUITE.
* \see CPPUNIT_TEST_SUITE_REGISTRATION.
*/
-#define CPPUNIT_TEST_SUITE_END() \
- builder.takeSuite(); \
- } \
- static CppUnit::TestSuite *suite() \
- { \
- CppUnit::TestSuiteBuilder<__ThisTestCaseType> \
- builder __CPPUNIT_SUITE_CTOR_ARGS( ATestCaseType ); \
- ThisTestCaseFactory factory; \
- __ThisTestCaseType::registerTests( builder.suite(), &factory ); \
- return builder.takeSuite(); \
- } \
- private: /* dummy typedef so that the macro can still end with ';'*/ \
- typedef ThisTestCaseFactory __ThisTestCaseFactory
+#define CPPUNIT_TEST_SUITE_END() \
+ builder.takeSuite(); \
+ } \
+ static CppUnit::TestSuite *suite() \
+ { \
+ CppUnit::TestSuiteBuilder<__ThisTestFixtureType> \
+ builder __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType ); \
+ ThisTestFixtureFactory factory; \
+ __ThisTestFixtureType::registerTests( builder.suite(), &factory ); \
+ return builder.takeSuite(); \
+ } \
+ private: /* dummy typedef so that the macro can still end with ';'*/ \
+ typedef ThisTestFixtureFactory __ThisTestFixtureFactory
#define __CPPUNIT_CONCATENATE_DIRECT( s1, s2 ) s1##s2
#define __CPPUNIT_CONCATENATE( s1, s2 ) __CPPUNIT_CONCATENATE_DIRECT( s1, s2 )
@@ -238,14 +251,14 @@
* of such factories. The registry is available by calling
* the static function CppUnit::TestFactoryRegistry::getRegistry().
*
- * \param ATestCaseType Type of the test case class.
+ * \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, CppUnit::AutoRegisterSuite,
* CppUnit::TestFactoryRegistry.
*/
-#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestCaseType ) \
- static CppUnit::AutoRegisterSuite< ATestCaseType > \
+#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
+ static CppUnit::AutoRegisterSuite< ATestFixtureType > \
__CPPUNIT_MAKE_UNIQUE_NAME(__autoRegisterSuite )
@@ -256,7 +269,7 @@
* suite of the specified name. The registry is available by calling
* the static function CppUnit::TestFactoryRegistry::getRegistry().
*
- * \param ATestCaseType Type of the test case class.
+ * \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
@@ -264,8 +277,8 @@
* \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite,
* CppUnit::TestFactoryRegistry..
*/
-#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestCaseType, suiteName ) \
- static CppUnit::AutoRegisterSuite< ATestCaseType > \
+#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
+ static CppUnit::AutoRegisterSuite< ATestFixtureType > \
__CPPUNIT_MAKE_UNIQUE_NAME(__autoRegisterSuite )(suiteName)