diff options
| author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2023-04-06 18:55:16 +0200 |
|---|---|---|
| committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2023-04-17 09:18:47 +0000 |
| commit | 837967a77a2cf2ba536c5bc06cff15644acc4425 (patch) | |
| tree | ecc1a9eee30f184e3c7b10366c233c86415341b7 /tests/auto | |
| parent | 962888cb02f0b851d6c9945f96f71298f1be7dda (diff) | |
| download | qt-creator-837967a77a2cf2ba536c5bc06cff15644acc4425.tar.gz | |
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>
Diffstat (limited to 'tests/auto')
| -rw-r--r-- | tests/auto/runextensions/tst_runextensions.cpp | 61 | ||||
| -rw-r--r-- | tests/auto/utils/asynctask/tst_asynctask.cpp | 60 |
2 files changed, 60 insertions, 61 deletions
diff --git a/tests/auto/runextensions/tst_runextensions.cpp b/tests/auto/runextensions/tst_runextensions.cpp index 16f5642c94..4ffee27002 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 <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" diff --git a/tests/auto/utils/asynctask/tst_asynctask.cpp b/tests/auto/utils/asynctask/tst_asynctask.cpp index 67a291172a..5118b5555a 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<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) { |
