diff --git a/tests/TestClient.h b/tests/TestClient.h index c2a0cf06e..e409841b6 100644 --- a/tests/TestClient.h +++ b/tests/TestClient.h @@ -43,11 +43,14 @@ class TestClient : public QXmppClient QCoreApplication::processEvents(); resetIdCount(); } - void expect(QString &&packet) { QVERIFY2(!m_sentPackets.empty(), "No packet was sent!"); - QCOMPARE(m_sentPackets.takeFirst().replace(u'\'', u'"'), packet.replace(u'\'', u'"')); + + auto expectedXml = rewriteXml(packet); + auto actualXml = rewriteXml(m_sentPackets.takeFirst()); + QCOMPARE(actualXml, expectedXml); + resetIdCount(); } QString takePacket() diff --git a/tests/util.h b/tests/util.h index 879a079a0..c59e29502 100644 --- a/tests/util.h +++ b/tests/util.h @@ -51,6 +51,29 @@ inline QDomElement xmlToDom(const String &xml) return doc.documentElement(); } +template +QString rewriteXml(const String &inputXml) +{ + QString outputXml; + QXmlStreamReader reader(inputXml); + QXmlStreamWriter writer(&outputXml); + while (reader.readNext() != QXmlStreamReader::EndDocument) { + if (reader.hasError()) { + qDebug() << "Parsing error:"; + qDebug().noquote() << inputXml; + qDebug().noquote() << reader.error() << reader.errorString(); + throw std::exception(); + } + + // do not generate '' + if (reader.tokenType() == QXmlStreamReader::StartDocument) { + continue; + } + writer.writeCurrentToken(reader); + } + return outputXml; +} + template static QByteArray packetToXml(const T &packet) {