From a4ac49e2e3c69ba2d42558fbfb52eaa931ca8e28 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sun, 5 May 2019 14:55:21 +0200 Subject: Implement XEP-0363: HTTP File Upload: Error cases This extends the QXmppStanza::Error by the error cases defined in XEP-0363: HTTP File Upload in version 0.9.0. --- tests/qxmppstanza/tst_qxmppstanza.cpp | 69 +++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'tests') diff --git a/tests/qxmppstanza/tst_qxmppstanza.cpp b/tests/qxmppstanza/tst_qxmppstanza.cpp index 3b6c564e..22878557 100644 --- a/tests/qxmppstanza/tst_qxmppstanza.cpp +++ b/tests/qxmppstanza/tst_qxmppstanza.cpp @@ -32,6 +32,9 @@ class tst_QXmppStanza : public QObject private slots: void testExtendedAddress_data(); void testExtendedAddress(); + + void testErrorFileTooLarge(); + void testErrorRetry(); }; void tst_QXmppStanza::testExtendedAddress_data() @@ -74,5 +77,71 @@ void tst_QXmppStanza::testExtendedAddress() serializePacket(address, xml); } +void tst_QXmppStanza::testErrorFileTooLarge() +{ + const QByteArray xml( + "" + "" + "" + "File too large. The maximum file size is 20000 bytes" + "" + "" + "20000" + "" + "" + ); + + QXmppStanza::Error error; + parsePacket(error, xml); + QCOMPARE(error.type(), QXmppStanza::Error::Modify); + QCOMPARE(error.text(), QString("File too large. The maximum file size is " + "20000 bytes")); + QCOMPARE(error.condition(), QXmppStanza::Error::NotAcceptable); + QVERIFY(error.fileTooLarge()); + QCOMPARE(error.maxFileSize(), 20000); + serializePacket(error, xml); + + // test setters + error.setMaxFileSize(60000); + QCOMPARE(error.maxFileSize(), 60000); + error.setFileTooLarge(false); + QVERIFY(!error.fileTooLarge()); + + QXmppStanza::Error e2; + e2.setMaxFileSize(123000); + QVERIFY(e2.fileTooLarge()); +} + +void tst_QXmppStanza::testErrorRetry() +{ + const QByteArray xml( + "" + "" + "" + "Quota reached. You can only upload 5 files in 5 minutes" + "" + "" + "" + ); + + QXmppStanza::Error error; + parsePacket(error, xml); + QCOMPARE(error.type(), QXmppStanza::Error::Wait); + QCOMPARE(error.text(), QString("Quota reached. You can only upload 5 " + "files in 5 minutes")); + QCOMPARE(error.condition(), QXmppStanza::Error::ResourceConstraint); + QCOMPARE(error.retryDate(), QDateTime(QDate(2017, 12, 03), + QTime(23, 42, 05), Qt::UTC)); + serializePacket(error, xml); + + // test setter + error.setRetryDate(QDateTime(QDate(1985, 10, 26), QTime(1, 35))); + QCOMPARE(error.retryDate(), QDateTime(QDate(1985, 10, 26), QTime(1, 35))); +} + QTEST_MAIN(tst_QXmppStanza) #include "tst_qxmppstanza.moc" -- cgit v1.2.3