From ba1e5dff3ad852573aadad2e378899f7d9b03355 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sun, 17 Oct 2021 17:19:48 +0200 Subject: Add parsing/serialization for SCE envelope --- tests/CMakeLists.txt | 1 + tests/qxmppsceenvelope/tst_qxmppsceenvelope.cpp | 92 +++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tests/qxmppsceenvelope/tst_qxmppsceenvelope.cpp (limited to 'tests') 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 + +class tst_QXmppSceEnvelope : public QObject +{ + Q_OBJECT + +private: + Q_SLOT void testReader(); + Q_SLOT void testWriter(); +}; + +void tst_QXmppSceEnvelope::testReader() +{ + const auto xml = QStringLiteral( + "" + "Hellohttps://en.wikipedia.org/wiki/Fight_Club#Plot" + ""); + 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( + "" + "Hellohttps://en.wikipedia.org/wiki/Fight_Club#Plot" + ""); + + 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" -- cgit v1.2.3