#ifndef TESTUTILS_CPPUNIT_H #define TESTUTILS_CPPUNIT_H #include "./testutils.h" #include #include #include #include using namespace std; using namespace CppUtilities; using namespace CPPUNIT_NS; /*! * \brief Performs unit tests using cppunit. */ int main(int argc, char **argv) { TestApplication testApp(argc, argv); 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.\n"; } } } const auto ok = runner.run(string(), false); cerr << (ok ? "Tests successful\n" : "Tests failed\n"); return !ok; } #endif // TESTUTILS_CPPUNIT_H