diff options
| author | Linus Jahn <lnj@kaidan.im> | 2020-04-01 00:50:56 +0200 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2020-04-01 00:51:35 +0200 |
| commit | 624a919b371bd96f96ecfef0030a7bd58bc9b761 (patch) | |
| tree | 2c2b4dd422a7ae1ba83378f3c0df68de8411c86d /tests | |
| parent | 313ba92519363f1ce0c308778744f6739028586d (diff) | |
| download | qxmpp-624a919b371bd96f96ecfef0030a7bd58bc9b761.tar.gz | |
Add tests for QXmppRosterManager
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | tests/qxmpprostermanager/tst_qxmpprostermanager.cpp | 110 |
2 files changed, 111 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b1ee1e57..49d0e6b0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,6 +40,7 @@ add_simple_test(qxmppregisteriq) add_simple_test(qxmppregistrationmanager) add_simple_test(qxmppresultset) add_simple_test(qxmpprosteriq) +add_simple_test(qxmpprostermanager) add_simple_test(qxmpprpciq) add_simple_test(qxmpprtcppacket) add_simple_test(qxmpprtppacket) diff --git a/tests/qxmpprostermanager/tst_qxmpprostermanager.cpp b/tests/qxmpprostermanager/tst_qxmpprostermanager.cpp new file mode 100644 index 00000000..f8a62aa7 --- /dev/null +++ b/tests/qxmpprostermanager/tst_qxmpprostermanager.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2008-2020 The QXmpp developers + * + * Authors: + * Jeremy Lainé + * Manjeet Dahiya + * + * 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 "QXmppClient.h" +#include "QXmppDiscoveryManager.h" +#include "QXmppRosterManager.h" + +#include "util.h" + +class tst_QXmppRosterManager : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + + void testDiscoFeatures(); + void testRenameItem(); + +private: + QXmppClient client; + QXmppLogger logger; + QXmppRosterManager *manager; +}; + +void tst_QXmppRosterManager::initTestCase() +{ + logger.setLoggingType(QXmppLogger::SignalLogging); + client.setLogger(&logger); + + manager = client.findExtension<QXmppRosterManager>(); +} + +void tst_QXmppRosterManager::testDiscoFeatures() +{ + QCOMPARE(manager->discoveryFeatures(), QStringList()); +} + +void tst_QXmppRosterManager::testRenameItem() +{ + // used to clean up lambda signal connections + QObject context; + + auto createItem = [](const QString &jid, const QString &ask = {}) -> QXmppRosterIq::Item { + QXmppRosterIq::Item item; + item.setBareJid(jid); + item.setSubscriptionStatus(ask); + return item; + }; + + // fill roster with initial contacts to rename + QXmppRosterIq initialItems; + initialItems.setType(QXmppIq::Result); + initialItems.addItem(createItem("stpeter@jabber.org")); + initialItems.addItem(createItem("bob@qxmpp.org")); + + QVERIFY(manager->handleStanza(writePacketToDom(initialItems))); + + // set a subscription state for bob (the subscription state MUST NOT be + // sent when renaming an item, so we need to check that it's not) + QXmppRosterIq bobAsk; + bobAsk.setType(QXmppIq::Set); + bobAsk.addItem(createItem("bob@qxmpp.org", "subscribe")); + + QVERIFY(manager->handleStanza(writePacketToDom(bobAsk))); + QCOMPARE(manager->getRosterEntry("bob@qxmpp.org").subscriptionStatus(), "subscribe"); + + // rename bob + bool requestSent = false; + connect(&logger, &QXmppLogger::message, &context, [&](QXmppLogger::MessageType type, const QString &text) { + if (type == QXmppLogger::SentMessage) { + requestSent = true; + + QXmppRosterIq renameRequest; + parsePacket(renameRequest, text.toUtf8()); + QCOMPARE(renameRequest.items().size(), 1); + QCOMPARE(renameRequest.items().first().bareJid(), "bob@qxmpp.org"); + QCOMPARE(renameRequest.items().first().name(), "Bob"); + // check that subscription state ('ask') for bob is not included + QVERIFY(renameRequest.items().first().subscriptionStatus().isNull()); + } + }); + + manager->renameItem("bob@qxmpp.org", "Bob"); + QVERIFY(requestSent); +} + +QTEST_MAIN(tst_QXmppRosterManager) +#include "tst_qxmpprostermanager.moc" |
