diff options
| author | Linus Jahn <lnj@kaidan.im> | 2022-09-09 19:24:19 +0200 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2022-09-09 22:49:06 +0200 |
| commit | 4428fdaa961fc8a44126e20887b8ca144503b27d (patch) | |
| tree | b4ed58fd2699e1955f523ce6cc669896e5b52a20 /tests | |
| parent | 668447ddc8d7cca55516b569e45adb64b19ec6c4 (diff) | |
| download | qxmpp-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.h | 12 |
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: |
