63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
#include "TestHarness.h"
|
|
|
|
#include <QCoreApplication>
|
|
#include <QStandardPaths>
|
|
#include <QTextStream>
|
|
|
|
#include <exception>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QStandardPaths::setTestModeEnabled(true);
|
|
QCoreApplication application(argc, argv);
|
|
QCoreApplication::setOrganizationName(QStringLiteral("QtDesktopPetInternalQA"));
|
|
QCoreApplication::setApplicationName(QStringLiteral("CoreLogicTests"));
|
|
|
|
QTextStream output(stdout);
|
|
QTextStream errors(stderr);
|
|
QString filter;
|
|
for (int index = 1; index < argc; ++index)
|
|
{
|
|
const QString argument = QString::fromLocal8Bit(argv[index]);
|
|
if (argument.startsWith(QStringLiteral("--filter=")))
|
|
{
|
|
filter = argument.mid(QStringLiteral("--filter=").size()).trimmed();
|
|
}
|
|
}
|
|
|
|
int failedCount = 0;
|
|
int executedCount = 0;
|
|
|
|
for (const Qa::TestCase &test : Qa::registry())
|
|
{
|
|
const QString testName = QString::fromStdString(test.name);
|
|
if (!filter.isEmpty() && !testName.contains(filter, Qt::CaseInsensitive))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
++executedCount;
|
|
try
|
|
{
|
|
test.function();
|
|
output << "[PASS] " << testName << Qt::endl;
|
|
}
|
|
catch (const std::exception &exception)
|
|
{
|
|
++failedCount;
|
|
errors << "[FAIL] " << QString::fromStdString(test.name)
|
|
<< ": " << exception.what() << Qt::endl;
|
|
}
|
|
catch (...)
|
|
{
|
|
++failedCount;
|
|
errors << "[FAIL] " << QString::fromStdString(test.name)
|
|
<< ": unknown exception" << Qt::endl;
|
|
}
|
|
}
|
|
|
|
output << "Executed " << executedCount << " tests; "
|
|
<< failedCount << " failed." << Qt::endl;
|
|
return failedCount == 0 ? 0 : 1;
|
|
}
|