aboutsummaryrefslogtreecommitdiff
path: root/tests/util.h
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2021-07-05 23:37:52 +0200
committerLinus Jahn <lnj@kaidan.im>2021-07-06 00:37:03 +0200
commit6b6fdfabb1ba8051f0a55e9e7bff123907253030 (patch)
tree5429461c7e1a0b1190772b6e5e4dbe79756f349c /tests/util.h
parentd3db0c7e5044dc4507c82ed8f371ca8c324ac639 (diff)
downloadqxmpp-6b6fdfabb1ba8051f0a55e9e7bff123907253030.tar.gz
tests: Add TestClient class for client testing with QFutures
Diffstat (limited to 'tests/util.h')
-rw-r--r--tests/util.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/util.h b/tests/util.h
index 7711518e..dc36e7af 100644
--- a/tests/util.h
+++ b/tests/util.h
@@ -23,8 +23,13 @@
*
*/
+#ifndef TESTS_UTIL_H
+#define TESTS_UTIL_H
+
#include "QXmppPasswordChecker.h"
+#include <variant>
+
#include <QDomDocument>
#include <QtTest>
@@ -33,7 +38,7 @@
if (!QTest::qVerify(statement, #statement, description, __FILE__, __LINE__)) \
return {};
-QDomElement xmlToDom(const QByteArray &xml)
+inline QDomElement xmlToDom(const QByteArray &xml)
{
QDomDocument doc;
QVERIFY_RV(doc.setContent(xml, true), "XML is not valid");
@@ -73,6 +78,17 @@ QDomElement writePacketToDom(T packet)
return doc.documentElement();
}
+template<typename T, typename Input>
+T expectFutureVariant(const QFuture<Input> &future)
+{
+#define return \
+ return { }
+ QVERIFY(future.isFinished());
+ QVERIFY2(std::holds_alternative<T>(future.result()), "Variant contains wrong type!");
+#undef return
+ return std::get<T>(future.result());
+}
+
class TestPasswordChecker : public QXmppPasswordChecker
{
public:
@@ -101,3 +117,5 @@ public:
private:
QMap<QString, QString> m_credentials;
};
+
+#endif // TESTS_UTIL_H