From 177af4dd379ac52d3d5fc177cf91df0dafda6bf0 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Mon, 5 Jul 2021 23:59:30 +0200 Subject: Add unit test for QXmppDiscoveryManager --- tests/CMakeLists.txt | 1 + .../tst_qxmppdiscoverymanager.cpp | 91 ++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/qxmppdiscoverymanager/tst_qxmppdiscoverymanager.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 10f07464..3e61c7f5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -23,6 +23,7 @@ add_simple_test(qxmppcarbonmanager) add_simple_test(qxmppclient) add_simple_test(qxmppdataform) add_simple_test(qxmppdiscoveryiq) +add_simple_test(qxmppdiscoverymanager TestClient.h) add_simple_test(qxmppentitytimeiq) add_simple_test(qxmpphttpuploadiq) add_simple_test(qxmppiceconnection) diff --git a/tests/qxmppdiscoverymanager/tst_qxmppdiscoverymanager.cpp b/tests/qxmppdiscoverymanager/tst_qxmppdiscoverymanager.cpp new file mode 100644 index 00000000..43dfd836 --- /dev/null +++ b/tests/qxmppdiscoverymanager/tst_qxmppdiscoverymanager.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2008-2021 The QXmpp developers + * + * Author: + * Linus Jahn + * + * Source: + * https://github.com/qxmpp-project/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#include "QXmppDiscoveryManager.h" + +#include "TestClient.h" + +class tst_QXmppDiscoveryManager : public QObject +{ + Q_OBJECT +private: + Q_SLOT void testInfo(); + Q_SLOT void testItems(); +}; + +void tst_QXmppDiscoveryManager::testInfo() +{ + TestClient test; + auto *discoManager = test.addNewExtension(); + + auto future = discoManager->requestDiscoInfo("user@example.org"); + test.expect(""); + test.inject(R"( + + + + + + +)"); + + const auto info = expectFutureVariant(future); + + const QStringList expFeatures = { "http://jabber.org/protocol/pubsub", "urn:xmpp:mix:core:1" }; + QCOMPARE(info.features(), expFeatures); + QCOMPARE(info.identities().count(), 1); +} + +void tst_QXmppDiscoveryManager::testItems() +{ + TestClient test; + auto *discoManager = test.addNewExtension(); + + auto future = discoManager->requestDiscoItems("user@example.org"); + test.expect(""); + qDebug() << "Moin"; + test.inject(R"( + + + + + + + +)"); + + const auto items = expectFutureVariant>(future); + + const QStringList expFeatures = { "http://jabber.org/protocol/pubsub", "urn:xmpp:mix:core:1" }; + QCOMPARE(items.size(), 4); + QCOMPARE(items.at(0).name(), QStringLiteral("368866411b877c30064a5f62b917cffe")); + QCOMPARE(items.at(1).name(), QStringLiteral("3300659945416e274474e469a1f0154c")); + QCOMPARE(items.at(2).name(), QStringLiteral("4e30f35051b7b8b42abe083742187228")); + QCOMPARE(items.at(3).name(), QStringLiteral("ae890ac52d0df67ed7cfdf51b644e901")); +} + +QTEST_MAIN(tst_QXmppDiscoveryManager) + +#include "tst_qxmppdiscoverymanager.moc" -- cgit v1.2.3