forked from qt-creator/qt-creator
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:
@@ -1,7 +1,6 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// 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 <QtTest>
|
||||
@@ -23,7 +22,6 @@ private slots:
|
||||
void threadPriority();
|
||||
void runAsyncNoFutureInterface();
|
||||
void crefFunction();
|
||||
void onResultReady();
|
||||
};
|
||||
|
||||
void report3(QFutureInterface<int> &fi)
|
||||
@@ -537,65 +535,6 @@ void tst_RunExtensions::crefFunction()
|
||||
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)
|
||||
|
||||
#include "tst_runextensions.moc"
|
||||
|
@@ -15,6 +15,7 @@ class tst_AsyncTask : public QObject
|
||||
private slots:
|
||||
void runAsync();
|
||||
void crefFunction();
|
||||
void onResultReady();
|
||||
void futureSynchonizer();
|
||||
void taskTree();
|
||||
void mapReduce_data();
|
||||
@@ -326,6 +327,65 @@ void tst_AsyncTask::crefFunction()
|
||||
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()
|
||||
{
|
||||
auto lambda = [](QPromise<int> &promise) {
|
||||
|
Reference in New Issue
Block a user