forked from qt-creator/qt-creator
Async tests: Add tests taking static function
Change-Id: Id10b40c7d50c36b8e9406f1ae7ab8915c908212c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -33,12 +33,25 @@ void report3(QPromise<int> &promise)
|
|||||||
promise.addResult(1);
|
promise.addResult(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void staticReport3(QPromise<int> &promise)
|
||||||
|
{
|
||||||
|
promise.addResult(0);
|
||||||
|
promise.addResult(2);
|
||||||
|
promise.addResult(1);
|
||||||
|
}
|
||||||
|
|
||||||
void reportN(QPromise<double> &promise, int n)
|
void reportN(QPromise<double> &promise, int n)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < n; ++i)
|
for (int i = 0; i < n; ++i)
|
||||||
promise.addResult(0);
|
promise.addResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void staticReportN(QPromise<double> &promise, int n)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
promise.addResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
void reportString1(QPromise<QString> &promise, const QString &s)
|
void reportString1(QPromise<QString> &promise, const QString &s)
|
||||||
{
|
{
|
||||||
promise.addResult(s);
|
promise.addResult(s);
|
||||||
@@ -135,6 +148,24 @@ std::shared_ptr<Async<ResultType>> createAsyncTask(Function &&function, Args &&.
|
|||||||
|
|
||||||
void tst_Async::runAsync()
|
void tst_Async::runAsync()
|
||||||
{
|
{
|
||||||
|
// tesing QtConcurrent::run()
|
||||||
|
QCOMPARE(QtConcurrent::run(&report3).results(),
|
||||||
|
QList<int>({0, 2, 1}));
|
||||||
|
QCOMPARE(QtConcurrent::run(report3).results(),
|
||||||
|
QList<int>({0, 2, 1}));
|
||||||
|
QCOMPARE(QtConcurrent::run(&staticReport3).results(),
|
||||||
|
QList<int>({0, 2, 1}));
|
||||||
|
QCOMPARE(QtConcurrent::run(staticReport3).results(),
|
||||||
|
QList<int>({0, 2, 1}));
|
||||||
|
QCOMPARE(QtConcurrent::run(&reportN, 2).results(),
|
||||||
|
QList<double>({0, 0}));
|
||||||
|
QCOMPARE(QtConcurrent::run(reportN, 2).results(),
|
||||||
|
QList<double>({0, 0}));
|
||||||
|
QCOMPARE(QtConcurrent::run(&staticReportN, 2).results(),
|
||||||
|
QList<double>({0, 0}));
|
||||||
|
QCOMPARE(QtConcurrent::run(staticReportN, 2).results(),
|
||||||
|
QList<double>({0, 0}));
|
||||||
|
|
||||||
// free function pointer
|
// free function pointer
|
||||||
QCOMPARE(createAsyncTask(&report3)->results(),
|
QCOMPARE(createAsyncTask(&report3)->results(),
|
||||||
QList<int>({0, 2, 1}));
|
QList<int>({0, 2, 1}));
|
||||||
@@ -144,15 +175,31 @@ void tst_Async::runAsync()
|
|||||||
QList<int>({0, 2, 1}));
|
QList<int>({0, 2, 1}));
|
||||||
QCOMPARE(Utils::asyncRun(report3).results(),
|
QCOMPARE(Utils::asyncRun(report3).results(),
|
||||||
QList<int>({0, 2, 1}));
|
QList<int>({0, 2, 1}));
|
||||||
|
QCOMPARE(createAsyncTask(&staticReport3)->results(),
|
||||||
|
QList<int>({0, 2, 1}));
|
||||||
|
QCOMPARE(Utils::asyncRun(&staticReport3).results(),
|
||||||
|
QList<int>({0, 2, 1}));
|
||||||
|
QCOMPARE(createAsyncTask(staticReport3)->results(),
|
||||||
|
QList<int>({0, 2, 1}));
|
||||||
|
QCOMPARE(Utils::asyncRun(staticReport3).results(),
|
||||||
|
QList<int>({0, 2, 1}));
|
||||||
|
|
||||||
QCOMPARE(createAsyncTask(reportN, 4)->results(),
|
QCOMPARE(createAsyncTask(&reportN, 2)->results(),
|
||||||
QList<double>({0, 0, 0, 0}));
|
QList<double>({0, 0}));
|
||||||
QCOMPARE(Utils::asyncRun(reportN, 4).results(),
|
QCOMPARE(Utils::asyncRun(&reportN, 2).results(),
|
||||||
QList<double>({0, 0, 0, 0}));
|
QList<double>({0, 0}));
|
||||||
QCOMPARE(createAsyncTask(reportN, 2)->results(),
|
QCOMPARE(createAsyncTask(reportN, 2)->results(),
|
||||||
QList<double>({0, 0}));
|
QList<double>({0, 0}));
|
||||||
QCOMPARE(Utils::asyncRun(reportN, 2).results(),
|
QCOMPARE(Utils::asyncRun(reportN, 2).results(),
|
||||||
QList<double>({0, 0}));
|
QList<double>({0, 0}));
|
||||||
|
QCOMPARE(createAsyncTask(&staticReportN, 2)->results(),
|
||||||
|
QList<double>({0, 0}));
|
||||||
|
QCOMPARE(Utils::asyncRun(&staticReportN, 2).results(),
|
||||||
|
QList<double>({0, 0}));
|
||||||
|
QCOMPARE(createAsyncTask(staticReportN, 2)->results(),
|
||||||
|
QList<double>({0, 0}));
|
||||||
|
QCOMPARE(Utils::asyncRun(staticReportN, 2).results(),
|
||||||
|
QList<double>({0, 0}));
|
||||||
|
|
||||||
QString s = QLatin1String("string");
|
QString s = QLatin1String("string");
|
||||||
const QString &crs = QLatin1String("cr string");
|
const QString &crs = QLatin1String("cr string");
|
||||||
|
|||||||
Reference in New Issue
Block a user