From 9c8fea86564712aca4363bb1ebe5fd227eff188f Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 19 Jan 2019 18:06:56 +0100 Subject: Implement XEP-0363: HTTP File Upload: Request/Slot IQs This implements the IQs for requesting and receiving upload slots as defined by XEP-0363: HTTP File Upload in version 0.9.0. --- tests/CMakeLists.txt | 1 + tests/qxmpphttpuploadiq/tst_qxmpphttpuploadiq.cpp | 172 ++++++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 tests/qxmpphttpuploadiq/tst_qxmpphttpuploadiq.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 794cd609..9984af9c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,6 +21,7 @@ add_simple_test(qxmppcarbonmanager) add_simple_test(qxmppdataform) add_simple_test(qxmppdiscoveryiq) add_simple_test(qxmppentitytimeiq) +add_simple_test(qxmpphttpuploadiq) add_simple_test(qxmppiceconnection) add_simple_test(qxmppiq) add_simple_test(qxmppjingleiq) diff --git a/tests/qxmpphttpuploadiq/tst_qxmpphttpuploadiq.cpp b/tests/qxmpphttpuploadiq/tst_qxmpphttpuploadiq.cpp new file mode 100644 index 00000000..d88a113c --- /dev/null +++ b/tests/qxmpphttpuploadiq/tst_qxmpphttpuploadiq.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2008-2019 The QXmpp developers + * + * Author: + * Linus Jahn + * + * Source: + * https://github.com/qxmpp-project/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#include +#include "QXmppHttpUploadIq.h" +#include "util.h" + +class tst_QXmppHttpUploadIq : public QObject +{ + Q_OBJECT + +private slots: + void testRequest(); + void testIsRequest_data(); + void testIsRequest(); + void testSlot(); + void testIsSlot_data(); + void testIsSlot(); +}; + +void tst_QXmppHttpUploadIq::testRequest() +{ + const QByteArray xml( + "" + "" + "" + ); + + QXmppHttpUploadRequestIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.fileName(), QString("très cool.jpg")); + QCOMPARE(iq.size(), 23456); + QCOMPARE(iq.contentType().name(), QString("image/jpeg")); + serializePacket(iq, xml); + + // test setters + iq.setFileName("icon.png"); + QCOMPARE(iq.fileName(), QString("icon.png")); + iq.setSize(23421337); + QCOMPARE(iq.size(), 23421337); + iq.setContentType(QMimeDatabase().mimeTypeForName("image/png")); + QCOMPARE(iq.contentType().name(), QString("image/png")); +} + +void tst_QXmppHttpUploadIq::testIsRequest_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("isRequest"); + + QTest::newRow("wrong-stanza") + << QByteArray("") + << false; + QTest::newRow("empty-iq") + << QByteArray("") + << false; + QTest::newRow("wrong-ns") + << QByteArray("") + << false; + QTest::newRow("correct") + << QByteArray("") + << true; +} + +void tst_QXmppHttpUploadIq::testIsRequest() +{ + QFETCH(QByteArray, xml); + QFETCH(bool, isRequest); + + QDomDocument doc; + QCOMPARE(doc.setContent(xml, true), true); + QCOMPARE(QXmppHttpUploadRequestIq::isHttpUploadRequestIq(doc.documentElement()), isRequest); +} + +void tst_QXmppHttpUploadIq::testSlot() +{ + const QByteArray xml( + "" + "" + "" + "
Basic Base64String==
" + "
foo=bar; user=romeo
" + "
" + "" + "
" + "
" + ); + + QXmppHttpUploadSlotIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.putUrl(), QUrl("https://upload.montague.tld/4a771ac1-f0b2-4a4a" + "-9700-f2a26fa2bb67/tr%C3%A8s%20cool.jpg")); + QCOMPARE(iq.getUrl(), QUrl("https://download.montague.tld/4a771ac1-f0b2-4a" + "4a-9700-f2a26fa2bb67/tr%C3%A8s%20cool.jpg")); + QMap headers; + headers["Authorization"] = "Basic Base64String=="; + headers["Cookie"] = "foo=bar; user=romeo"; + QCOMPARE(iq.putHeaders(), headers); + serializePacket(iq, xml); + + // test setters + iq.setGetUrl(QUrl("https://dl.example.org/user/file")); + QCOMPARE(iq.getUrl(), QUrl("https://dl.example.org/user/file")); + iq.setPutUrl(QUrl("https://ul.example.org/user/file")); + QCOMPARE(iq.putUrl(), QUrl("https://ul.example.org/user/file")); + QMap emptyMap; + iq.setPutHeaders(emptyMap); + QCOMPARE(iq.putHeaders(), emptyMap); + +} + +void tst_QXmppHttpUploadIq::testIsSlot_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("isSlot"); + + QTest::newRow("wrong-stanza") + << QByteArray("") + << false; + QTest::newRow("empty-iq") + << QByteArray("") + << false; + QTest::newRow("wrong-ns") + << QByteArray("") + << false; + QTest::newRow("correct") + << QByteArray("") + << true; +} + +void tst_QXmppHttpUploadIq::testIsSlot() +{ + QFETCH(QByteArray, xml); + QFETCH(bool, isSlot); + + QDomDocument doc; + QCOMPARE(doc.setContent(xml, true), true); + QCOMPARE(QXmppHttpUploadSlotIq::isHttpUploadSlotIq(doc.documentElement()), isSlot); +} + +QTEST_MAIN(tst_QXmppHttpUploadIq) +#include "tst_qxmpphttpuploadiq.moc" -- cgit v1.2.3