diff options
| author | Linus Jahn <lnj@kaidan.im> | 2020-10-10 21:41:13 +0200 |
|---|---|---|
| committer | LNJ <lnj@kaidan.im> | 2020-10-10 22:33:41 +0200 |
| commit | 947ad50e7c62a8d65544d64bb7a85303522dfd80 (patch) | |
| tree | 98df0bd8c0737b9eb92255e6da03672cc6f9ea62 | |
| parent | 3fce512b43b00f1f0b30a79d849597682ab9098f (diff) | |
| download | qxmpp-947ad50e7c62a8d65544d64bb7a85303522dfd80.tar.gz | |
tests: Adapt to Qt6's stricter XML parsing
| -rw-r--r-- | tests/qxmppcarbonmanager/tst_qxmppcarbonmanager.cpp | 80 | ||||
| -rw-r--r-- | tests/qxmppmammanager/tst_qxmppmammanager.cpp | 24 | ||||
| -rw-r--r-- | tests/qxmppstreamfeatures/tst_qxmppstreamfeatures.cpp | 23 |
3 files changed, 72 insertions, 55 deletions
diff --git a/tests/qxmppcarbonmanager/tst_qxmppcarbonmanager.cpp b/tests/qxmppcarbonmanager/tst_qxmppcarbonmanager.cpp index 684c7470..1e8a4d76 100644 --- a/tests/qxmppcarbonmanager/tst_qxmppcarbonmanager.cpp +++ b/tests/qxmppcarbonmanager/tst_qxmppcarbonmanager.cpp @@ -86,15 +86,15 @@ void tst_QXmppCarbonManager::testHandleStanza_data() QTest::newRow("received1") << QByteArray("<message xmlns='jabber:client'" - "from='romeo@montague.example'" - "to='romeo@montague.example/home'" - "type='chat'>" + " from='romeo@montague.example'" + " to='romeo@montague.example/home'" + " type='chat'>" "<received xmlns='urn:xmpp:carbons:2'>" "<forwarded xmlns='urn:xmpp:forward:0'>" "<message xmlns='jabber:client'" - "from='juliet@capulet.example/balcony'" - "to='romeo@montague.example/garden'" - "type='chat'>" + " from='juliet@capulet.example/balcony'" + " to='romeo@montague.example/garden'" + " type='chat'>" "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" "</message>" @@ -103,24 +103,24 @@ void tst_QXmppCarbonManager::testHandleStanza_data() "</message>") << true << false << QByteArray("<message xmlns='jabber:client'" - "from='juliet@capulet.example/balcony'" - "to='romeo@montague.example/garden'" - "type='chat'>" + " from='juliet@capulet.example/balcony'" + " to='romeo@montague.example/garden'" + " type='chat'>" "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" "</message>"); QTest::newRow("sent1") << QByteArray("<message xmlns='jabber:client'" - "from='romeo@montague.example'" - "to='romeo@montague.example/garden'" - "type='chat'>" + " from='romeo@montague.example'" + " to='romeo@montague.example/garden'" + " type='chat'>" "<sent xmlns='urn:xmpp:carbons:2'>" "<forwarded xmlns='urn:xmpp:forward:0'>" "<message xmlns='jabber:client'" - "to='juliet@capulet.example/balcony'" - "from='romeo@montague.example/home'" - "type='chat'>" + " to='juliet@capulet.example/balcony'" + " from='romeo@montague.example/home'" + " type='chat'>" "<body>Neither, fair saint, if either thee dislike.</body>" "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" "</message>" @@ -129,24 +129,24 @@ void tst_QXmppCarbonManager::testHandleStanza_data() "</message>") << true << true << QByteArray("<message xmlns='jabber:client'" - "to='juliet@capulet.example/balcony'" - "from='romeo@montague.example/home'" - "type='chat'>" + " to='juliet@capulet.example/balcony'" + " from='romeo@montague.example/home'" + " type='chat'>" "<body>Neither, fair saint, if either thee dislike.</body>" "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" "</message>"); QTest::newRow("received-wrong-from") << QByteArray("<message xmlns='jabber:client'" - "from='not-romeo@montague.example'" - "to='romeo@montague.example/home'" - "type='chat'>" + " from='not-romeo@montague.example'" + " to='romeo@montague.example/home'" + " type='chat'>" "<received xmlns='urn:xmpp:carbons:2'>" "<forwarded xmlns='urn:xmpp:forward:0'>" "<message xmlns='jabber:client'" - "from='juliet@capulet.example/balcony'" - "to='romeo@montague.example/garden'" - "type='chat'>" + " from='juliet@capulet.example/balcony'" + " to='romeo@montague.example/garden'" + " type='chat'>" "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" "</message>" @@ -155,24 +155,24 @@ void tst_QXmppCarbonManager::testHandleStanza_data() "</message>") << false << false << QByteArray("<message xmlns='jabber:client'" - "from='juliet@capulet.example/balcony'" - "to='romeo@montague.example/garden'" - "type='chat'>" + " from='juliet@capulet.example/balcony'" + " to='romeo@montague.example/garden'" + " type='chat'>" "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" "</message>"); QTest::newRow("sent-wrong-from") << QByteArray("<message xmlns='jabber:client'" - "from='not-romeo@montague.example'" - "to='romeo@montague.example/garden'" - "type='chat'>" + " from='not-romeo@montague.example'" + " to='romeo@montague.example/garden'" + " type='chat'>" "<sent xmlns='urn:xmpp:carbons:2'>" "<forwarded xmlns='urn:xmpp:forward:0'>" "<message xmlns='jabber:client'" - "to='juliet@capulet.example/balcony'" - "from='romeo@montague.example/home'" - "type='chat'>" + " to='juliet@capulet.example/balcony'" + " from='romeo@montague.example/home'" + " type='chat'>" "<body>Neither, fair saint, if either thee dislike.</body>" "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" "</message>" @@ -181,9 +181,9 @@ void tst_QXmppCarbonManager::testHandleStanza_data() "</message>") << false << true << QByteArray("<message xmlns='jabber:client'" - "to='juliet@capulet.example/balcony'" - "from='romeo@montague.example/home'" - "type='chat'>" + " to='juliet@capulet.example/balcony'" + " from='romeo@montague.example/home'" + " type='chat'>" "<body>Neither, fair saint, if either thee dislike.</body>" "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" "</message>"); @@ -194,10 +194,10 @@ void tst_QXmppCarbonManager::testHandleStanza_data() "<forwarded xmlns='urn:xmpp:forward:0'>" "<delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>" "<message from='juliet@capulet.lit/orchard'" - "id='0202197'" - "to='romeo@montague.lit'" - "type='chat'" - "xmlns='jabber:client'>" + " id='0202197'" + " to='romeo@montague.lit'" + " type='chat'" + " xmlns='jabber:client'>" "<body>Yet I should kill thee with much cherishing.</body>" "<mood xmlns='http://jabber.org/protocol/mood'>" "<amorous/>" diff --git a/tests/qxmppmammanager/tst_qxmppmammanager.cpp b/tests/qxmppmammanager/tst_qxmppmammanager.cpp index fbcd9b01..c433a4db 100644 --- a/tests/qxmppmammanager/tst_qxmppmammanager.cpp +++ b/tests/qxmppmammanager/tst_qxmppmammanager.cpp @@ -86,9 +86,9 @@ void tst_QXmppMamManager::testHandleStanza_data() "<forwarded xmlns='urn:xmpp:forward:0'>" "<delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>" "<message xmlns='jabber:client'" - "to='juliet@capulet.lit/balcony'" - "from='romeo@montague.lit/orchard'" - "type='chat'>" + " to='juliet@capulet.lit/balcony'" + " from='romeo@montague.lit/orchard'" + " type='chat'>" "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" "</message>" "</forwarded>" @@ -96,9 +96,9 @@ void tst_QXmppMamManager::testHandleStanza_data() "</message>") << true << QByteArray("<message xmlns='jabber:client'" - "to='juliet@capulet.lit/balcony'" - "from='romeo@montague.lit/orchard'" - "type='chat'>" + " to='juliet@capulet.lit/balcony'" + " from='romeo@montague.lit/orchard'" + " type='chat'>" "<delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>" "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" "</message>") @@ -110,9 +110,9 @@ void tst_QXmppMamManager::testHandleStanza_data() "<forwarded xmlns='urn:xmpp:forward:0'>" "<delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:09:32Z'/>" "<message xmlns='jabber:client'" - "to='romeo@montague.lit/orchard'" - "from='juliet@capulet.lit/balcony'" - "type='chat' id='8a54s'>" + " to='romeo@montague.lit/orchard'" + " from='juliet@capulet.lit/balcony'" + " type='chat' id='8a54s'>" "<body>What man art thou that thus bescreen'd in night so stumblest on my counsel?</body>" "</message>" "</forwarded>" @@ -128,9 +128,9 @@ void tst_QXmppMamManager::testHandleStanza_data() "<forwarded xmlns='urn:xmpp:forward:0'>" "<delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>" "<message xmlns='jabber:client'" - "to='juliet@capulet.lit/balcony'" - "from='romeo@montague.lit/orchard'" - "type='chat'>" + " to='juliet@capulet.lit/balcony'" + " from='romeo@montague.lit/orchard'" + " type='chat'>" "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" "</message>" "</forwarded>" diff --git a/tests/qxmppstreamfeatures/tst_qxmppstreamfeatures.cpp b/tests/qxmppstreamfeatures/tst_qxmppstreamfeatures.cpp index fe011789..3a0dd5e3 100644 --- a/tests/qxmppstreamfeatures/tst_qxmppstreamfeatures.cpp +++ b/tests/qxmppstreamfeatures/tst_qxmppstreamfeatures.cpp @@ -25,6 +25,23 @@ #include "util.h" +template<class T> +static void parsePacketWithStream(T &packet, const QByteArray &xml) +{ + QDomDocument doc; + const auto wrappedXml = + QByteArrayLiteral("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>") + + xml + QByteArrayLiteral("</stream:stream>"); + + QString err; + bool parsingSuccess = doc.setContent(wrappedXml, true, &err); + if (!err.isNull()) + qDebug() << err; + QVERIFY(parsingSuccess); + + packet.parse(doc.documentElement().firstChildElement()); +} + class tst_QXmppStreamFeatures : public QObject { Q_OBJECT @@ -41,7 +58,7 @@ void tst_QXmppStreamFeatures::testEmpty() const QByteArray xml("<stream:features/>"); QXmppStreamFeatures features; - parsePacket(features, xml); + parsePacketWithStream(features, xml); QCOMPARE(features.bindMode(), QXmppStreamFeatures::Disabled); QCOMPARE(features.sessionMode(), QXmppStreamFeatures::Disabled); QCOMPARE(features.nonSaslAuthMode(), QXmppStreamFeatures::Disabled); @@ -65,7 +82,7 @@ void tst_QXmppStreamFeatures::testRequired() "</stream:features>"); QXmppStreamFeatures features; - parsePacket(features, xml); + parsePacketWithStream(features, xml); QCOMPARE(features.tlsMode(), QXmppStreamFeatures::Required); serializePacket(features, xml); } @@ -86,7 +103,7 @@ void tst_QXmppStreamFeatures::testFull() "</stream:features>"); QXmppStreamFeatures features; - parsePacket(features, xml); + parsePacketWithStream(features, xml); QCOMPARE(features.bindMode(), QXmppStreamFeatures::Enabled); QCOMPARE(features.sessionMode(), QXmppStreamFeatures::Enabled); QCOMPARE(features.nonSaslAuthMode(), QXmppStreamFeatures::Enabled); |
