From 3377b74df903cdaa99b5d1c83680e13b78674a08 Mon Sep 17 00:00:00 2001 From: Mate Barany Date: Tue, 14 Nov 2023 15:10:38 +0100 Subject: Add QDebug support to QHttpPart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As part of QTBUG-114647 we are planning to introduce a deduction mechanism that could deduce the contentType header and the contentDisposition headers based on the arguments (and the MIME database). In case of non-trivial types this deduction may give the wrong result and without QDebug support it might be a bit tedious to check. The debug output displays some information about the body device if one is attached, otherwise it displays the size of the body. Task-number: QTBUG-114647 Change-Id: Ia693b078ff5b9f8ea57fbf3c385edaec47886ff1 Reviewed-by: Marc Mutz Reviewed-by: MÃ¥rten Nordheim --- .../access/qnetworkreply/tst_qnetworkreply.cpp | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'tests/auto/network/access/qnetworkreply') diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index a4a05b18f5..66cbeaac9b 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -560,6 +560,9 @@ private Q_SLOTS: void notFoundWithCompression_data(); void notFoundWithCompression(); + void qhttpPartDebug_data(); + void qhttpPartDebug(); + void qtbug68821proxyError_data(); void qtbug68821proxyError(); @@ -10479,6 +10482,59 @@ void tst_QNetworkReply::notFoundWithCompression() QCOMPARE(reply->readAll(), expected); } +void tst_QNetworkReply::qhttpPartDebug_data() +{ + QTest::addColumn("header_data"); + QTest::addColumn("raw_header_data"); + QTest::addColumn>("expected_header_values"); + QTest::addColumn("overwrite"); + + QTest::newRow("header-data-set") << "form-data; name=\"prompt\""_ba << ""_ba + << (QList() << "form-data; name=\"prompt\""_ba) << false; + QTest::newRow("raw-header-data-set") << ""_ba << "thisismykeyherebutnotreally"_ba + << (QList() << "thisismykeyherebutnotreally"_ba) << false; + QTest::newRow("both-set") << "form-data; name=\"prompt\""_ba + << "thisismykeyherebutnotreally"_ba + << (QList() + << "form-data; name=\"prompt\""_ba + << "thisismykeyherebutnotreally"_ba) << false; + QTest::newRow("overwrite") << "form-data; name=\"prompt\""_ba + << "thisismykeyherebutnotreally"_ba + << (QList() + << "thisismykeyherebutnotreally"_ba + << "thisismykeyherebutnotreally"_ba) << true; +} + +void tst_QNetworkReply::qhttpPartDebug() +{ + QFETCH(const QByteArray, header_data); + QFETCH(const QByteArray, raw_header_data); + QFETCH(const QList, expected_header_values); + QFETCH(bool, overwrite); + + QHttpPart httpPart; + + if (!header_data.isEmpty()) + httpPart.setHeader(QNetworkRequest::ContentDispositionHeader, header_data); + + if (!raw_header_data.isEmpty()) + httpPart.setRawHeader("Authorization", raw_header_data); + + if (overwrite) + httpPart.setRawHeader("Content-Disposition", raw_header_data); + + QByteArray msg; + { + QBuffer buf(&msg); + QVERIFY(buf.open(QIODevice::WriteOnly)); + QDebug debug(&buf); + debug << httpPart; + } + + for (const auto &value : expected_header_values) + QVERIFY2(msg.contains(value), "Missing header value: " + value); +} + void tst_QNetworkReply::qtbug68821proxyError_data() { QTest::addColumn("proxyHost"); -- cgit v1.2.3