summaryrefslogtreecommitdiff
path: root/include/cppunit/TestCaller.h
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-12-16 13:50:27 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-12-16 14:05:07 +0100
commit923e2a837d515eb0d33792aba8bbb839f0012067 (patch)
tree9fd3a9d79939120aa63f391b0b1412ff4cc0efda /include/cppunit/TestCaller.h
parent25ccf3dd39c283c54313d8d26374e493e0e5f1a6 (diff)
downloadcppunit-923e2a837d515eb0d33792aba8bbb839f0012067.tar.gz
use std::function for the test method in TestCaller
This allows us to pass in any callable e.g. results of std::bind.
Diffstat (limited to 'include/cppunit/TestCaller.h')
-rw-r--r--include/cppunit/TestCaller.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/include/cppunit/TestCaller.h b/include/cppunit/TestCaller.h
index bbb9002..fbf3902 100644
--- a/include/cppunit/TestCaller.h
+++ b/include/cppunit/TestCaller.h
@@ -4,6 +4,8 @@
#include <cppunit/Exception.h>
#include <cppunit/TestCase.h>
+#include <functional>
+
#if defined(CPPUNIT_USE_TYPEINFO_NAME)
# include <cppunit/extensions/TypeInfoHelper.h>
@@ -116,7 +118,7 @@ public:
TestCase( name ),
m_ownFixture( true ),
m_fixture( new Fixture() ),
- m_test( test )
+ m_test_function( std::bind(test, m_fixture) )
{
}
@@ -133,7 +135,7 @@ public:
TestCase( name ),
m_ownFixture( false ),
m_fixture( &fixture ),
- m_test( test )
+ m_test_function( std::bind(test, &fixture) )
{
}
@@ -150,9 +152,17 @@ public:
TestCase( name ),
m_ownFixture( true ),
m_fixture( fixture ),
- m_test( test )
+ m_test_function( std::bind(test, fixture) )
{
}
+
+ TestCaller(std::string name, std::function<void()> test_function, Fixture* fixture):
+ TestCase(name),
+ m_ownFixture(true),
+ m_fixture(fixture),
+ m_test_function(test_function)
+ {
+ }
~TestCaller()
{
@@ -162,7 +172,7 @@ public:
void runTest()
{
- (m_fixture->*m_test)();
+ m_test_function();
}
void setUp()
@@ -187,7 +197,7 @@ private:
private:
bool m_ownFixture;
Fixture *m_fixture;
- TestMethod m_test;
+ std::function<void()> m_test_function;
};