File: TestUtils.h

package info (click to toggle)
kaidan 0.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 9,376 kB
  • sloc: cpp: 30,143; xml: 1,623; sh: 522; python: 34; makefile: 5
file content (33 lines) | stat: -rw-r--r-- 716 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-FileCopyrightText: 2022 Linus Jahn <lnj@kaidan.im>
//
// SPDX-License-Identifier: GPL-3.0-or-later OR LGPL-2.1-or-later

#pragma once

// std
#include <memory>
// Qt
#include <QFuture>
#include <QFutureWatcher>
#include <QSignalSpy>
#include <QTest>
// QXmpp
#include <QXmppTask.h>

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();
    }
}

template<typename T>
T wait(QObject *context, QXmppTask<T> task)
{
    return wait(task.toFuture(context));
}