aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2020-03-31 23:20:00 +0200
committerLNJ <lnj@kaidan.im>2020-04-01 00:09:45 +0200
commit175ee42efc00e8185e3143a389df42c89dd78671 (patch)
tree42aff563e8bf815b3db5e1bd8421fd7a8c205156 /tests
parent40622fc1dc45d514dfc82f8802dc6dac5306bddc (diff)
downloadqxmpp-175ee42efc00e8185e3143a389df42c89dd78671.tar.gz
Add QXmppVCardManger tests
Co-authored-by: Melvin Keskin <melvo@olomono.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/qxmppvcardmanager/tst_qxmppvcardmanager.cpp108
2 files changed, 109 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d320ae95..b1ee1e57 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -51,6 +51,7 @@ add_simple_test(qxmppstarttlspacket)
add_simple_test(qxmppstreamfeatures)
add_simple_test(qxmppstunmessage)
add_simple_test(qxmppvcardiq)
+add_simple_test(qxmppvcardmanager)
add_simple_test(qxmppversioniq)
if(BUILD_INTERNAL_TESTS)
diff --git a/tests/qxmppvcardmanager/tst_qxmppvcardmanager.cpp b/tests/qxmppvcardmanager/tst_qxmppvcardmanager.cpp
new file mode 100644
index 00000000..ec079e93
--- /dev/null
+++ b/tests/qxmppvcardmanager/tst_qxmppvcardmanager.cpp
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2008-2020 The QXmpp developers
+ *
+ * Authors:
+ * Melvin Keskin
+ * 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 <QObject>
+#include "QXmppClient.h"
+#include "QXmppVCardIq.h"
+#include "QXmppVCardManager.h"
+#include "util.h"
+
+Q_DECLARE_METATYPE(QXmppVCardIq);
+
+class tst_QXmppVCardManager : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testHandleStanza_data();
+ void testHandleStanza();
+
+private:
+ QXmppClient m_client;
+};
+
+void tst_QXmppVCardManager::testHandleStanza_data()
+{
+ QTest::addColumn<QXmppVCardIq>("expectedIq");
+ QTest::addColumn<bool>("isClientVCard");
+
+#define ROW(name, iq, clientVCard) \
+ QTest::newRow(QT_STRINGIFY(name)) << iq << clientVCard
+
+ QXmppVCardIq iq;
+ iq.setType(QXmppIq::Result);
+ iq.setTo("stpeter@jabber.org/roundabout");
+ iq.setFullName("Jeremie Miller");
+
+ auto iqFromBare = iq;
+ iqFromBare.setFrom("stpeter@jabber.org");
+
+ auto iqFromFull = iq;
+ iqFromFull.setFrom("stpeter@jabber.org/roundabout");
+
+ ROW(client-vcard-from-empty, iq, true);
+ ROW(client-vcard-from-bare, iqFromBare, true);
+ ROW(client-vcard-from-full, iqFromFull, false);
+
+#undef ROW
+}
+
+void tst_QXmppVCardManager::testHandleStanza()
+{
+ QFETCH(QXmppVCardIq, expectedIq);
+ QFETCH(bool, isClientVCard);
+
+ // initialize new manager to clear internal values
+ QXmppVCardManager *manager = new QXmppVCardManager();
+ m_client.addExtension(manager);
+
+ // sets own jid internally
+ m_client.connectToServer("stpeter@jabber.org", {});
+ m_client.disconnectFromServer();
+
+ bool vCardReceived = false;
+ bool clientVCardReceived = false;
+
+ QObject context;
+ connect(manager, &QXmppVCardManager::vCardReceived, &context, [&](QXmppVCardIq iq) {
+ vCardReceived = true;
+ QCOMPARE(iq, expectedIq);
+ });
+ connect(manager, &QXmppVCardManager::clientVCardReceived, &context, [&]() {
+ clientVCardReceived = true;
+ QCOMPARE(manager->clientVCard(), expectedIq);
+ });
+
+ bool accepted = manager->handleStanza(writePacketToDom(expectedIq));
+
+ QVERIFY(accepted);
+ QVERIFY(vCardReceived);
+ QCOMPARE(clientVCardReceived, isClientVCard);
+
+ // clean up (client deletes manager)
+ m_client.removeExtension(manager);
+}
+
+QTEST_MAIN(tst_QXmppVCardManager)
+#include "tst_qxmppvcardmanager.moc"