1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-31 18:07:14 +01:00
Sandu Liviu Catalin 4a6bfc086c Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
2021-01-30 08:51:39 +02:00

104 lines
2.1 KiB
C++

//
// TestCaller.h
//
#ifndef CppUnit_TestCaller_INCLUDED
#define CppUnit_TestCaller_INCLUDED
#include "CppUnit/CppUnit.h"
#include "Guards.h"
#include "TestCase.h"
#include <memory>
namespace CppUnit {
/*
* A test caller provides access to a test case method
* on a test case class. Test callers are useful when
* you want to run an individual test or add it to a
* suite.
*
* Here is an example:
*
* class MathTest : public TestCase {
* ...
* public:
* void setUp ();
* void tearDown ();
*
* void testAdd ();
* void testSubtract ();
* };
*
* Test *MathTest::suite () {
* TestSuite *suite = new TestSuite;
*
* suite->addTest (new TestCaller<MathTest> ("testAdd", testAdd));
* return suite;
* }
*
* You can use a TestCaller to bind any test method on a TestCase
* class, as long as it returns accepts void and returns void.
*
* See TestCase
*/
template <class Fixture>
class TestCaller: public TestCase
{
REFERENCEOBJECT (TestCaller)
typedef void (Fixture::*TestMethod)();
public:
TestCaller(const std::string& name, TestMethod test, Test::Type testType = Test::Normal):
TestCase(name, testType),
_test(test),
_fixture(new Fixture(name))
{
}
protected:
void runTest()
{
(_fixture.get()->*_test)();
}
void setUp()
{
if (!setup().empty())
_fixture.get()->addSetup(setup());
_fixture.get()->setUp();
}
void tearDown()
{
_fixture.get()->tearDown();
}
private:
TestMethod _test;
std::unique_ptr<Fixture> _fixture;
};
} // namespace CppUnit
#define CppUnit_addTest(suite, cls, mth) \
suite->addTest(new CppUnit::TestCaller<cls>(#mth, &cls::mth))
#define CppUnit_addLongTest(suite, cls, mth) \
suite->addTest(new CppUnit::TestCaller<cls>(#mth, &cls::mth, CppUnit::Test::Long))
#define CppUnit_addQualifiedTest(suite, cls, mth) \
suite->addTest(new CppUnit::TestCaller<cls>(#cls"::"#mth, &cls::mth))
#define CppUnit_addLongQualifiedTest(suite, cls, mth) \
suite->addTest(new CppUnit::TestCaller<cls>(#cls"::"#mth, &cls::mth, CppUnit::Test::Long))
#endif // CppUnit_TestCaller_INCLUDED