From 2b63b9ce2b7e369ccf3e8365864ec2d4522db26e Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 4 Jul 2020 16:34:59 +0200 Subject: tests: util: Add xmlToDom() helper --- tests/util.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/util.h b/tests/util.h index 61f50ee7..7711518e 100644 --- a/tests/util.h +++ b/tests/util.h @@ -4,6 +4,7 @@ * Authors: * Jeremy Lainé * Manjeet Dahiya + * Linus Jahn * * Source: * https://github.com/qxmpp-project/qxmpp @@ -27,14 +28,23 @@ #include #include +// QVERIFY2 with empty return value (return {};) +#define QVERIFY_RV(statement, description) \ + if (!QTest::qVerify(statement, #statement, description, __FILE__, __LINE__)) \ + return {}; + +QDomElement xmlToDom(const QByteArray &xml) +{ + QDomDocument doc; + QVERIFY_RV(doc.setContent(xml, true), "XML is not valid"); + return doc.documentElement(); +} + template static void parsePacket(T &packet, const QByteArray &xml) { //qDebug() << "parsing" << xml; - QDomDocument doc; - QCOMPARE(doc.setContent(xml, true), true); - QDomElement element = doc.documentElement(); - packet.parse(element); + packet.parse(xmlToDom(xml)); } template -- cgit v1.2.3