aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2021-10-17 17:19:48 +0200
committerLinus Jahn <lnj@kaidan.im>2021-10-18 19:23:21 +0200
commitba1e5dff3ad852573aadad2e378899f7d9b03355 (patch)
tree0e55993d20380cd1867a80343022b58d18e0ac2d /tests
parente4970a79535dd5cfff2d010049cf39b644a87850 (diff)
downloadqxmpp-ba1e5dff3ad852573aadad2e378899f7d9b03355.tar.gz
Add parsing/serialization for SCE envelope
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/qxmppsceenvelope/tst_qxmppsceenvelope.cpp92
2 files changed, 93 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b01b691d..0cce4582 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -52,6 +52,7 @@ add_simple_test(qxmppresultset)
add_simple_test(qxmpprosteriq)
add_simple_test(qxmpprostermanager TestClient.h)
add_simple_test(qxmpprpciq)
+add_simple_test(qxmppsceenvelope)
add_simple_test(qxmppserver)
add_simple_test(qxmppsessioniq)
add_simple_test(qxmppsocks)
diff --git a/tests/qxmppsceenvelope/tst_qxmppsceenvelope.cpp b/tests/qxmppsceenvelope/tst_qxmppsceenvelope.cpp
new file mode 100644
index 00000000..69ec8981
--- /dev/null
+++ b/tests/qxmppsceenvelope/tst_qxmppsceenvelope.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2008-2021 The QXmpp developers
+ *
+ * Author:
+ * 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 "QXmppSceEnvelope_p.h"
+
+#include "util.h"
+#include <QObject>
+
+class tst_QXmppSceEnvelope : public QObject
+{
+ Q_OBJECT
+
+private:
+ Q_SLOT void testReader();
+ Q_SLOT void testWriter();
+};
+
+void tst_QXmppSceEnvelope::testReader()
+{
+ const auto xml = QStringLiteral(
+ "<envelope xmlns=\"urn:xmpp:sce:1\">"
+ "<content><body xmlns=\"jabber:client\">Hello</body><x xmlns=\"jabber:x:oob\"><url>https://en.wikipedia.org/wiki/Fight_Club#Plot</url></x></content>"
+ "<time stamp=\"2004-01-25T06:05:00+01:00\"/>"
+ "<to jid=\"missioncontrol@houston.nasa.gov\"/>"
+ "<from jid=\"opportunity@mars.planet\"/>"
+ "<rpad>C1DHN9HK-9A25tSmwK4hU!Jji9%GKYK^syIlHJT9TnI4</rpad>"
+ "</envelope>");
+ const auto dom = xmlToDom(xml);
+
+ QXmppSceEnvelopeReader reader(dom);
+ QCOMPARE(reader.from(), QStringLiteral("opportunity@mars.planet"));
+ QCOMPARE(reader.to(), QStringLiteral("missioncontrol@houston.nasa.gov"));
+ QCOMPARE(reader.timestamp(), QDateTime({2004, 01, 25}, {05, 05, 00}, Qt::UTC));
+ QCOMPARE(reader.contentElement().firstChildElement().tagName(), QStringLiteral("body"));
+}
+
+void tst_QXmppSceEnvelope::testWriter()
+{
+ const auto expectedXml = QStringLiteral(
+ "<envelope xmlns=\"urn:xmpp:sce:1\">"
+ "<content><body xmlns=\"jabber:client\">Hello</body><x xmlns=\"jabber:x:oob\"><url>https://en.wikipedia.org/wiki/Fight_Club#Plot</url></x></content>"
+ "<time stamp=\"2004-01-25T05:05:00Z\"/>"
+ "<to jid=\"missioncontrol@houston.nasa.gov\"/>"
+ "<from jid=\"opportunity@mars.planet\"/>"
+ "<rpad>C1DHN9HK-9A25tSmwK4hU!Jji9%GKYK^syIlHJT9TnI4</rpad>"
+ "</envelope>");
+
+ QString out;
+ QXmlStreamWriter writer(&out);
+ QXmppSceEnvelopeWriter envelope(writer);
+ envelope.start();
+ envelope.writeContent([&writer] {
+ writer.writeStartElement("body");
+ writer.writeDefaultNamespace("jabber:client");
+ writer.writeCharacters("Hello");
+ writer.writeEndElement();
+ writer.writeStartElement("x");
+ writer.writeDefaultNamespace("jabber:x:oob");
+ writer.writeTextElement("url", "https://en.wikipedia.org/wiki/Fight_Club#Plot");
+ writer.writeEndElement();
+ });
+ envelope.writeTimestamp(QDateTime({2004, 01, 25}, {05, 05, 00}, Qt::UTC));
+ envelope.writeTo("missioncontrol@houston.nasa.gov");
+ envelope.writeFrom("opportunity@mars.planet");
+ envelope.writeRpad("C1DHN9HK-9A25tSmwK4hU!Jji9%GKYK^syIlHJT9TnI4");
+ envelope.end();
+
+ QCOMPARE(out, expectedXml);
+}
+
+QTEST_MAIN(tst_QXmppSceEnvelope)
+#include "tst_qxmppsceenvelope.moc"