summaryrefslogtreecommitdiff
path: root/include/cppunit/extensions
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2001-06-11 19:00:08 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2001-06-11 19:00:08 +0000
commite38eb47e23d6106c32ee136351b0080313339270 (patch)
tree7989d9f5435ed23b30ef45b9f3cd40f00cafc391 /include/cppunit/extensions
parentc7a4dccd9f1b1fadcd47afe482c8a8ff9e05ea8f (diff)
downloadcppunit-e38eb47e23d6106c32ee136351b0080313339270.tar.gz
Include/cppunit/extensions/HelperMacros.
include/cppunit/extensions/HelperMacros.h: static method suite() implemented by CPPUNIT_TEST_SUITE_END macro now returns a TestSuite instead of a Test. * include/cppunit/extensions/RepeatedTest.h: corrected countTestCases, operator = declaration. * include/cppunit/extensions/TestDecorator.h: removed const from run() method. Did not match run() declaration of Test class. * include/cppunit/extensions/TestFactory.h: fixed a comment. * include/cppunit/extensions/TestSetup.h: corrected run() method declaration. Methods setUp() and tearDown() were not declared virtual. * include/cppunit/extensions/TestSuiteBuilder.h: added a method addTestCaller() which take a pointer on a fixture.
Diffstat (limited to 'include/cppunit/extensions')
-rw-r--r--include/cppunit/extensions/HelperMacros.h58
-rw-r--r--include/cppunit/extensions/Makefile.am2
-rw-r--r--include/cppunit/extensions/Orthodox.h3
-rw-r--r--include/cppunit/extensions/RepeatedTest.h37
-rw-r--r--include/cppunit/extensions/TestDecorator.h4
-rw-r--r--include/cppunit/extensions/TestFactory.h2
-rw-r--r--include/cppunit/extensions/TestSetUp.h18
-rw-r--r--include/cppunit/extensions/TestSuiteBuilder.h22
8 files changed, 81 insertions, 65 deletions
diff --git a/include/cppunit/extensions/HelperMacros.h b/include/cppunit/extensions/HelperMacros.h
index 17784ea..a3df5f3 100644
--- a/include/cppunit/extensions/HelperMacros.h
+++ b/include/cppunit/extensions/HelperMacros.h
@@ -98,15 +98,15 @@
* \param ATestCaseType Type of the test case class.
* \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END, CPPUNIT_TEST_SUITE_REGISTRATION.
*/
-#define CPPUNIT_TEST_SUITE( ATestCaseType ) \
- private: \
- typedef ATestCaseType __ThisTestCaseType; \
- public: \
- template<typename TestCaseType> \
- static void \
- registerTests( CppUnit::TestSuiteBuilder<TestCaseType> &suite, \
- TestCaseType *test ) \
- {
+#define CPPUNIT_TEST_SUITE( ATestCaseType ) \
+ private: \
+ typedef ATestCaseType __ThisTestCaseType; \
+ public: \
+ static void \
+ registerTests( CppUnit::TestSuite *suite, \
+ CppUnit::TestFactory *factory ) \
+ { \
+ CppUnit::TestSuiteBuilder<__ThisTestCaseType> builder( suite );
/** Begin test suite (includes parent suite)
@@ -138,11 +138,11 @@
* \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 ); \
- __ThisSuperClassType::registerTests( suite, test )
+#define CPPUNIT_TEST_SUB_SUITE( ATestCaseType, ASuperClass ) \
+ private: \
+ typedef ASuperClass __ThisSuperClassType; \
+ CPPUNIT_TEST_SUITE( ATestCaseType ); \
+ __ThisSuperClassType::registerTests( suite, factory )
/** Add a method to the suite.
@@ -151,8 +151,10 @@
* type: void testMethod();
* \see CPPUNIT_TEST_SUITE.
*/
-#define CPPUNIT_TEST( testMethod ) \
- suite.addTestCaller( #testMethod, &__ThisTestCaseType::testMethod )
+#define CPPUNIT_TEST( testMethod ) \
+ builder.addTestCaller( #testMethod, \
+ &__ThisTestCaseType::testMethod , \
+ (__ThisTestCaseType*)factory->makeTest() )
/** End declaration of the test suite.
@@ -162,17 +164,25 @@
* \see CPPUNIT_TEST_SUITE.
* \see CPPUNIT_TEST_SUITE_REGISTRATION.
*/
-#define CPPUNIT_TEST_SUITE_END() \
-} \
- static CppUnit::Test *suite() \
+#define CPPUNIT_TEST_SUITE_END() \
+ builder.takeSuite(); \
+ } \
+ static CppUnit::TestSuite *suite() \
{ \
- __ThisTestCaseType *test =NULL; \
CppUnit::TestSuiteBuilder<__ThisTestCaseType> \
- suite __CPPUNIT_SUITE_CTOR_ARGS( ATestCaseType ); \
- __ThisTestCaseType::registerTests( suite, test ); \
- return suite.takeSuite(); \
+ builder __CPPUNIT_SUITE_CTOR_ARGS( ATestCaseType ); \
+ ThisTestCaseFactory factory; \
+ __ThisTestCaseType::registerTests( builder.suite(), &factory ); \
+ return builder.takeSuite(); \
} \
- private:
+ private: \
+ class ThisTestCaseFactory : public CppUnit::TestFactory \
+ { \
+ virtual CppUnit::Test *makeTest() \
+ { \
+ return new __ThisTestCaseType(); \
+ } \
+ };
#define __CPPUNIT_CONCATENATE_DIRECT( s1, s2 ) s1##s2
#define __CPPUNIT_CONCATENATE( s1, s2 ) __CPPUNIT_CONCATENATE_DIRECT( s1, s2 )
diff --git a/include/cppunit/extensions/Makefile.am b/include/cppunit/extensions/Makefile.am
index 46b50e9..a69ab1f 100644
--- a/include/cppunit/extensions/Makefile.am
+++ b/include/cppunit/extensions/Makefile.am
@@ -8,7 +8,7 @@ libcppunitinclude_HEADERS = \
RepeatedTest.h \
TestDecorator.h \
TestFactoryRegistry.h \
- TestSetup.h \
+ TestSetUp.h \
TestSuiteBuilder.h \
TestSuiteFactory.h \
TypeInfoHelper.h
diff --git a/include/cppunit/extensions/Orthodox.h b/include/cppunit/extensions/Orthodox.h
index 39506f1..5fc7aab 100644
--- a/include/cppunit/extensions/Orthodox.h
+++ b/include/cppunit/extensions/Orthodox.h
@@ -82,7 +82,8 @@ template <typename ClassUnderTest> void Orthodox<ClassUnderTest>::runTest ()
// Exercise a call
-template <typename ClassUnderTest> ClassUnderTest Orthodox<ClassUnderTest>::call (ClassUnderTest object)
+template <typename ClassUnderTest>
+ClassUnderTest Orthodox<ClassUnderTest>::call (ClassUnderTest object)
{
return object;
}
diff --git a/include/cppunit/extensions/RepeatedTest.h b/include/cppunit/extensions/RepeatedTest.h
index b96b6ec..7a68e88 100644
--- a/include/cppunit/extensions/RepeatedTest.h
+++ b/include/cppunit/extensions/RepeatedTest.h
@@ -14,45 +14,26 @@ class TestResult;
* Does not assume ownership of the test it decorates
*
*/
-
class RepeatedTest : public TestDecorator
{
public:
- RepeatedTest (Test *test, int timesRepeat)
- : TestDecorator (test), m_timesRepeat (timesRepeat) {}
+ RepeatedTest( Test *test,
+ int timesRepeat ) :
+ TestDecorator( test ),
+ m_timesRepeat(timesRepeat) {}
- int countTestCases ();
- std::string toString ();
- void run (TestResult *result);
+ int countTestCases();
+ std::string toString();
+ void run( TestResult *result );
private:
RepeatedTest( const RepeatedTest & );
- void operator( const RepeatedTest & );
+ void operator=( const RepeatedTest & );
- const int m_timesRepeat;
+ const int m_timesRepeat;
};
-// Counts the number of test cases that will be run by this test.
-inline RepeatedTest::countTestCases ()
-{ return TestDecorator::countTestCases () * m_timesRepeat; }
-
-// Returns the name of the test instance.
-inline std::string RepeatedTest::toString ()
-{ return TestDecorator::toString () + " (repeated)"; }
-
-// Runs a repeated test
-inline void RepeatedTest::run (TestResult *result)
-{
- for (int n = 0; n < m_timesRepeat; n++) {
- if (result->shouldStop ())
- break;
-
- TestDecorator::run (result);
- }
-}
-
-
} // namespace CppUnit
diff --git a/include/cppunit/extensions/TestDecorator.h b/include/cppunit/extensions/TestDecorator.h
index ab637d2..c706446 100644
--- a/include/cppunit/extensions/TestDecorator.h
+++ b/include/cppunit/extensions/TestDecorator.h
@@ -21,7 +21,7 @@ public:
~TestDecorator ();
int countTestCases () const;
- void run (TestResult *result) const;
+ void run (TestResult *result);
std::string toString () const;
std::string getName () const;
@@ -46,7 +46,7 @@ inline TestDecorator::countTestCases () const
{ return m_test->countTestCases (); }
-inline void TestDecorator::run (TestResult *result) const
+inline void TestDecorator::run (TestResult *result)
{ m_test->run (result); }
diff --git a/include/cppunit/extensions/TestFactory.h b/include/cppunit/extensions/TestFactory.h
index a648243..0658a09 100644
--- a/include/cppunit/extensions/TestFactory.h
+++ b/include/cppunit/extensions/TestFactory.h
@@ -20,4 +20,4 @@ namespace CppUnit {
} // namespace CppUnit
-#endif // CPPUNIT_EXTENSIONS_ABSTRACTTESTFACTORY_H
+#endif // CPPUNIT_EXTENSIONS_TESTFACTORY_H
diff --git a/include/cppunit/extensions/TestSetUp.h b/include/cppunit/extensions/TestSetUp.h
index 34f4603..c97402c 100644
--- a/include/cppunit/extensions/TestSetUp.h
+++ b/include/cppunit/extensions/TestSetUp.h
@@ -12,12 +12,13 @@ class TestResult;
class TestSetUp : public TestDecorator
{
public:
- TestSetUp (Test *test) : TestDecorator (test) {}
- run (TestResult *result);
+ TestSetUp (Test *test) : TestDecorator (test) {}
+
+ void run (TestResult *result);
protected:
- void setUp () {}
- void tearDown () {}
+ virtual void setUp () {}
+ virtual void tearDown () {}
private:
TestSetUp( const TestSetUp & );
@@ -25,8 +26,13 @@ private:
};
-inline TestSetup::run (TestResult *result)
-{ setUp (); TestDecorator::run (result); tearDown (); }
+inline void
+TestSetUp::run (TestResult *result)
+{
+ setUp ();
+ TestDecorator::run (result);
+ tearDown ();
+}
} // namespace CppUnit
diff --git a/include/cppunit/extensions/TestSuiteBuilder.h b/include/cppunit/extensions/TestSuiteBuilder.h
index 8536f1c..15a7078 100644
--- a/include/cppunit/extensions/TestSuiteBuilder.h
+++ b/include/cppunit/extensions/TestSuiteBuilder.h
@@ -49,14 +49,32 @@ namespace CppUnit {
m_suite->addTest( test );
}
- void addTestCaller( std::string name, TestMethod testMethod )
+ void addTestCaller( std::string methodName,
+ TestMethod testMethod )
{
Test *test =
- new TestCaller<Fixture>( m_suite->getName() + "." + name,
+ new TestCaller<Fixture>( makeTestName( methodName ),
testMethod );
addTest( test );
}
+ void addTestCaller( std::string methodName,
+ TestMethod testMethod,
+ Fixture *fixture )
+ {
+ Test *test =
+ new TestCaller<Fixture>( makeTestName( methodName ),
+ testMethod,
+ fixture);
+ addTest( test );
+ }
+
+ protected:
+ std::string makeTestName( const std::string &methodName )
+ {
+ return m_suite->getName() + "." + methodName;
+ }
+
private:
std::auto_ptr<TestSuite> m_suite;
};