summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp')
-rw-r--r--tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp113
1 files changed, 40 insertions, 73 deletions
diff --git a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
index 10d7aa20f8..9460060dbf 100644
--- a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
+++ b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
@@ -1,33 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
#include <QtCore/QJsonArray>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
@@ -37,14 +11,17 @@
#include <QtNetwork/QNetworkRequest>
#if QT_CONFIG(topleveldomain)
#include "private/qtldurl_p.h"
-#include "private/qurltlds_p.h"
#endif
+#include <memory>
+
class tst_QNetworkCookieJar: public QObject
{
Q_OBJECT
private slots:
+ void initTestCase();
+
void getterSetter();
void setCookiesFromUrl_data();
void setCookiesFromUrl();
@@ -56,6 +33,8 @@ private slots:
#endif
void rfc6265_data();
void rfc6265();
+private:
+ QSharedPointer<QTemporaryDir> m_dataDir;
};
class MyCookieJar: public QNetworkCookieJar
@@ -83,6 +62,22 @@ void tst_QNetworkCookieJar::getterSetter()
QCOMPARE(jar.allCookies(), list);
}
+void tst_QNetworkCookieJar::initTestCase()
+{
+#if QT_CONFIG(topleveldomain) && QT_CONFIG(publicsuffix_system)
+ QString testDataDir;
+#ifdef BUILTIN_TESTDATA
+ m_dataDir = QEXTRACTTESTDATA("/testdata");
+ QVERIFY(m_dataDir);
+ testDataDir = m_dataDir->path() + "/testdata";
+#else
+ testDataDir = QFINDTESTDATA("testdata");
+#endif
+ qDebug() << "Test data dir:" << testDataDir;
+ qputenv("XDG_DATA_DIRS", QFile::encodeName(testDataDir));
+#endif
+}
+
void tst_QNetworkCookieJar::setCookiesFromUrl_data()
{
QTest::addColumn<QList<QNetworkCookie> >("preset");
@@ -241,7 +236,7 @@ void tst_QNetworkCookieJar::setCookiesFromUrl()
QFETCH(QList<QNetworkCookie>, preset);
QFETCH(QNetworkCookie, newCookie);
QFETCH(QString, referenceUrl);
- QFETCH(QList<QNetworkCookie>, expectedResult);
+ QFETCH(const QList<QNetworkCookie>, expectedResult);
QFETCH(bool, setCookies);
QList<QNetworkCookie> cookieList;
@@ -251,11 +246,11 @@ void tst_QNetworkCookieJar::setCookiesFromUrl()
QCOMPARE(jar.setCookiesFromUrl(cookieList, referenceUrl), setCookies);
QList<QNetworkCookie> result = jar.allCookies();
- foreach (QNetworkCookie cookie, expectedResult) {
+ for (const QNetworkCookie &cookie : expectedResult) {
QVERIFY2(result.contains(cookie), cookie.toRawForm());
result.removeAll(cookie);
}
- QVERIFY2(result.isEmpty(), QTest::toString(result));
+ QVERIFY2(result.isEmpty(), std::unique_ptr<char[]>(QTest::toString(result)).get());
}
void tst_QNetworkCookieJar::cookiesForUrl_data()
@@ -414,13 +409,11 @@ void tst_QNetworkCookieJar::effectiveTLDs_data()
QTest::newRow("yes1") << "com" << true;
QTest::newRow("yes2") << "de" << true;
- QTest::newRow("yes3") << "ulm.museum" << true;
QTest::newRow("yes4") << "krodsherad.no" << true;
QTest::newRow("yes5") << "1.bg" << true;
QTest::newRow("yes6") << "com.cn" << true;
QTest::newRow("yes7") << "org.ws" << true;
QTest::newRow("yes8") << "co.uk" << true;
- QTest::newRow("yes9") << "wallonie.museum" << true;
QTest::newRow("yes10") << "hk.com" << true;
QTest::newRow("yes11") << "hk.org" << true;
@@ -437,33 +430,23 @@ void tst_QNetworkCookieJar::effectiveTLDs_data()
QTest::newRow("no11") << "mosreg.ru" << false;
const char16_t s1[] = {0x74, 0x72, 0x61, 0x6e, 0xf8, 0x79, 0x2e, 0x6e, 0x6f, 0x00}; // xn--trany-yua.no
- const char16_t s2[] = {0x5d9, 0x5e8, 0x5d5, 0x5e9, 0x5dc, 0x5d9, 0x5dd, 0x2e, 0x6d, 0x75, 0x73, 0x65, 0x75, 0x6d, 0x00}; // xn--9dbhblg6di.museum
const char16_t s3[] = {0x7ec4, 0x7e54, 0x2e, 0x68, 0x6b, 0x00}; // xn--mk0axi.hk
const char16_t s4[] = {0x7f51, 0x7edc, 0x2e, 0x63, 0x6e, 0x00}; // xn--io0a7i.cn
const char16_t s5[] = {0x72, 0xe1, 0x68, 0x6b, 0x6b, 0x65, 0x72, 0xe1, 0x76, 0x6a, 0x75, 0x2e, 0x6e, 0x6f, 0x00}; // xn--rhkkervju-01af.no
const char16_t s6[] = {0xb9a, 0xbbf, 0xb99, 0xbcd, 0xb95, 0xbaa, 0xbcd, 0xbaa, 0xbc2, 0xbb0, 0xbcd, 0x00}; // xn--clchc0ea0b2g2a9gcd
const char16_t s7[] = {0x627, 0x644, 0x627, 0x631, 0x62f, 0x646, 0x00}; // xn--mgbayh7gpa
- const char16_t s8[] = {0x63, 0x6f, 0x72, 0x72, 0x65, 0x69, 0x6f, 0x73, 0x2d, 0x65, 0x2d, 0x74, 0x65, 0x6c, 0x65,
- 0x63, 0x6f, 0x6d, 0x75, 0x6e, 0x69, 0x63, 0x61, 0xe7, 0xf5, 0x65, 0x73, 0x2e, 0x6d, 0x75,
- 0x73, 0x65, 0x75, 0x6d, 0x00}; // xn--correios-e-telecomunicaes-ghc29a.museum
QTest::newRow("yes-specialchars1") << QString::fromUtf16(s1) << true;
- QTest::newRow("yes-specialchars2") << QString::fromUtf16(s2) << true;
QTest::newRow("yes-specialchars3") << QString::fromUtf16(s3) << true;
QTest::newRow("yes-specialchars4") << QString::fromUtf16(s4) << true;
QTest::newRow("yes-specialchars5") << QString::fromUtf16(s5) << true;
QTest::newRow("yes-specialchars6") << QString::fromUtf16(s6) << true;
QTest::newRow("yes-specialchars7") << QString::fromUtf16(s7) << true;
- QTest::newRow("yes-specialchars8") << QString::fromUtf16(s8) << true;
QTest::newRow("no-specialchars1") << QString::fromUtf16(s1).prepend("something") << false;
- QTest::newRow("no-specialchars2") << QString::fromUtf16(s2).prepend(QString::fromUtf16(s2)) << false;
- QTest::newRow("no-specialchars2.5") << QString::fromUtf16(s2).prepend("whatever") << false;
QTest::newRow("no-specialchars3") << QString::fromUtf16(s3).prepend("foo") << false;
QTest::newRow("no-specialchars4") << QString::fromUtf16(s4).prepend("bar") << false;
- QTest::newRow("no-specialchars5") << QString::fromUtf16(s5).prepend(QString::fromUtf16(s2)) << false;
QTest::newRow("no-specialchars6") << QString::fromUtf16(s6).prepend(QLatin1Char('.') + QString::fromUtf16(s6)) << false;
QTest::newRow("no-specialchars7") << QString::fromUtf16(s7).prepend("bla") << false;
- QTest::newRow("no-specialchars8") << QString::fromUtf16(s8).append("foo") << false;
QTest::newRow("exception1") << "pref.iwate.jp" << false;
QTest::newRow("exception2") << "omanpost.om" << false;
@@ -477,24 +460,8 @@ void tst_QNetworkCookieJar::effectiveTLDs_data()
QTest::newRow("no-wildcard3") << "whatever.uk" << false; // was changed at some point
QTest::newRow("yes-wildcard4") << "anything.sendai.jp" << true;
QTest::newRow("yes-wildcard5") << "foo.sch.uk" << true;
- QTest::newRow("yes-wildcard6") << "something.platform.sh" << true;
-
- int i;
- for (i = 0; tldIndices[i] < tldChunks[0]; i++) { }
- Q_ASSERT(i < tldCount);
- int TLDsInFirstChunk = i;
-
- const char *lastGroupFromFirstChunk = &tldData[0][tldIndices[TLDsInFirstChunk - 1]];
- QTest::addRow("lastGroupFromFirstChunk: %s", lastGroupFromFirstChunk)
- << lastGroupFromFirstChunk
- << true;
-
- Q_ASSERT(tldChunkCount > 1); // There are enough TLDs to fill 64K bytes
- const char *lastGroupFromLastChunk =
- &tldData[tldChunkCount-1][tldIndices[tldCount - 1] - tldChunks[tldChunkCount - 2]];
- QTest::addRow("lastGroupFromLastChunk: %s", lastGroupFromLastChunk)
- << lastGroupFromLastChunk
- << true;
+ QTest::newRow("yes-platform.sh") << "eu.platform.sh" << true;
+ QTest::newRow("no-platform.sh") << "something.platform.sh" << false;
}
void tst_QNetworkCookieJar::effectiveTLDs()
@@ -518,7 +485,7 @@ void tst_QNetworkCookieJar::rfc6265_data()
QVERIFY(!document.isNull());
QVERIFY(document.isArray());
- foreach (const QJsonValue& testCase, document.array()) {
+ for (const QJsonValue testCase : document.array()) {
QJsonObject testObject = testCase.toObject();
//"test" - the test case name
@@ -527,15 +494,15 @@ void tst_QNetworkCookieJar::rfc6265_data()
continue;
//"received" - the cookies received from the server
- QJsonArray received = testObject.value("received").toArray();
+ const QJsonArray received = testObject.value("received").toArray();
QStringList receivedList;
- foreach (const QJsonValue& receivedCookie, received)
+ for (const QJsonValue receivedCookie : received)
receivedList.append(receivedCookie.toString());
//"sent" - the cookies sent back to the server
- QJsonArray sent = testObject.value("sent").toArray();
+ const QJsonArray sent = testObject.value("sent").toArray();
QList<QNetworkCookie> sentList;
- foreach (const QJsonValue& sentCookie, sent) {
+ for (const QJsonValue sentCookie : sent) {
QJsonObject sentCookieObject = sentCookie.toObject();
QNetworkCookie cookie;
cookie.setName(sentCookieObject.value("name").toString().toUtf8());
@@ -550,7 +517,7 @@ void tst_QNetworkCookieJar::rfc6265_data()
void tst_QNetworkCookieJar::rfc6265()
{
- QFETCH(QStringList, received);
+ QFETCH(const QStringList, received);
QFETCH(QList<QNetworkCookie>, sent);
QFETCH(QString, sentTo);
@@ -561,16 +528,16 @@ void tst_QNetworkCookieJar::rfc6265()
QNetworkCookieJar jar;
QList<QNetworkCookie> receivedCookies;
- foreach (const QString &cookieLine, received)
+ for (const QString &cookieLine : received)
receivedCookies.append(QNetworkCookie::parseCookies(cookieLine.toUtf8()));
jar.setCookiesFromUrl(receivedCookies, receivedUrl);
QList<QNetworkCookie> cookiesToSend = jar.cookiesForUrl(sentUrl);
//compare cookies only using name/value, as the metadata isn't sent over the network
- QCOMPARE(cookiesToSend.count(), sent.count());
+ QCOMPARE(cookiesToSend.size(), sent.size());
bool ok = true;
- for (int i = 0; i < cookiesToSend.count(); i++) {
+ for (int i = 0; i < cookiesToSend.size(); i++) {
if (cookiesToSend.at(i).name() != sent.at(i).name()) {
ok = false;
break;