diff --git a/tests/auto/runextensions/tst_runextensions.cpp b/tests/auto/runextensions/tst_runextensions.cpp index 16f5642c942..4ffee270025 100644 --- a/tests/auto/runextensions/tst_runextensions.cpp +++ b/tests/auto/runextensions/tst_runextensions.cpp @@ -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 #include #include @@ -23,7 +22,6 @@ private slots: void threadPriority(); void runAsyncNoFutureInterface(); void crefFunction(); - void onResultReady(); }; void report3(QFutureInterface &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 f = Utils::runAsync([](QFutureInterface &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 f = Utils::runAsync([](QFutureInterface &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 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" diff --git a/tests/auto/utils/asynctask/tst_asynctask.cpp b/tests/auto/utils/asynctask/tst_asynctask.cpp index 67a291172a1..5118b5555af 100644 --- a/tests/auto/utils/asynctask/tst_asynctask.cpp +++ b/tests/auto/utils/asynctask/tst_asynctask.cpp @@ -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({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 f = Utils::asyncRun([](QPromise &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 f = Utils::asyncRun([](QPromise &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 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 &promise) {