tst_RunExtensions: Move onResultReady test into tst_AsyncTask

Change-Id: I73e2cc62be207adbfb2a4e4ce1367140986cc8b3
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2023-04-06 18:55:16 +02:00
parent 962888cb02
commit 837967a77a
2 changed files with 60 additions and 61 deletions

View File

@@ -1,7 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd. // Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <utils/asynctask.h>
#include <utils/runextensions.h> #include <utils/runextensions.h>
#include <QtTest> #include <QtTest>
@@ -23,7 +22,6 @@ private slots:
void threadPriority(); void threadPriority();
void runAsyncNoFutureInterface(); void runAsyncNoFutureInterface();
void crefFunction(); void crefFunction();
void onResultReady();
}; };
void report3(QFutureInterface<int> &fi) void report3(QFutureInterface<int> &fi)
@@ -537,65 +535,6 @@ void tst_RunExtensions::crefFunction()
QCOMPARE(value, true); QCOMPARE(value, true);
} }
class ObjWithProperty : public QObject
{
Q_OBJECT
public slots:
void setValue(const QString &s)
{
value = s;
}
public:
QString value;
};
void tst_RunExtensions::onResultReady()
{
{ // lambda
QObject context;
QFuture<QString> f = Utils::runAsync([](QFutureInterface<QString> &fi) {
fi.reportResult("Hi");
fi.reportResult("there");
});
int count = 0;
QString res;
Utils::onResultReady(f, &context, [&count, &res](const QString &s) {
++count;
res = s;
});
f.waitForFinished();
QCoreApplication::processEvents();
QCOMPARE(count, 2);
QCOMPARE(res, QString("there"));
}
{ // lambda with guard
QFuture<QString> f = Utils::runAsync([](QFutureInterface<QString> &fi) {
fi.reportResult("Hi");
fi.reportResult("there");
});
int count = 0;
ObjWithProperty obj;
Utils::onResultReady(f, &obj, [&count, &obj](const QString &s) {
++count;
obj.setValue(s);
});
f.waitForFinished();
QCoreApplication::processEvents();
QCOMPARE(count, 2);
QCOMPARE(obj.value, QString("there"));
}
{ // member
QFuture<QString> f = Utils::runAsync([]() { return QString("Hi"); });
ObjWithProperty obj;
Utils::onResultReady(f, &obj, &ObjWithProperty::setValue);
f.waitForFinished();
QCoreApplication::processEvents();
QCOMPARE(obj.value, QString("Hi"));
}
}
QTEST_GUILESS_MAIN(tst_RunExtensions) QTEST_GUILESS_MAIN(tst_RunExtensions)
#include "tst_runextensions.moc" #include "tst_runextensions.moc"

View File

@@ -15,6 +15,7 @@ class tst_AsyncTask : public QObject
private slots: private slots:
void runAsync(); void runAsync();
void crefFunction(); void crefFunction();
void onResultReady();
void futureSynchonizer(); void futureSynchonizer();
void taskTree(); void taskTree();
void mapReduce_data(); void mapReduce_data();
@@ -326,6 +327,65 @@ void tst_AsyncTask::crefFunction()
QList<double>({0, 2, 1})); QList<double>({0, 2, 1}));
} }
class ObjWithProperty : public QObject
{
Q_OBJECT
public slots:
void setValue(const QString &s)
{
value = s;
}
public:
QString value;
};
void tst_AsyncTask::onResultReady()
{
{ // lambda
QObject context;
QFuture<QString> f = Utils::asyncRun([](QPromise<QString> &fi) {
fi.addResult("Hi");
fi.addResult("there");
});
int count = 0;
QString res;
Utils::onResultReady(f, &context, [&count, &res](const QString &s) {
++count;
res = s;
});
f.waitForFinished();
QCoreApplication::processEvents();
QCOMPARE(count, 2);
QCOMPARE(res, QString("there"));
}
{ // lambda with guard
QFuture<QString> f = Utils::asyncRun([](QPromise<QString> &fi) {
fi.addResult("Hi");
fi.addResult("there");
});
int count = 0;
ObjWithProperty obj;
Utils::onResultReady(f, &obj, [&count, &obj](const QString &s) {
++count;
obj.setValue(s);
});
f.waitForFinished();
QCoreApplication::processEvents();
QCOMPARE(count, 2);
QCOMPARE(obj.value, QString("there"));
}
{ // member
QFuture<QString> f = Utils::asyncRun([] { return QString("Hi"); });
ObjWithProperty obj;
Utils::onResultReady(f, &obj, &ObjWithProperty::setValue);
f.waitForFinished();
QCoreApplication::processEvents();
QCOMPARE(obj.value, QString("Hi"));
}
}
void tst_AsyncTask::futureSynchonizer() void tst_AsyncTask::futureSynchonizer()
{ {
auto lambda = [](QPromise<int> &promise) { auto lambda = [](QPromise<int> &promise) {