From a34484064de3dab3a244f25babac856526519ebe Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Tue, 31 Mar 2020 18:07:33 +0200 Subject: Add tests for QXmppStanza::Error parsing --- tests/qxmppstanza/tst_qxmppstanza.cpp | 169 ++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) (limited to 'tests') diff --git a/tests/qxmppstanza/tst_qxmppstanza.cpp b/tests/qxmppstanza/tst_qxmppstanza.cpp index e536042b..05522d3d 100644 --- a/tests/qxmppstanza/tst_qxmppstanza.cpp +++ b/tests/qxmppstanza/tst_qxmppstanza.cpp @@ -34,6 +34,8 @@ private slots: void testExtendedAddress_data(); void testExtendedAddress(); + void testErrorCases_data(); + void testErrorCases(); void testErrorFileTooLarge(); void testErrorRetry(); }; @@ -78,6 +80,173 @@ void tst_QXmppStanza::testExtendedAddress() serializePacket(address, xml); } +void tst_QXmppStanza::testErrorCases_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("type"); + QTest::addColumn("condition"); + QTest::addColumn("text"); + +#define ROW(xml, type, condition, text) \ + QTest::newRow(QT_STRINGIFY(condition)) << QByteArrayLiteral(xml) << QXmppStanza::Error::type << QXmppStanza::Error::condition << text +#define BASIC(xml, type, condition) \ + ROW(xml, type, condition, QString()) + + ROW( + "" + "" + "", + Modify, + BadRequest, + ""); + BASIC( + "" + "" + "", + Cancel, + Conflict); + BASIC( + "" + "" + "", + Cancel, + FeatureNotImplemented); + BASIC( + "" + "" + "", + Auth, + Forbidden); + BASIC( + "" + "" + "", + Cancel, + Gone); + BASIC( + "" + "" + "", + Cancel, + InternalServerError); + BASIC( + "" + "" + "", + Cancel, + ItemNotFound); + BASIC( + "" + "" + "", + Modify, + JidMalformed); + BASIC( + "" + "" + "", + Modify, + NotAcceptable); + BASIC( + "" + "" + "", + Cancel, + NotAllowed); + BASIC( + "" + "" + "", + Auth, + NotAuthorized); + ROW( + "" + "" + "The used words are not allowed on this server." + "", + Modify, + PolicyViolation, + "The used words are not allowed on this server."); + BASIC( + "" + "" + "", + Wait, + RecipientUnavailable); + BASIC( + "" + "" + "", + Modify, + Redirect); + BASIC( + "" + "" + "", + Auth, + RegistrationRequired); + BASIC( + "" + "" + "", + Cancel, + RemoteServerNotFound); + BASIC( + "" + "" + "", + Wait, + RemoteServerTimeout); + BASIC( + "" + "" + "", + Wait, + ResourceConstraint); + BASIC( + "" + "" + "", + Cancel, + ServiceUnavailable); + BASIC( + "" + "" + "", + Auth, + SubscriptionRequired); + BASIC( + "" + "" + "", + Modify, + UndefinedCondition); +} + +void tst_QXmppStanza::testErrorCases() +{ + QFETCH(QByteArray, xml); + QFETCH(QXmppStanza::Error::Type, type); + QFETCH(QXmppStanza::Error::Condition, condition); + QFETCH(QString, text); + + // parsing + QXmppStanza::Error error; + parsePacket(error, xml); + QCOMPARE(error.type(), type); + QCOMPARE(error.condition(), condition); + QCOMPARE(error.text(), text); + // check parsed error results in the same xml + serializePacket(error, xml); + + // serialization from setters + error = QXmppStanza::Error(); + error.setType(type); + error.setCondition(condition); + error.setText(text); + serializePacket(error, xml); +} + void tst_QXmppStanza::testErrorFileTooLarge() { const QByteArray xml( -- cgit v1.2.3