summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2021-08-17 16:00:26 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2021-08-18 09:41:55 +0200
commit642b9fce81b46e23b35b17e8284bd81bdba57fdd (patch)
tree22c5f33e691bbbe6289acde7bbbc6b9f3191c09c /tests/auto
parentc4ac9e74c79ebba3493ce29b25623b8c39b021a4 (diff)
QtConcurrent::run: support non default-constructible return types
The QtConcurrent::RunFunctionTask class keeps a variable to store the result of QtConcurrent::run when it becomes available, so that it can be reported afterwards. This requires the result type to be default-constructible. However there's no need in storing the result, it can be reported immediately after it becomes available. Pick-to: 6.1 6.2 Fixes: QTBUG-95214 Change-Id: I95f3dbff0ab41eaa81b104a8834b37d10a0d193a Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp12
-rw-r--r--tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp8
2 files changed, 16 insertions, 4 deletions
diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp
index 1b0b9577cf..235ffca0fc 100644
--- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp
+++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp
@@ -64,6 +64,7 @@ private slots:
void moveOnlyType();
void crefFunction();
void customPromise();
+ void nonDefaultConstructibleValue();
};
void light()
@@ -1564,6 +1565,17 @@ void tst_QtConcurrentRun::customPromise()
QCOMPARE(p.future().progressMaximum(), 10);
}
+void tst_QtConcurrentRun::nonDefaultConstructibleValue()
+{
+ struct NonDefaultConstructible
+ {
+ explicit NonDefaultConstructible(int v) : value(v) { }
+ int value = 0;
+ };
+
+ auto future = QtConcurrent::run([] { return NonDefaultConstructible(42); });
+ QCOMPARE(future.result().value, 42);
+}
QTEST_MAIN(tst_QtConcurrentRun)
#include "tst_qtconcurrentrun.moc"
diff --git a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp
index 929047c07e..33ecfb9cab 100644
--- a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp
+++ b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp
@@ -229,12 +229,12 @@ void tst_QFutureWatcher::canceled()
future.waitForFinished();
}
-class IntTask : public RunFunctionTask<int>
+class IntTask : public RunFunctionTaskBase<int>
{
public:
void runFunctor() override
{
- result = 10;
+ promise.reportResult(10);
}
};
@@ -463,7 +463,7 @@ void tst_QFutureWatcher::disconnectRunningFuture()
}
const int maxProgress = 100000;
-class ProgressEmitterTask : public RunFunctionTask<void>
+class ProgressEmitterTask : public RunFunctionTaskBase<void>
{
public:
void runFunctor() override
@@ -493,7 +493,7 @@ void tst_QFutureWatcher::tooMuchProgress()
}
template <typename T>
-class ProgressTextTask : public RunFunctionTask<T>
+class ProgressTextTask : public RunFunctionTaskBase<T>
{
public:
void runFunctor() override