From 4428fdaa961fc8a44126e20887b8ca144503b27d Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Fri, 9 Sep 2022 19:24:19 +0200 Subject: 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. --- tests/util.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') 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 &future) return expectVariant(future.result()); } +template +T wait(const QFuture &future) +{ + auto watcher = std::make_unique>(); + QSignalSpy spy(watcher.get(), &QFutureWatcherBase::finished); + watcher->setFuture(future); + spy.wait(); + if constexpr (!std::is_same_v) { + return future.result(); + } +} + class TestPasswordChecker : public QXmppPasswordChecker { public: -- cgit v1.2.3