summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/access
diff options
context:
space:
mode:
authorLena Biliaieva <lena.biliaieva@qt.io>2024-03-08 18:10:02 +0100
committerLena Biliaieva <lena.biliaieva@qt.io>2024-04-29 18:26:15 +0200
commitfa456ad5501dc74446329222d12ba0fa2ecd0457 (patch)
tree36814db3bb0fa48ebd26e2098df8927aeacaf3a8 /tests/auto/network/access
parent979836382e3721ff5fe47b6a94a68abd70ebbd2d (diff)
Add QHttpHeaders to QNetworkRequest
Added headers() and setHeaders() methods to QNetworkRequest. [ChangeLog][QtNetwork][QNetworkRequest] Added headers() and setHeaders() methods to QNetworkRequest, which provide an interface to work with QHttpHeaders. Task-number: QTBUG-107751 Change-Id: I2e1dc7cb2efab5903eb7ff23b75d01aefe13273d Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/network/access')
-rw-r--r--tests/auto/network/access/CMakeLists.txt1
-rw-r--r--tests/auto/network/access/qhttpheadershelper/CMakeLists.txt15
-rw-r--r--tests/auto/network/access/qhttpheadershelper/tst_qhttpheadershelper.cpp76
-rw-r--r--tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp29
4 files changed, 121 insertions, 0 deletions
diff --git a/tests/auto/network/access/CMakeLists.txt b/tests/auto/network/access/CMakeLists.txt
index 44b7d5c1bb..13703cf89c 100644
--- a/tests/auto/network/access/CMakeLists.txt
+++ b/tests/auto/network/access/CMakeLists.txt
@@ -15,6 +15,7 @@ add_subdirectory(qrestaccessmanager)
if(QT_FEATURE_private_tests)
add_subdirectory(qhttp2connection)
add_subdirectory(qhttpheaderparser)
+ add_subdirectory(qhttpheadershelper)
add_subdirectory(qhttpnetworkconnection)
add_subdirectory(qhttpnetworkreply)
add_subdirectory(hpack)
diff --git a/tests/auto/network/access/qhttpheadershelper/CMakeLists.txt b/tests/auto/network/access/qhttpheadershelper/CMakeLists.txt
new file mode 100644
index 0000000000..75935d2844
--- /dev/null
+++ b/tests/auto/network/access/qhttpheadershelper/CMakeLists.txt
@@ -0,0 +1,15 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qhttpheadershelper LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_qhttpheadershelper
+ SOURCES
+ tst_qhttpheadershelper.cpp
+ LIBRARIES
+ Qt::NetworkPrivate
+)
diff --git a/tests/auto/network/access/qhttpheadershelper/tst_qhttpheadershelper.cpp b/tests/auto/network/access/qhttpheadershelper/tst_qhttpheadershelper.cpp
new file mode 100644
index 0000000000..b204d0cbe3
--- /dev/null
+++ b/tests/auto/network/access/qhttpheadershelper/tst_qhttpheadershelper.cpp
@@ -0,0 +1,76 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QtNetwork/qhttpheaders.h>
+#include <QtNetwork/private/qhttpheadershelper_p.h>
+
+#include <QtTest/qtest.h>
+
+using namespace Qt::StringLiterals;
+
+class tst_QHttpHeadersHelper : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testCompareStrict();
+
+private:
+ static constexpr QAnyStringView n1{"name1"};
+ static constexpr QAnyStringView n2{"name2"};
+ static constexpr QAnyStringView v1{"value1"};
+ static constexpr QAnyStringView v2{"value2"};
+ static constexpr QAnyStringView N1{"NAME1"};
+ static constexpr QAnyStringView N2{"NAME2"};
+ static constexpr QAnyStringView V1{"VALUE1"};
+ static constexpr QAnyStringView V2{"VALUE2"};
+};
+
+void tst_QHttpHeadersHelper::testCompareStrict()
+{
+ using namespace QHttpHeadersHelper;
+
+ // Basic comparisons
+ QHttpHeaders h1;
+ QHttpHeaders h2;
+ QVERIFY(compareStrict(h1, h2)); // empties
+ h1.append(n1, v1);
+ QVERIFY(compareStrict(h1, h1)); // self
+ h2.append(n1, v1);
+ QVERIFY(compareStrict(h1, h2));
+ h1.append(n2, v2);
+ QVERIFY(!compareStrict(h1, h2));
+ h1.removeAll(n2);
+ QVERIFY(compareStrict(h1, h2));
+
+ // Order-sensitivity
+ h1.clear();
+ h2.clear();
+ // Same headers but in different order
+ h1.append(n1, v1);
+ h1.append(n2, v2);
+ h2.append(n2, v2);
+ h2.append(n1, v1);
+ QVERIFY(!compareStrict(h1, h2));
+
+ // Different number of headers
+ h1.clear();
+ h2.clear();
+ h1.append(n1, v1);
+ h2.append(n1, v1);
+ h2.append(n2, v2);
+ QVERIFY(!compareStrict(h1, h2));
+
+ // Same header name, multiple values
+ h1.clear();
+ h2.clear();
+ h1.append(n1, v1);
+ h1.append(n1, v2);
+ h2.append(n1, v1);
+ QVERIFY(!compareStrict(h1, h2));
+ h2.append(n1, v2);
+ QVERIFY(compareStrict(h1, h2));
+}
+
+QTEST_MAIN(tst_QHttpHeadersHelper)
+#include "tst_qhttpheadershelper.moc"
diff --git a/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp b/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
index bdef1115dd..ed978e6b0f 100644
--- a/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
+++ b/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
@@ -31,6 +31,8 @@ private slots:
void rawHeaderParsing_data();
void rawHeaderParsing();
void originatingObject();
+ void setHeaders_data();
+ void setHeaders();
void removeHeader();
};
@@ -552,5 +554,32 @@ void tst_QNetworkRequest::originatingObject()
QVERIFY(!request.originatingObject());
}
+void tst_QNetworkRequest::setHeaders_data()
+{
+ QTest::addColumn<QHttpHeaders>("h");
+ QTest::newRow("null") << QHttpHeaders();
+ QHttpHeaders headers;
+ headers.append("name1", "value1");
+ QTest::newRow("valid") << headers;
+}
+
+void tst_QNetworkRequest::setHeaders()
+{
+ QFETCH(QHttpHeaders, h);
+
+ QNetworkRequest r1;
+
+ auto result = r1.headers();
+ QVERIFY(result.isEmpty());
+
+ r1.setHeaders(h);
+ QCOMPARE(r1.headers().toListOfPairs(), h.toListOfPairs());
+
+ QNetworkRequest r2;
+ auto tmp = h;
+ r2.setHeaders(std::move(tmp));
+ QCOMPARE(r2.headers().toListOfPairs(), h.toListOfPairs());
+}
+
QTEST_MAIN(tst_QNetworkRequest)
#include "tst_qnetworkrequest.moc"