From e1a904a51fbe4bb9df9eeaa5b9d1048cfdd1befb Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sun, 5 Jul 2020 01:32:39 +0200 Subject: tests: Add tests for QXmppPubSubManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Germán Márquez Mejía --- tests/CMakeLists.txt | 1 + .../qxmpppubsubmanager/tst_qxmpppubsubmanager.cpp | 860 +++++++++++++++++++++ 2 files changed, 861 insertions(+) create mode 100644 tests/qxmpppubsubmanager/tst_qxmpppubsubmanager.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bad03081..0b7efc43 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -43,6 +43,7 @@ add_simple_test(qxmpppubsub) add_simple_test(qxmpppubsubevent) add_simple_test(qxmpppubsubforms) add_simple_test(qxmpppubsubiq) +add_simple_test(qxmpppubsubmanager TestClient.h) add_simple_test(qxmppregisteriq) add_simple_test(qxmppregistrationmanager) add_simple_test(qxmppresultset) diff --git a/tests/qxmpppubsubmanager/tst_qxmpppubsubmanager.cpp b/tests/qxmpppubsubmanager/tst_qxmpppubsubmanager.cpp new file mode 100644 index 00000000..efe3b865 --- /dev/null +++ b/tests/qxmpppubsubmanager/tst_qxmpppubsubmanager.cpp @@ -0,0 +1,860 @@ +/* + * Copyright (C) 2008-2020 The QXmpp developers + * + * Authors: + * Linus Jahn + * Germán Márquez Mejía + * + * 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 "QXmppMessage.h" +#include "QXmppPubSubAffiliation.h" +#include "QXmppPubSubEventManager.h" +#include "QXmppPubSubIq.h" +#include "QXmppPubSubItem.h" +#include "QXmppPubSubManager.h" +#include "QXmppPubSubPublishOptions.h" +#include "QXmppPubSubSubscribeOptions.h" +#include "QXmppTuneItem.h" + +#include "TestClient.h" +#include "util.h" +#include + +Q_DECLARE_METATYPE(QXmppPubSubIq<>); +Q_DECLARE_METATYPE(std::optional); + +using PSManager = QXmppPubSubManager; +using Affiliation = QXmppPubSubAffiliation; +using AffiliationType = QXmppPubSubAffiliation::Affiliation; + +class TestEventManager : public QXmppPubSubEventManager +{ +public: + QXmppPubSubManager *pubSub() + { + return QXmppPubSubEventManager::pubSub(); + } + + bool handlePubSubEvent(const QDomElement &, const QString &pubSubService, const QString &nodeName) override + { + m_events++; +#define return return false; + QCOMPARE(pubSubService, m_serviceJid); + QCOMPARE(nodeName, m_node); +#undef return + return true; + } + + QString m_serviceJid; + QString m_node; + uint m_events = 0; +}; + +class tst_QXmppPubSubManager : public QObject +{ + Q_OBJECT + +private: + Q_SLOT void testDiscoFeatures(); + Q_SLOT void testFetchNodes(); + Q_SLOT void testCreateNodes_data(); + Q_SLOT void testCreateNodes(); + Q_SLOT void testCreateInstantNode(); + Q_SLOT void testDeleteNodes_data(); + Q_SLOT void testDeleteNodes(); + Q_SLOT void testPublishItems_data(); + Q_SLOT void testPublishItems(); + Q_SLOT void testRetractItem_data(); + Q_SLOT void testRetractItem(); + Q_SLOT void testPurgeItems(); + Q_SLOT void testPurgePepItems(); + Q_SLOT void testRequestItems_data(); + Q_SLOT void testRequestItems(); + Q_SLOT void testRequestItemNotFound(); + Q_SLOT void testRequestNodeAffiliations(); + Q_SLOT void testRequestAffiliations(); + Q_SLOT void testRequestAffiliationsNode(); + Q_SLOT void testRequestOptions(); + Q_SLOT void testRequestOptionsError(); + Q_SLOT void testSetOptions(); + Q_SLOT void testEventNotifications_data(); + Q_SLOT void testEventNotifications(); +}; + +void tst_QXmppPubSubManager::testDiscoFeatures() +{ + // so the coverage report is happy: + PSManager manager; + QCOMPARE(manager.discoveryFeatures(), QStringList {"http://jabber.org/protocol/pubsub#rsm"}); +} + +void tst_QXmppPubSubManager::testFetchNodes() +{ + TestClient test; + auto *psManager = test.addNewExtension(); + + auto future = psManager->fetchNodes("pepuser@qxmpp.org"); + test.expect(""); + test.inject(QStringLiteral("" + "" + "" + "" + "")); + + const auto nodes = expectFutureVariant>(future); + QCOMPARE(nodes, (QVector { "blogs", "news" })); +} + +void tst_QXmppPubSubManager::testCreateNodes_data() +{ + QTest::addColumn("isPep"); + QTest::addColumn("jid"); + QTest::addColumn("node"); + + QTest::addRow("createNode") + << false + << "pubsub.shakespeare.lit" + << "princely_musings"; + + QTest::addRow("createPepNode") + << true + << "juliet@capulet.lit" + << "urn:xmpp:omemo:1:bundles"; +} + +void tst_QXmppPubSubManager::testCreateNodes() +{ + QFETCH(bool, isPep); + QFETCH(QString, jid); + QFETCH(QString, node); + + TestClient test; + auto *psManager = test.addNewExtension(); + + QFuture future; + if (isPep) { + test.configuration().setJid(jid); + future = psManager->createPepNode(node); + } else { + future = psManager->createNode(jid, node); + } + + test.expect(QStringLiteral("").arg(jid, node)); + test.inject(""); + expectFutureVariant(future); +} + +void tst_QXmppPubSubManager::testCreateInstantNode() +{ + TestClient test; + auto *psManager = test.addNewExtension(); + + auto future = psManager->createInstantNode("pubsub.qxmpp.org"); + test.expect("" + ""); + test.inject(QStringLiteral("" + "" + "" + "")); + + const auto nodeId = expectFutureVariant(future); + QCOMPARE(nodeId, QString("25e3d37dabbab9541f7523321421edc5bfeb2dae")); +} + +void tst_QXmppPubSubManager::testDeleteNodes_data() +{ + QTest::addColumn("isPep"); + QTest::addColumn("jid"); + QTest::addColumn("node"); + + QTest::addRow("deleteNode") + << false + << "pubsub.shakespeare.lit" + << "princely_musings"; + + QTest::addRow("deletePepNode") + << true + << "juliet@capulet.lit" + << "urn:xmpp:omemo:1:bundles"; +} + +void tst_QXmppPubSubManager::testDeleteNodes() +{ + QFETCH(bool, isPep); + QFETCH(QString, jid); + QFETCH(QString, node); + + TestClient test; + auto *psManager = test.addNewExtension(); + + QFuture future; + if (isPep) { + test.configuration().setJid(jid); + future = psManager->deletePepNode(node); + } else { + future = psManager->deleteNode(jid, node); + } + + // FIXME: pubsub#owner here, but not for ? + test.expect(QStringLiteral("").arg(jid, node)); + test.inject(""); + expectFutureVariant(future); +} + +void tst_QXmppPubSubManager::testPublishItems_data() +{ + using OptionsOpt = std::optional; + QTest::addColumn("isPep"); + QTest::addColumn("jid"); + QTest::addColumn("node"); + QTest::addColumn>("items"); + QTest::addColumn("publishOptions"); + QTest::addColumn("returnIds"); + + QXmppTuneItem item1; + item1.setId("1234"); + item1.setTitle("Hello Goodbye"); + + QXmppTuneItem item2; + item2.setId("5678"); + item2.setArtist("Rick Astley"); + item2.setTitle("Never gonna give you up"); + + QVector items1 { item1 }; + QVector items2 { item1, item2 }; + + QXmppPubSubPublishOptions publishOptions; + publishOptions.setAccessModel(QXmppPubSubPublishOptions::Presence); + + auto addRow = [&](const char *name, bool isPep, QString &&jid, + QString &&node, const QVector &items) { + QTest::addRow("%s", name) << isPep << jid << node << items << OptionsOpt() << false; + QTest::addRow("%s%s", name, "ReturnIds") << isPep << jid << node << items << OptionsOpt() << true; + QTest::addRow("%s%s", name, "WithOptions") << isPep << jid << node << items << std::make_optional(publishOptions) << false; + QTest::addRow("%s%s%s", name, "WithOptions", "ReturnIds") << isPep << jid << node << items << std::make_optional(publishOptions) << true; + }; + + addRow("publishItem", false, "pubsub.shakespeare.lit", "princely_musings", items1); + addRow("publishItems", false, "pubsub.shakespeare.lit", "princely_musings", items2); + addRow("publishPepItem", true, "juliet@capulet.lit", "urn:xmpp:omemo:1:bundles", items1); + addRow("publishPepItems", true, "juliet@capulet.lit", "urn:xmpp:omemo:1:bundles", items2); +} + +void tst_QXmppPubSubManager::testPublishItems() +{ + QFETCH(bool, isPep); + QFETCH(QString, jid); + QFETCH(QString, node); + QFETCH(QVector, items); + QFETCH(std::optional, publishOptions); + QFETCH(bool, returnIds); + + const auto itemsXml = [=]() { + QBuffer buffer; + buffer.open(QIODevice::ReadWrite); + QXmlStreamWriter writer(&buffer); + for (const auto &item : items) { + item.toXml(&writer); + } + return buffer.data(); + }(); + const auto publishOptionsXml = [&]() -> QString { + if (publishOptions) { + return "" + QString::fromUtf8(packetToXml(publishOptions->toDataForm())) + ""; + } + return {}; + }(); + const auto itemIdsXml = [&]() { + QString result; + for (const auto &item : std::as_const(items)) { + result += ""; + } + return result; + }(); + const auto itemIds = [&]() { + QVector ids; + for (const auto &item : std::as_const(items)) { + ids << item.id(); + } + return ids; + }(); + + TestClient test; + if (isPep) { + test.configuration().setJid(jid); + } + auto *psManager = test.addNewExtension(); + + auto injectXml = [&]() { + test.expect(QStringLiteral("%3%4") + .arg(jid, node, itemsXml, publishOptionsXml)); + if (returnIds) { + test.inject(QStringLiteral(R"( + + + %3 + + )") + .arg(jid, node, itemIdsXml)); + } else { + test.inject(QStringLiteral("")); + } + }; + + if (items.size() == 1) { + QFuture future; + if (isPep) { + if (publishOptions) { + future = psManager->publishPepItem(node, items.constFirst(), *publishOptions); + } else { + future = psManager->publishPepItem(node, items.constFirst()); + } + } else { + if (publishOptions) { + future = psManager->publishItem(jid, node, items.constFirst(), *publishOptions); + } else { + future = psManager->publishItem(jid, node, items.constFirst()); + } + } + + injectXml(); + const auto id = expectFutureVariant(future); + if (returnIds) { + QCOMPARE(id, items.constFirst().id()); + } else { + QVERIFY(id.isNull()); + } + } else { + QFuture future; + if (isPep) { + if (publishOptions) { + future = psManager->publishPepItems(node, items, *publishOptions); + } else { + future = psManager->publishPepItems(node, items); + } + } else { + if (publishOptions) { + future = psManager->publishItems(jid, node, items, *publishOptions); + } else { + future = psManager->publishItems(jid, node, items); + } + } + + injectXml(); + const auto ids = expectFutureVariant>(future); + if (returnIds) { + QCOMPARE(ids, itemIds); + } else { + QVERIFY(ids.empty()); + } + } +} + +void tst_QXmppPubSubManager::testRetractItem_data() +{ + QTest::addColumn("isPep"); + QTest::addColumn("jid"); + QTest::addColumn("node"); + QTest::addColumn("itemId"); + + QTest::addRow("retractItem") + << false + << "pubsub.shakespeare.lit" + << "princely_musings" + << "ae890ac52d0df67ed7cfdf51b644e901"; + + QTest::addRow("retractPepItem") + << true + << "juliet@capulet.lit" + << "urn:xmpp:omemo:1:bundles" + << "31415"; +} + +void tst_QXmppPubSubManager::testRetractItem() +{ + QFETCH(bool, isPep); + QFETCH(QString, jid); + QFETCH(QString, node); + QFETCH(QString, itemId); + + TestClient test; + auto *psManager = test.addNewExtension(); + + QFuture future; + if (isPep) { + test.configuration().setJid(jid); + future = psManager->retractPepItem(node, itemId); + } else { + future = psManager->retractItem(jid, node, itemId); + } + + test.expect(QStringLiteral("") + .arg(jid, node, itemId)); + test.inject(QStringLiteral("") + .arg(jid)); + + expectFutureVariant(future); +} + +void tst_QXmppPubSubManager::testPurgeItems() +{ + TestClient test; + auto *psManager = test.addNewExtension(); + auto future = psManager->purgeItems("pubsub.qxmpp.org", "news"); + test.expect("" + "" + "" + ""); + test.inject(QStringLiteral("")); + expectFutureVariant(future); +} + +void tst_QXmppPubSubManager::testPurgePepItems() +{ + TestClient test; + test.configuration().setJid("user@qxmpp.org"); + auto *psManager = test.addNewExtension(); + auto future = psManager->purgePepItems("urn:xmpp:x-avatar:0"); + test.expect("" + "" + "" + ""); + test.inject(QStringLiteral("")); + expectFutureVariant(future); +} + +void tst_QXmppPubSubManager::testRequestItems_data() +{ + QTest::addColumn("jid"); + QTest::addColumn("node"); + QTest::addColumn("requestIds"); + QTest::addColumn("itemIds"); + + QTest::addRow("allItems-0") + << "pubsub.shakespeare.lit" + << "princely_musings" + << false + << QStringList(); + + QTest::addRow("allItems-1") + << "pubsub.shakespeare.lit" + << "princely_musings" + << false + << QStringList { "ae890ac52d0df67ed7cfdf51b644e901" }; + + QTest::addRow("allItems-2") + << "pubsub.shakespeare.lit" + << "princely_musings" + << false + << QStringList { "ae890ac52d0df67ed7cfdf51b644e901", "3300659945416e274474e469a1f0154c" }; + + QTest::addRow("oneItemById") + << "pubsub.shakespeare.lit" + << "princely_musings" + << true + << QStringList { "ae890ac52d0df67ed7cfdf51b644e901" }; + + QTest::addRow("twoItemsByIds") + << "pubsub.shakespeare.lit" + << "princely_musings" + << true + << QStringList { "ae890ac52d0df67ed7cfdf51b644e901", "3300659945416e274474e469a1f0154c" }; +} + +void tst_QXmppPubSubManager::testRequestItems() +{ + QFETCH(QString, jid); + QFETCH(QString, node); + QFETCH(bool, requestIds); + QFETCH(QStringList, itemIds); + + QString itemsReplyXml; + for (const auto &id : std::as_const(itemIds)) { + itemsReplyXml += QStringLiteral(R"( + + + Yes + 686 + 8 + Yessongs + Heart of the Sunrise + 3 + http://www.yesworld.com/lyrics/Fragile.html#9 + +)") + .arg(id); + } + + TestClient test; + auto *psManager = test.addNewExtension(); + QVector returnedItems; + + if (requestIds) { + QString itemsXml; + for (const auto &id : std::as_const(itemIds)) { + itemsXml += ""; + } + + if (itemIds.size() == 1) { + auto future = psManager->requestItem(jid, node, itemIds.constFirst()); + test.expect(QStringLiteral("" + "" + "%3" + "") + .arg(jid, node, itemsXml)); + test.inject(QStringLiteral("" + "" + "%3" + "") + .arg(jid, node, itemsReplyXml)); + + returnedItems = { expectFutureVariant(future) }; + } else { + auto future = psManager->requestItems(jid, node, itemIds); + test.expect(QStringLiteral("" + "" + "%3" + "") + .arg(jid, node, itemsXml)); + test.inject(QStringLiteral("" + "" + "%3" + "") + .arg(jid, node, itemsReplyXml)); + + returnedItems = expectFutureVariant>(future).items; + } + } else { + auto future = psManager->requestItems(jid, node); + test.expect(QStringLiteral("" + "" + "") + .arg(jid, node)); + test.inject(QStringLiteral("" + "" + "%3" + "") + .arg(jid, node, itemsReplyXml)); + + returnedItems = expectFutureVariant>(future).items; + } + + for (const auto &item : std::as_const(returnedItems)) { + QCOMPARE(item.artist(), QStringLiteral("Yes")); + QCOMPARE(item.length(), uint16_t(686)); + QCOMPARE(item.rating(), uint8_t(8)); + QCOMPARE(item.source(), QStringLiteral("Yessongs")); + QCOMPARE(item.title(), QStringLiteral("Heart of the Sunrise")); + QCOMPARE(item.track(), QLatin1String("3")); + QCOMPARE(item.uri(), QUrl("http://www.yesworld.com/lyrics/Fragile.html#9")); + } + + const auto itemsEqual = std::equal(returnedItems.cbegin(), returnedItems.cend(), + itemIds.cbegin(), itemIds.cend(), + [](const QXmppTuneItem &item, const QString &itemId) { + return item.id() == itemId; + }); + QVERIFY2(itemsEqual, "The items returned from the manager don't match the item IDs from the XML response"); +} + +void tst_QXmppPubSubManager::testRequestItemNotFound() +{ + TestClient test; + auto *psManager = test.addNewExtension(); + auto future = psManager->requestItem("pubsub.qxmpp.org", "features", "item1"); + test.expect(QStringLiteral("" + "" + "")); + test.inject(QStringLiteral("" + "" + "" + "")); + const auto error = expectFutureVariant(future); + QCOMPARE(error.type(), QXmppStanza::Error::Cancel); + QCOMPARE(error.condition(), QXmppStanza::Error::ItemNotFound); +} + +void tst_QXmppPubSubManager::testRequestNodeAffiliations() +{ + TestClient test; + auto *psManager = test.addNewExtension(); + auto future = psManager->requestNodeAffiliations("pubsub.qxmpp.org", "news"); + test.expect("" + "" + "" + ""); + test.inject(QStringLiteral("" + "" + "" + "" + "" + "")); + const auto affiliations = expectFutureVariant>(future); + + QCOMPARE(affiliations.size(), 2); + QCOMPARE(affiliations[0].node(), QString()); + QCOMPARE(affiliations[0].jid(), QString("hamlet@denmark.lit")); + QCOMPARE(affiliations[0].type(), AffiliationType::Owner); + QCOMPARE(affiliations[1].node(), QString()); + QCOMPARE(affiliations[1].jid(), QString("polonius@denmark.lit")); + QCOMPARE(affiliations[1].type(), AffiliationType::Outcast); +} + +void tst_QXmppPubSubManager::testRequestAffiliations() +{ + TestClient test; + auto *psManager = test.addNewExtension(); + auto future = psManager->requestAffiliations("pubsub.qxmpp.org"); + test.expect("" + ""); + test.inject(QStringLiteral("" + "" + "" + "" + "" + "" + "")); + + const auto affiliations = expectFutureVariant>(future); + QCOMPARE(affiliations.size(), 4); + QCOMPARE(affiliations[3].node(), QString("node6")); + QCOMPARE(affiliations[3].jid(), QString()); + QCOMPARE(affiliations[3].type(), AffiliationType::Owner); +} + +void tst_QXmppPubSubManager::testRequestAffiliationsNode() +{ + TestClient test; + auto *psManager = test.addNewExtension(); + auto future = psManager->requestAffiliations("pubsub.qxmpp.org", "node6"); + test.expect("" + ""); + test.inject(QStringLiteral("" + "" + "" + "")); + + const auto affiliations = expectFutureVariant>(future); + QCOMPARE(affiliations.size(), 1); + QCOMPARE(affiliations[0].node(), QString("node6")); + QCOMPARE(affiliations[0].jid(), QString()); + QCOMPARE(affiliations[0].type(), AffiliationType::Owner); +} + +void tst_QXmppPubSubManager::testRequestOptions() +{ + using PresenceStates = QXmppPubSubSubscribeOptions::PresenceState; + + TestClient test; + auto *psManager = test.addNewExtension(); + + auto testOpts = [&](QFuture &&future) { + test.expect("" + "" + ""); + test.inject("" + "" + "" + "" + "http://jabber.org/protocol/pubsub#subscribe_options" + "1" + "0" + "false" + "" + "" + "" + "" + "" + "" + "chat" + "online" + ""); + const auto form = expectFutureVariant(future); + + QCOMPARE(form.notificationsEnabled().value(), true); + QCOMPARE(form.digestsEnabled().value(), false); + QCOMPARE(form.bodyIncluded().value(), false); + QCOMPARE(form.notificationRules(), PresenceStates::Chat | PresenceStates::Online); + QCOMPARE(form.unknownFields().size(), 0); + }; + + testOpts(psManager->requestSubscribeOptions("pubsub.qxmpp.org", "node1", "me@qxmpp.org")); + + test.configuration().setJid("me@qxmpp.org"); + testOpts(psManager->requestSubscribeOptions("pubsub.qxmpp.org", "node1")); +} + +void tst_QXmppPubSubManager::testRequestOptionsError() +{ + TestClient test; + auto *psManager = test.addNewExtension(); + auto future = psManager->requestSubscribeOptions("pubsub.qxmpp.org", "node1", "me@qxmpp.org"); + test.expect("" + "" + ""); + test.inject("" + "" + "" + "" + "urn:xmpp:invlid:pubsub#subscribe_options" + "1" + "0" + "false" + "" + "" + "" + "" + "" + "" + "chat" + "online" + ""); + const auto error = expectFutureVariant(future); + QCOMPARE(error.type(), QXmppStanza::Error::Cancel); + QCOMPARE(error.condition(), QXmppStanza::Error::InternalServerError); + QVERIFY(!error.text().isEmpty()); +} + +void tst_QXmppPubSubManager::testSetOptions() +{ + using PresenceStates = QXmppPubSubSubscribeOptions::PresenceState; + + TestClient test; + test.configuration().setJid("francisco@denmark.lit"); + auto *psManager = test.addNewExtension(); + + QXmppPubSubSubscribeOptions opts; + opts.setNotificationsEnabled(true); + opts.setDigestsEnabled(false); + opts.setBodyIncluded(false); + opts.setNotificationRules(PresenceStates::Chat | PresenceStates::Online | PresenceStates::Away); + + auto future = psManager->setSubscribeOptions("pubsub.shakespeare.lit", "princely_musings", opts); + test.expect("" + "" + "" + "http://jabber.org/protocol/pubsub#subscribe_options" + "1" + "0" + "0" + "awaychatonline" + ""); + test.inject(""); + + expectFutureVariant(future); +} + +void tst_QXmppPubSubManager::testEventNotifications_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("accepted"); + + QTest::addRow("default") + << QStringLiteral( + "" + "" + "" + "" + "" + "Soliloquy" + "" + "To be, or not to be: that is the question:" + "Whether 'tis nobler in the mind to suffer" + "The slings and arrows of outrageous fortune," + "Or to take arms against a sea of troubles," + "And by opposing end them?" + "" + "" + "tag:denmark.lit,2003:entry-32397" + "2003-12-13T18:30:02Z" + "2003-12-13T18:30:02Z" + "" + "" + "" + "" + "") + << true; + QTest::addRow("additional-subelement") + << QStringLiteral( + "" + "" + "" + "" + "" + "" + "Soliloquy" + "" + "To be, or not to be: that is the question:" + "Whether 'tis nobler in the mind to suffer" + "The slings and arrows of outrageous fortune," + "Or to take arms against a sea of troubles," + "And by opposing end them?" + "" + "" + "tag:denmark.lit,2003:entry-32397" + "2003-12-13T18:30:02Z" + "2003-12-13T18:30:02Z" + "" + "" + "" + "" + "") + << true; + QTest::addRow("wrong-event-namespace") + << QStringLiteral( + "" + "" + "" + "" + "" + "" + "Soliloquy" + "" + "" + "" + "" + "") + << false; +} + +void tst_QXmppPubSubManager::testEventNotifications() +{ + QFETCH(QString, xml); + QFETCH(bool, accepted); + const auto event = xmlToDom(xml); + + TestClient client; + auto *psManager = client.addNewExtension(); + auto *eventManager = client.addNewExtension(); + eventManager->m_node = "princely_musings"; + eventManager->m_serviceJid = "pubsub.shakespeare.lit"; + + QCOMPARE(psManager->handleStanza(event), accepted); + if (accepted) { + QCOMPARE(eventManager->m_events, 1u); + } else { + QCOMPARE(eventManager->m_events, 0u); + } + + QCOMPARE(eventManager->pubSub(), psManager); +} + +QTEST_MAIN(tst_QXmppPubSubManager) +#include "tst_qxmpppubsubmanager.moc" -- cgit v1.2.3