2017-10-24 01:02:07 +02:00
|
|
|
#ifndef TESTUTILS_CPPUNIT_H
|
|
|
|
#define TESTUTILS_CPPUNIT_H
|
2016-02-06 02:52:06 +01:00
|
|
|
|
|
|
|
#include "./testutils.h"
|
|
|
|
|
2017-05-01 03:13:11 +02:00
|
|
|
#include <cppunit/TestPath.h>
|
2016-02-06 02:52:06 +01:00
|
|
|
#include <cppunit/extensions/TestFactoryRegistry.h>
|
|
|
|
#include <cppunit/ui/text/TestRunner.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace TestUtilities;
|
|
|
|
using namespace CPPUNIT_NS;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Performs unit tests using cppunit.
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
TestApplication testApp(argc, argv);
|
2017-10-24 01:02:07 +02:00
|
|
|
if (!testApp) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// run tests
|
|
|
|
TextUi::TestRunner runner;
|
|
|
|
TestFactoryRegistry ®istry = TestFactoryRegistry::getRegistry();
|
|
|
|
if (!testApp.unitsSpecified() || testApp.units().empty()) {
|
|
|
|
// no units specified -> test all
|
|
|
|
runner.addTest(registry.makeTest());
|
|
|
|
} else {
|
|
|
|
// pick specified units from overall test
|
|
|
|
Test *overallTest = registry.makeTest();
|
|
|
|
for (const char *unit : testApp.units()) {
|
|
|
|
try {
|
|
|
|
runner.addTest(overallTest->findTest(unit));
|
|
|
|
} catch (const invalid_argument &) {
|
|
|
|
cerr << "The specified test unit \"" << unit << "\" is not available and will be ignored." << endl;
|
2016-05-01 20:09:20 +02:00
|
|
|
}
|
|
|
|
}
|
2016-02-06 02:52:06 +01:00
|
|
|
}
|
2017-10-24 01:02:07 +02:00
|
|
|
return !runner.run(string(), false);
|
2016-02-06 02:52:06 +01:00
|
|
|
}
|
|
|
|
|
2017-10-24 01:02:07 +02:00
|
|
|
#endif // TESTUTILS_CPPUNIT_H
|