summaryrefslogtreecommitdiff
path: root/include/cppunit
diff options
context:
space:
mode:
authorBastiaan Bakker <bastiaan.bakker@lifeline.nl>2001-05-06 19:04:02 +0000
committerBastiaan Bakker <bastiaan.bakker@lifeline.nl>2001-05-06 19:04:02 +0000
commit90296fa9c8fdedb9104faba5a8bac62210a9a80d (patch)
treeb455e31a182bd41b9d28b55c6ef6cffc429423ef /include/cppunit
parent58bffb0f4dafa3f2457ef65cec4546fbf6ff3428 (diff)
downloadcppunit-90296fa9c8fdedb9104faba5a8bac62210a9a80d.tar.gz
Added constructors to TestCaller which accept an already constucted Fixture.
Diffstat (limited to 'include/cppunit')
-rw-r--r--include/cppunit/TestCaller.h74
-rw-r--r--include/cppunit/extensions/TestSuiteBuilder.h7
2 files changed, 59 insertions, 22 deletions
diff --git a/include/cppunit/TestCaller.h b/include/cppunit/TestCaller.h
index 9262b86..f71734e 100644
--- a/include/cppunit/TestCaller.h
+++ b/include/cppunit/TestCaller.h
@@ -1,7 +1,6 @@
#ifndef CPPUNIT_TESTCALLER_H
#define CPPUNIT_TESTCALLER_H
-#include <memory>
#include <cppunit/TestCase.h>
namespace CppUnit {
@@ -36,7 +35,6 @@ namespace CppUnit {
*
* You can use a TestCaller to bind any test method on a TestCase
* class, as long as it accepts void and returns void.
- * TestCallers are automatically registered in the TestRegistry.
*
* \see TestCase
*/
@@ -47,26 +45,74 @@ namespace CppUnit {
typedef void (Fixture::*TestMethod)();
public:
+ /**
+ * Constructor for TestCaller. This constructor builds a new Fixture
+ * instance owned by the TestCaller.
+ * \param name name of this TestCaller
+ * \param test the method this TestCaller calls in runTest()
+ **/
TestCaller (std::string name, TestMethod test) :
TestCase (name),
- m_fixture (new Fixture ()),
+ m_ownFixture(true),
+ m_fixture (new Fixture ()),
m_test (test)
{}
+ /**
+ * Constructor for TestCaller.
+ * This constructor does not create a new Fixture instance but accepts
+ * an existing one as parameter. The TestCaller will not own the
+ * Fixture object.
+ * \param name name of this TestCaller
+ * \param test the method this TestCaller calls in runTest()
+ * \param fixture the Fixture to invoke the test method on.
+ **/
+ TestCaller(std::string name, TestMethod test, Fixture& fixture) :
+ TestCase (name),
+ m_ownFixture(false),
+ m_fixture (&fixture),
+ m_test (test)
+ {}
+
+ /**
+ * Constructor for TestCaller.
+ * This constructor does not create a new Fixture instance but accepts
+ * an existing one as parameter. The TestCaller will own the
+ * Fixture object and delete it in its destructor.
+ * \param name name of this TestCaller
+ * \param test the method this TestCaller calls in runTest()
+ * \param fixture the Fixture to invoke the test method on.
+ **/
+ TestCaller(std::string name, TestMethod test, Fixture* fixture) :
+ TestCase (name),
+ m_ownFixture(true),
+ m_fixture (fixture),
+ m_test (test)
+ {}
+
+ ~TestCaller() {
+ if (m_ownFixture) {
+ if (m_fixture) {
+ delete m_fixture;
+ m_fixture = NULL;
+ }
+ }
+ }
+
protected:
void runTest ()
{
- (m_fixture.get ()->*m_test)();
+ (m_fixture->*m_test)();
}
void setUp ()
{
- m_fixture.get ()->setUp ();
+ m_fixture->setUp ();
}
void tearDown ()
{
- m_fixture.get ()->tearDown ();
+ m_fixture->tearDown ();
}
std::string toString () const
@@ -79,22 +125,12 @@ namespace CppUnit {
TestCaller& operator= (const TestCaller& other);
private:
- std::auto_ptr<Fixture> m_fixture;
- TestMethod m_test;
+ bool m_ownFixture;
+ Fixture* m_fixture;
+ TestMethod m_test;
};
- /** Returns a TestCaller for the specified method.
- * \param name Name for the TestCaller.
- * \param testMethod Method called by the TestCaller.
- * \return TestCaller for the specified method.
- */
- template<typename Fixture>
- Test *makeTestCaller( std::string name, void (Fixture::*testMethod)() )
- {
- return new TestCaller<Fixture>( name, testMethod );
- }
-
} // namespace CppUnit
#endif // CPPUNIT_TESTCALLER_H
diff --git a/include/cppunit/extensions/TestSuiteBuilder.h b/include/cppunit/extensions/TestSuiteBuilder.h
index d85683d..ab553e9 100644
--- a/include/cppunit/extensions/TestSuiteBuilder.h
+++ b/include/cppunit/extensions/TestSuiteBuilder.h
@@ -38,9 +38,10 @@ namespace CppUnit {
void addTestCaller( std::string name, TestMethod testMethod )
{
- Test *test = makeTestCaller( m_suite->getName() + "." + name,
- testMethod );
- addTest( test );
+ Test *test =
+ new TestCaller<Fixture>( m_suite->getName() + "." + name,
+ testMethod );
+ addTest( test );
}
private: