void filterPattern(const std::vector<CppUnit::Test*> &from, std::vector<CppUnit::Test*> &to, QString pattern, bool includeOnMatch) { QRegExp regex(pattern); for (size_t i = 0; i < from.size(); i++) { CppUnit::Test* child = from[i]; QString name = QString::fromStdString(child->getName()); if (regex.exactMatch(name) == includeOnMatch) to.push_back(child); } }
int main(int argc, char** argv) { // Get the top level suite from the registry CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); // Adds the test to the list of test to run CppUnit::TextUi::TestRunner runner; runner.addTest( suite ); #ifndef TESTNAME std::ofstream outputFile(std::string(suite->getName()+"-result.xml").c_str()); #else std::ofstream outputFile((std::string(TESTNAME)+std::string("-result.xml")).c_str()); #endif // Change the default outputter to a compiler error format outputter runner.setOutputter( new CppUnit::XmlOutputter( &runner.result(),outputFile ) ); // Run the tests. bool wasSucessful = runner.run(); outputFile.close(); // Return error code 1 if the one of test failed. return wasSucessful ? 0 : 1; }