aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2021-07-05 23:58:47 +0200
committerLinus Jahn <lnj@kaidan.im>2021-07-06 00:37:03 +0200
commit203f82b18330f47511bbeed9511ade15a66314bb (patch)
tree1aced5e739c63ba19833d8973a851784c4832860 /tests
parent6b6fdfabb1ba8051f0a55e9e7bff123907253030 (diff)
downloadqxmpp-203f82b18330f47511bbeed9511ade15a66314bb.tar.gz
RosterManager: Add unit tests for QFuture requests
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/qxmpprostermanager/tst_qxmpprostermanager.cpp52
2 files changed, 52 insertions, 2 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 2022b75a..10f07464 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -43,7 +43,7 @@ add_simple_test(qxmppregisteriq)
add_simple_test(qxmppregistrationmanager)
add_simple_test(qxmppresultset)
add_simple_test(qxmpprosteriq)
-add_simple_test(qxmpprostermanager)
+add_simple_test(qxmpprostermanager TestClient.h)
add_simple_test(qxmpprpciq)
add_simple_test(qxmppserver)
add_simple_test(qxmppsessioniq)
diff --git a/tests/qxmpprostermanager/tst_qxmpprostermanager.cpp b/tests/qxmpprostermanager/tst_qxmpprostermanager.cpp
index 1cee09b1..a3cd82ab 100644
--- a/tests/qxmpprostermanager/tst_qxmpprostermanager.cpp
+++ b/tests/qxmpprostermanager/tst_qxmpprostermanager.cpp
@@ -26,7 +26,7 @@
#include "QXmppDiscoveryManager.h"
#include "QXmppRosterManager.h"
-#include "util.h"
+#include "TestClient.h"
class tst_QXmppRosterManager : public QObject
{
@@ -38,6 +38,8 @@ private slots:
void testDiscoFeatures();
void testRenameItem();
void subscriptionRequestReceived();
+ Q_SLOT void testAddItem();
+ Q_SLOT void testRemoveItem();
private:
QXmppClient client;
@@ -127,5 +129,53 @@ void tst_QXmppRosterManager::subscriptionRequestReceived()
QVERIFY(subscriptionRequestReceived);
}
+void tst_QXmppRosterManager::testAddItem()
+{
+ TestClient test;
+ auto *rosterManager = test.addNewExtension<QXmppRosterManager>(&test);
+
+ auto future = rosterManager->addRosterItem("contact@example.org");
+ test.expect("<iq id='qxmpp1' type='set'><query xmlns='jabber:iq:roster'><item jid='contact@example.org'/></query></iq>");
+ test.inject("<iq id='qxmpp1' type='result'/>");
+ expectFutureVariant<QXmpp::Success>(future);
+
+ future = rosterManager->addRosterItem("contact@example.org");
+ test.expect("<iq id='qxmpp1' type='set'><query xmlns='jabber:iq:roster'><item jid='contact@example.org'/></query></iq>");
+ test.inject(R"(
+<iq id='qxmpp1' type='error'>
+ <error type='modify'>
+ <not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
+ <text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>This is not allowed</text>
+ </error>
+</iq>)");
+ auto error = expectFutureVariant<QXmppStanza::Error>(future);
+ QCOMPARE(error.type(), QXmppStanza::Error::Modify);
+ QCOMPARE(error.text(), QStringLiteral("This is not allowed"));
+}
+
+void tst_QXmppRosterManager::testRemoveItem()
+{
+ TestClient test;
+ auto *rosterManager = test.addNewExtension<QXmppRosterManager>(&test);
+
+ auto future = rosterManager->removeRosterItem("contact@example.org");
+ test.expect("<iq id='qxmpp1' type='set'><query xmlns='jabber:iq:roster'><item jid='contact@example.org' subscription='remove'/></query></iq>");
+ test.inject("<iq id='qxmpp1' type='result'/>");
+ expectFutureVariant<QXmpp::Success>(future);
+
+ future = rosterManager->removeRosterItem("contact@example.org");
+ test.expect("<iq id='qxmpp1' type='set'><query xmlns='jabber:iq:roster'><item jid='contact@example.org' subscription='remove'/></query></iq>");
+ test.inject(R"(
+<iq id='qxmpp1' type='error'>
+ <error type='cancel'>
+ <item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
+ <text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Not found</text>
+ </error>
+</iq>)");
+ auto error = expectFutureVariant<QXmppStanza::Error>(future);
+ QCOMPARE(error.type(), QXmppStanza::Error::Cancel);
+ QCOMPARE(error.text(), QStringLiteral("Not found"));
+}
+
QTEST_MAIN(tst_QXmppRosterManager)
#include "tst_qxmpprostermanager.moc"