diff options
author | Juha Vuolle <juha.vuolle@qt.io> | 2024-01-10 13:37:53 +0200 |
---|---|---|
committer | Juha Vuolle <juha.vuolle@qt.io> | 2024-01-15 10:29:07 +0200 |
commit | 89dab8578c10ed4aee4e2f4b51e7c962d618c1eb (patch) | |
tree | d24bc0a7c441801f99f4918f1fde992e88eb0835 /tests/auto/network | |
parent | 2d9afc8501879a0ef39bc169cdf8d0b7fa9616f8 (diff) |
Remove HTTP headers equals() / comparison
There's several ways to compare HTTP headers, and arguably
the need for it is not very high. For the time being users can use
different accessors and compare in ways that make sense for
their use cases.
Consequently since HTTP headers are no longer trivially comparable,
it makes also comparing the request factories more 'moot' because
headers are a central piece of request information. So removed
comparison from request factory as well.
These comparisons can be restored later if a clear understanding
on it's need, and on how it should be best done, emerges.
Resulted from API-review
Pick-to: 6.7
Change-Id: Idb5ab3710268b52a8e59656db8cc7de82f0ae511
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'tests/auto/network')
-rw-r--r-- | tests/auto/network/access/qhttpheaders/tst_qhttpheaders.cpp | 90 | ||||
-rw-r--r-- | tests/auto/network/access/qnetworkrequestfactory/tst_qnetworkrequestfactory.cpp | 10 |
2 files changed, 16 insertions, 84 deletions
diff --git a/tests/auto/network/access/qhttpheaders/tst_qhttpheaders.cpp b/tests/auto/network/access/qhttpheaders/tst_qhttpheaders.cpp index 4a9b2c7fcf..3ce38aab97 100644 --- a/tests/auto/network/access/qhttpheaders/tst_qhttpheaders.cpp +++ b/tests/auto/network/access/qhttpheaders/tst_qhttpheaders.cpp @@ -14,7 +14,6 @@ class tst_QHttpHeaders : public QObject Q_OBJECT private slots: - void comparison(); void constructors(); void accessors(); void headerNameField(); @@ -36,71 +35,6 @@ private: static constexpr QAnyStringView V3{"VALUE3"}; }; -void tst_QHttpHeaders::comparison() -{ - // Basic comparisons - QHttpHeaders h1; - QHttpHeaders h2; - QVERIFY(h1.equals(h2)); // empties - h1.append(n1, v1); - QVERIFY(h1.equals(h1)); // self - h2.append(n1, v1); - QVERIFY(h1.equals(h2)); - h1.append(n2, v2); - QVERIFY(!h1.equals(h2)); - h1.removeAll(n2); - QVERIFY(h1.equals(h2)); - - // 'name' case-insensitivity and 'value' case-sensitivity - h1.removeAll(n1); - QVERIFY(h1.isEmpty()); - h1.append(N1, v1); - QVERIFY(h1.equals(h2)); - h1.removeAll(n1); - QVERIFY(h1.isEmpty()); - h1.append(n1, V1); - QVERIFY(!h1.equals(h2)); - - // Order-insensitivity - h1.clear(); - h2.clear(); - QVERIFY(h1.isEmpty() && h2.isEmpty()); - // Same headers but in different order - h1.append(n1, v1); - h1.append(n2, v2); - h2.append(n2, v2); - h2.append(n1, v1); - QVERIFY(h1.equals(h2)); - // Add header with different name casing - h1.insert(0, n1, v1); - h2.append(N1, v1); - QVERIFY(h1.equals(h2)); - // Add header with different value casing - h1.insert(0, n1, v1); - h2.append(n1, V1); - QVERIFY(!h1.equals(h2)); - - // Order-sensitivity - h1.clear(); - h2.clear(); - QVERIFY(h1.equals(h2, QHttpHeaders::CompareOption::OrderSensitive)); - // Same headers but in different order - h1.append(n1, v1); - h1.append(n2, v2); - h2.append(n2, v2); - h2.append(n1, v1); - QVERIFY(!h1.equals(h2, QHttpHeaders::CompareOption::OrderSensitive)); - - // Different number of headers - h1.clear(); - h2.clear(); - h1.append(n1, v1); - h2.append(n1, v1); - h2.append(n2, v2); - QVERIFY(!h1.equals(h2)); - QVERIFY(!h1.equals(h2, QHttpHeaders::CompareOption::OrderSensitive)); -} - void tst_QHttpHeaders::constructors() { // Default ctor @@ -109,38 +43,44 @@ void tst_QHttpHeaders::constructors() // Copy ctor QHttpHeaders h2(h1); - QVERIFY(h2.equals(h1)); + QCOMPARE(h2.toListOfPairs(), h1.toListOfPairs()); // Copy assignment QHttpHeaders h3; h3 = h1; - QVERIFY(h3.equals(h1)); + QCOMPARE(h3.toListOfPairs(), h1.toListOfPairs()); // Move assignment QHttpHeaders h4; h4 = std::move(h2); - QVERIFY(h4.equals(h1)); + QCOMPARE(h4.toListOfPairs(), h1.toListOfPairs()); // Move ctor QHttpHeaders h5(std::move(h4)); - QVERIFY(h5.equals(h1)); + QCOMPARE(h5.toListOfPairs(), h1.toListOfPairs()); // Constructors that are counterparts to 'toXXX()' conversion getters const QByteArray nb1{"name1"}; const QByteArray nb2{"name2"}; const QByteArray nv1{"value1"}; const QByteArray nv2{"value2"}; - // Initialize three QHttpHeaders with same content and verify they match + // Initialize three QHttpHeaders with similar content, and verify that they have + // similar header entries +#define CONTAINS_HEADER(NAME, VALUE) \ + QVERIFY(hlist.contains(NAME) && hmap.contains(NAME) && hhash.contains(NAME)); \ + QCOMPARE(hlist.combinedValue(NAME), VALUE); \ + QCOMPARE(hmap.combinedValue(NAME), VALUE); \ + QCOMPARE(hhash.combinedValue(NAME), VALUE); \ + QList<std::pair<QByteArray, QByteArray>> list{{nb1, nv1}, {nb2, nv2}, {nb2, nv2}}; QMultiMap<QByteArray, QByteArray> map{{nb1, nv1}, {nb2, nv2}, {nb2, nv2}}; QMultiHash<QByteArray, QByteArray> hash{{nb1, nv1}, {nb2, nv2}, {nb2, nv2}}; QHttpHeaders hlist = QHttpHeaders::fromListOfPairs(list); QHttpHeaders hmap = QHttpHeaders::fromMultiMap(map); QHttpHeaders hhash = QHttpHeaders::fromMultiHash(hash); - QVERIFY(hlist.contains(nb1) && hmap.contains(nb1) && hhash.contains(nb1)); - QVERIFY(!hlist.contains(n3) && !hmap.contains(n3) && !hhash.contains(n3)); - QVERIFY(hlist.equals(hmap)); - QVERIFY(hmap.equals(hhash)); + CONTAINS_HEADER(nb1, v1); + CONTAINS_HEADER(nb2, nv2 + "," + nv2) +#undef CONTAINS_HEADER } void tst_QHttpHeaders::accessors() diff --git a/tests/auto/network/access/qnetworkrequestfactory/tst_qnetworkrequestfactory.cpp b/tests/auto/network/access/qnetworkrequestfactory/tst_qnetworkrequestfactory.cpp index 7ea0e854ba..740b2ba10a 100644 --- a/tests/auto/network/access/qnetworkrequestfactory/tst_qnetworkrequestfactory.cpp +++ b/tests/auto/network/access/qnetworkrequestfactory/tst_qnetworkrequestfactory.cpp @@ -157,7 +157,6 @@ void tst_QNetworkRequestFactory::sslConfiguration() // Two initially equal factories QNetworkRequestFactory factory1{url1}; QNetworkRequestFactory factory2{url1}; - QCOMPARE(factory1, factory2); // Make two differing SSL configurations (for this test it's irrelevant how they differ) QSslConfiguration config1; @@ -171,9 +170,6 @@ void tst_QNetworkRequestFactory::sslConfiguration() factory2.setSslConfiguration(config2); QCOMPARE(factory2.sslConfiguration(), config2); - // Verify that the factories differ (different SSL config) - QCOMPARE_NE(factory1, factory2); - // Verify requests are set with appropriate SSL configs QNetworkRequest request1 = factory1.createRequest(); QCOMPARE(request1.sslConfiguration(), config1); @@ -310,13 +306,9 @@ void tst_QNetworkRequestFactory::operators() QCOMPARE(factory1.baseUrl(), url2); // changed QCOMPARE(factory2.baseUrl(), url1); // remains - // Comparison - QVERIFY(factory2 == factory4); // factory4 was copied + moved, and originates from factory2 - QVERIFY(factory1 != factory2); // factory1 url was changed - // Move ctor QNetworkRequestFactory factory5{std::move(factory4)}; - QVERIFY(factory5 == factory2); // the moved factory4 originates from factory2 + QCOMPARE(factory5.baseUrl(), factory2.baseUrl()); // the moved factory4 originates from factory2 QCOMPARE(factory5.baseUrl(), url1); } |