summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/access/qnetworkreply
diff options
context:
space:
mode:
authorMate Barany <mate.barany@qt.io>2023-11-14 15:10:38 +0100
committerMarc Mutz <marc.mutz@qt.io>2024-05-03 15:16:14 +0000
commit3377b74df903cdaa99b5d1c83680e13b78674a08 (patch)
treedcc37c7eb414fb9df05164c363f65505177358a4 /tests/auto/network/access/qnetworkreply
parentb64932ba82ebdb4d03815263570b7a9d2ea1dc92 (diff)
Add QDebug support to QHttpPart
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 <marc.mutz@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/network/access/qnetworkreply')
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp56
1 files changed, 56 insertions, 0 deletions
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<QByteArray>("header_data");
+ QTest::addColumn<QByteArray>("raw_header_data");
+ QTest::addColumn<QList<QByteArray>>("expected_header_values");
+ QTest::addColumn<bool>("overwrite");
+
+ QTest::newRow("header-data-set") << "form-data; name=\"prompt\""_ba << ""_ba
+ << (QList<QByteArray>() << "form-data; name=\"prompt\""_ba) << false;
+ QTest::newRow("raw-header-data-set") << ""_ba << "thisismykeyherebutnotreally"_ba
+ << (QList<QByteArray>() << "thisismykeyherebutnotreally"_ba) << false;
+ QTest::newRow("both-set") << "form-data; name=\"prompt\""_ba
+ << "thisismykeyherebutnotreally"_ba
+ << (QList<QByteArray>()
+ << "form-data; name=\"prompt\""_ba
+ << "thisismykeyherebutnotreally"_ba) << false;
+ QTest::newRow("overwrite") << "form-data; name=\"prompt\""_ba
+ << "thisismykeyherebutnotreally"_ba
+ << (QList<QByteArray>()
+ << "thisismykeyherebutnotreally"_ba
+ << "thisismykeyherebutnotreally"_ba) << true;
+}
+
+void tst_QNetworkReply::qhttpPartDebug()
+{
+ QFETCH(const QByteArray, header_data);
+ QFETCH(const QByteArray, raw_header_data);
+ QFETCH(const QList<QByteArray>, 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<QString>("proxyHost");