aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2022-09-09 19:24:19 +0200
committerLinus Jahn <lnj@kaidan.im>2022-09-09 22:49:06 +0200
commit4428fdaa961fc8a44126e20887b8ca144503b27d (patch)
treeb4ed58fd2699e1955f523ce6cc669896e5b52a20 /tests
parent668447ddc8d7cca55516b569e45adb64b19ec6c4 (diff)
downloadqxmpp-4428fdaa961fc8a44126e20887b8ca144503b27d.tar.gz
tests: util: Add wait(QFuture) function
The function uses a QSignalSpy and a QFutureWatcher to wait for the future's result. It blocks until the result is there. However it still runs the event loop, so processing of the future can be done in the background.
Diffstat (limited to 'tests')
-rw-r--r--tests/util.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/util.h b/tests/util.h
index 51aac3f8..34cd0d6e 100644
--- a/tests/util.h
+++ b/tests/util.h
@@ -94,6 +94,18 @@ T expectFutureVariant(const QFuture<Input> &future)
return expectVariant<T>(future.result());
}
+template<typename T>
+T wait(const QFuture<T> &future)
+{
+ auto watcher = std::make_unique<QFutureWatcher<T>>();
+ QSignalSpy spy(watcher.get(), &QFutureWatcherBase::finished);
+ watcher->setFuture(future);
+ spy.wait();
+ if constexpr (!std::is_same_v<T, void>) {
+ return future.result();
+ }
+}
+
class TestPasswordChecker : public QXmppPasswordChecker
{
public: