From 947ad50e7c62a8d65544d64bb7a85303522dfd80 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 10 Oct 2020 21:41:13 +0200 Subject: tests: Adapt to Qt6's stricter XML parsing --- .../qxmppcarbonmanager/tst_qxmppcarbonmanager.cpp | 80 +++++++++++----------- tests/qxmppmammanager/tst_qxmppmammanager.cpp | 24 +++---- .../tst_qxmppstreamfeatures.cpp | 23 ++++++- 3 files changed, 72 insertions(+), 55 deletions(-) (limited to 'tests') 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("" + " from='romeo@montague.example'" + " to='romeo@montague.example/home'" + " type='chat'>" "" "" "" + " from='juliet@capulet.example/balcony'" + " to='romeo@montague.example/garden'" + " type='chat'>" "What man art thou that, thus bescreen'd in night, so stumblest on my counsel?" "0e3141cd80894871a68e6fe6b1ec56fa" "" @@ -103,24 +103,24 @@ void tst_QXmppCarbonManager::testHandleStanza_data() "") << true << false << QByteArray("" + " from='juliet@capulet.example/balcony'" + " to='romeo@montague.example/garden'" + " type='chat'>" "What man art thou that, thus bescreen'd in night, so stumblest on my counsel?" "0e3141cd80894871a68e6fe6b1ec56fa" ""); QTest::newRow("sent1") << QByteArray("" + " from='romeo@montague.example'" + " to='romeo@montague.example/garden'" + " type='chat'>" "" "" "" + " to='juliet@capulet.example/balcony'" + " from='romeo@montague.example/home'" + " type='chat'>" "Neither, fair saint, if either thee dislike." "0e3141cd80894871a68e6fe6b1ec56fa" "" @@ -129,24 +129,24 @@ void tst_QXmppCarbonManager::testHandleStanza_data() "") << true << true << QByteArray("" + " to='juliet@capulet.example/balcony'" + " from='romeo@montague.example/home'" + " type='chat'>" "Neither, fair saint, if either thee dislike." "0e3141cd80894871a68e6fe6b1ec56fa" ""); QTest::newRow("received-wrong-from") << QByteArray("" + " from='not-romeo@montague.example'" + " to='romeo@montague.example/home'" + " type='chat'>" "" "" "" + " from='juliet@capulet.example/balcony'" + " to='romeo@montague.example/garden'" + " type='chat'>" "What man art thou that, thus bescreen'd in night, so stumblest on my counsel?" "0e3141cd80894871a68e6fe6b1ec56fa" "" @@ -155,24 +155,24 @@ void tst_QXmppCarbonManager::testHandleStanza_data() "") << false << false << QByteArray("" + " from='juliet@capulet.example/balcony'" + " to='romeo@montague.example/garden'" + " type='chat'>" "What man art thou that, thus bescreen'd in night, so stumblest on my counsel?" "0e3141cd80894871a68e6fe6b1ec56fa" ""); QTest::newRow("sent-wrong-from") << QByteArray("" + " from='not-romeo@montague.example'" + " to='romeo@montague.example/garden'" + " type='chat'>" "" "" "" + " to='juliet@capulet.example/balcony'" + " from='romeo@montague.example/home'" + " type='chat'>" "Neither, fair saint, if either thee dislike." "0e3141cd80894871a68e6fe6b1ec56fa" "" @@ -181,9 +181,9 @@ void tst_QXmppCarbonManager::testHandleStanza_data() "") << false << true << QByteArray("" + " to='juliet@capulet.example/balcony'" + " from='romeo@montague.example/home'" + " type='chat'>" "Neither, fair saint, if either thee dislike." "0e3141cd80894871a68e6fe6b1ec56fa" ""); @@ -194,10 +194,10 @@ void tst_QXmppCarbonManager::testHandleStanza_data() "" "" "" + " id='0202197'" + " to='romeo@montague.lit'" + " type='chat'" + " xmlns='jabber:client'>" "Yet I should kill thee with much cherishing." "" "" 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() "" "" "" + " to='juliet@capulet.lit/balcony'" + " from='romeo@montague.lit/orchard'" + " type='chat'>" "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo." "" "" @@ -96,9 +96,9 @@ void tst_QXmppMamManager::testHandleStanza_data() "") << true << QByteArray("" + " to='juliet@capulet.lit/balcony'" + " from='romeo@montague.lit/orchard'" + " type='chat'>" "" "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo." "") @@ -110,9 +110,9 @@ void tst_QXmppMamManager::testHandleStanza_data() "" "" "" + " to='romeo@montague.lit/orchard'" + " from='juliet@capulet.lit/balcony'" + " type='chat' id='8a54s'>" "What man art thou that thus bescreen'd in night so stumblest on my counsel?" "" "" @@ -128,9 +128,9 @@ void tst_QXmppMamManager::testHandleStanza_data() "" "" "" + " to='juliet@capulet.lit/balcony'" + " from='romeo@montague.lit/orchard'" + " type='chat'>" "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo." "" "" 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 +static void parsePacketWithStream(T &packet, const QByteArray &xml) +{ + QDomDocument doc; + const auto wrappedXml = + QByteArrayLiteral("") + + xml + QByteArrayLiteral(""); + + 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(""); 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() ""); QXmppStreamFeatures features; - parsePacket(features, xml); + parsePacketWithStream(features, xml); QCOMPARE(features.tlsMode(), QXmppStreamFeatures::Required); serializePacket(features, xml); } @@ -86,7 +103,7 @@ void tst_QXmppStreamFeatures::testFull() ""); QXmppStreamFeatures features; - parsePacket(features, xml); + parsePacketWithStream(features, xml); QCOMPARE(features.bindMode(), QXmppStreamFeatures::Enabled); QCOMPARE(features.sessionMode(), QXmppStreamFeatures::Enabled); QCOMPARE(features.nonSaslAuthMode(), QXmppStreamFeatures::Enabled); -- cgit v1.2.3