aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2023-03-17 17:24:52 +0100
committerLinus Jahn <lnj@kaidan.im>2023-03-17 17:24:52 +0100
commit55362b2e36f91282ccfbdd2bd5a9bba1d50c2002 (patch)
treea0d6193add779507821defb2ebe9e9f8d8405628 /tests
parentd679ad1c49eeb28be2ac3a75bd7fd1a9be24d483 (diff)
parent1cf0a4aff856a1f3cab0f9750ee6b361691350a7 (diff)
downloadqxmpp-55362b2e36f91282ccfbdd2bd5a9bba1d50c2002.tar.gz
Merge branch '1.5'
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/qxmppentitytimemanager/tst_qxmppentitytimemanager.cpp68
-rw-r--r--tests/qxmppmessage/tst_qxmppmessage.cpp2
-rw-r--r--tests/qxmppversionmanager/tst_qxmppversionmanager.cpp68
4 files changed, 139 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index e7d304ef..e599ec47 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -35,6 +35,7 @@ add_simple_test(qxmppdataform)
add_simple_test(qxmppdiscoveryiq)
add_simple_test(qxmppdiscoverymanager TestClient.h)
add_simple_test(qxmppentitytimeiq)
+add_simple_test(qxmppentitytimemanager TestClient.h)
add_simple_test(qxmppexternalservicediscoveryiq)
add_simple_test(qxmppexternalservicediscoverymanager TestClient.h)
add_simple_test(qxmpphttpuploadiq)
@@ -79,6 +80,7 @@ add_simple_test(qxmppusertunemanager TestClient.h)
add_simple_test(qxmppvcardiq)
add_simple_test(qxmppvcardmanager)
add_simple_test(qxmppversioniq)
+add_simple_test(qxmppversionmanager TestClient.h)
if(WITH_QCA)
add_simple_test(qxmppfileencryption)
diff --git a/tests/qxmppentitytimemanager/tst_qxmppentitytimemanager.cpp b/tests/qxmppentitytimemanager/tst_qxmppentitytimemanager.cpp
new file mode 100644
index 00000000..a76a628d
--- /dev/null
+++ b/tests/qxmppentitytimemanager/tst_qxmppentitytimemanager.cpp
@@ -0,0 +1,68 @@
+// SPDX-FileCopyrightText: 2023 Linus Jahn <lnj@kaidan.im>
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+
+#include "QXmppEntityTimeIq.h"
+#include "QXmppEntityTimeManager.h"
+
+#include "TestClient.h"
+
+Q_DECLARE_METATYPE(QXmppEntityTimeIq)
+
+class tst_QXmppEntityTimeManager : public QObject
+{
+ Q_OBJECT
+ Q_SLOT void initTestCase();
+ Q_SLOT void testSendRequest();
+ Q_SLOT void testHandleRequest();
+};
+
+void tst_QXmppEntityTimeManager::initTestCase()
+{
+ qRegisterMetaType<QXmppEntityTimeIq>();
+}
+
+void tst_QXmppEntityTimeManager::testSendRequest()
+{
+ TestClient test;
+ auto *manager = test.addNewExtension<QXmppEntityTimeManager>();
+
+ QSignalSpy spy(manager, &QXmppEntityTimeManager::timeReceived);
+
+ manager->requestTime("juliet@capulet.com/balcony");
+ test.expect("<iq id='qxmpp1' to='juliet@capulet.com/balcony' type='get'><time xmlns='urn:xmpp:time'/></iq>");
+ manager->handleStanza(xmlToDom(R"(<iq id='qxmpp1' to='romeo@montague.net/orchard' from='juliet@capulet.com/balcony' type='result'>
+ <time xmlns='urn:xmpp:time'>
+ <tzo>-06:00</tzo>
+ <utc>2006-12-19T17:58:35Z</utc>
+ </time>
+</iq>)"));
+
+ QCOMPARE(spy.size(), 1);
+ auto time = spy.at(0).at(0).value<QXmppEntityTimeIq>();
+ QCOMPARE(time.utc(), QDateTime({2006, 12, 19}, {17, 58, 35}, Qt::UTC));
+ QCOMPARE(time.tzo(), -6 * 60 * 60);
+}
+
+void tst_QXmppEntityTimeManager::testHandleRequest()
+{
+ TestClient test;
+ test.configuration().setJid("juliet@capulet.com/balcony");
+
+ auto *manager = test.addNewExtension<QXmppEntityTimeManager>();
+
+ manager->handleStanza(xmlToDom(R"(<iq type='get' from='romeo@montague.net/orchard' to='juliet@capulet.com/balcony' id='time_1'>
+ <time xmlns='urn:xmpp:time'/>
+</iq>)"));
+
+ auto packet = xmlToDom(test.takePacket());
+ QVERIFY(QXmppEntityTimeIq::isEntityTimeIq(packet));
+ QXmppEntityTimeIq resp;
+ resp.parse(packet);
+
+ QCOMPARE(resp.id(), QStringLiteral("time_1"));
+ QCOMPARE(resp.type(), QXmppIq::Result);
+}
+
+QTEST_MAIN(tst_QXmppEntityTimeManager)
+#include "tst_qxmppentitytimemanager.moc"
diff --git a/tests/qxmppmessage/tst_qxmppmessage.cpp b/tests/qxmppmessage/tst_qxmppmessage.cpp
index deca437e..98ca5670 100644
--- a/tests/qxmppmessage/tst_qxmppmessage.cpp
+++ b/tests/qxmppmessage/tst_qxmppmessage.cpp
@@ -783,7 +783,7 @@ void tst_QXmppMessage::testEme()
// test standard encryption: OMEMO
const QByteArray xmlOmemo(
"<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">"
- "<encryption xmlns=\"urn:xmpp:eme:0\" namespace=\"eu.siacs.conversations.axolotl\"/>"
+ "<encryption xmlns=\"urn:xmpp:eme:0\" namespace=\"eu.siacs.conversations.axolotl\" name=\"OMEMO\"/>"
"<body>This message is encrypted with OMEMO, but your client doesn&apos;t seem to support that.</body>"
"</message>");
diff --git a/tests/qxmppversionmanager/tst_qxmppversionmanager.cpp b/tests/qxmppversionmanager/tst_qxmppversionmanager.cpp
new file mode 100644
index 00000000..b28d0de2
--- /dev/null
+++ b/tests/qxmppversionmanager/tst_qxmppversionmanager.cpp
@@ -0,0 +1,68 @@
+// SPDX-FileCopyrightText: 2023 Linus Jahn <lnj@kaidan.im>
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+
+#include "QXmppVersionManager.h"
+#include "QXmppVersionIq.h"
+
+#include "TestClient.h"
+
+Q_DECLARE_METATYPE(QXmppVersionIq);
+
+class tst_QXmppVersionManager : public QObject
+{
+ Q_OBJECT
+ Q_SLOT void initTestCase();
+ Q_SLOT void testSendRequest();
+ Q_SLOT void testHandleRequest();
+};
+
+void tst_QXmppVersionManager::initTestCase()
+{
+ qRegisterMetaType<QXmppVersionIq>();
+}
+
+void tst_QXmppVersionManager::testSendRequest()
+{
+ TestClient test;
+ auto *verManager = test.addNewExtension<QXmppVersionManager>();
+
+ QSignalSpy spy(verManager, &QXmppVersionManager::versionReceived);
+
+ auto id = verManager->requestVersion("juliet@capulet.com/balcony");
+ test.expect("<iq id='qxmpp1' to='juliet@capulet.com/balcony' type='get'><query xmlns='jabber:iq:version'/></iq>");
+ verManager->handleStanza(xmlToDom(R"(<iq type='result' from='juliet@capulet.com/balcony' id='qxmpp1'>
+ <query xmlns='jabber:iq:version'>
+ <name>Exodus</name>
+ <version>0.7.0.4</version>
+ <os>Windows-XP 5.01.2600</os>
+ </query>
+</iq>)"));
+
+ QCOMPARE(spy.size(), 1);
+ auto version = spy.at(0).at(0).value<QXmppVersionIq>();
+ QCOMPARE(version.name(), QStringLiteral("Exodus"));
+ QCOMPARE(version.version(), QStringLiteral("0.7.0.4"));
+ QCOMPARE(version.os(), QStringLiteral("Windows-XP 5.01.2600"));
+}
+
+void tst_QXmppVersionManager::testHandleRequest()
+{
+ TestClient test;
+ test.configuration().setJid("juliet@capulet.com/balcony");
+
+ auto *verManager = test.addNewExtension<QXmppVersionManager>();
+ verManager->setClientName("Exodus");
+ verManager->setClientVersion("0.7.0.4");
+ verManager->setClientOs("Windows-XP 5.01.2600");
+
+ verManager->handleStanza(xmlToDom(R"(<iq type='get' from='romeo@montague.net/orchard' to='juliet@capulet.com/balcony' id='version_1'>
+ <query xmlns='jabber:iq:version'/>
+</iq>)"));
+ test.expect(R"(<iq id='version_1' to='romeo@montague.net/orchard' type='result'>)"
+ "<query xmlns='jabber:iq:version'><name>Exodus</name><os>Windows-XP 5.01.2600</os><version>0.7.0.4</version>"
+ "</query></iq>");
+}
+
+QTEST_MAIN(tst_QXmppVersionManager)
+#include "tst_qxmppversionmanager.moc"