summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qurl/tst_qurl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qurl/tst_qurl.cpp')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp444
1 files changed, 234 insertions, 210 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index ef4325d2ea..2024968435 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -1,44 +1,23 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** 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$
-**
-****************************************************************************/
-
-#define QT_DEPRECATED
-#define QT_DISABLE_DEPRECATED_BEFORE 0
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
#include <qurl.h>
-#include <QtTest/QtTest>
#include <QtCore/QDebug>
+#include <QTest>
+#include <QtTest/private/qcomparisontesthelper_p.h>
+#include <QDirIterator>
+
#include <qcoreapplication.h>
#include <qfileinfo.h>
-#include <qtextcodec.h>
#include <qmap.h>
+#include <QtTest/private/qemulationdetector_p.h>
+
+using namespace Qt::StringLiterals;
+
Q_DECLARE_METATYPE(QUrl::FormattingOptions)
class tst_QUrl : public QObject
@@ -48,13 +27,12 @@ class tst_QUrl : public QObject
private slots:
void initTestCase();
void cleanupTestCase();
- void effectiveTLDs_data();
- void effectiveTLDs();
void getSetCheck();
void constructing();
void hashInPath();
void unc();
void assignment();
+ void orderingCompiles();
void comparison();
void comparison2_data();
void comparison2();
@@ -70,6 +48,8 @@ private slots:
void toString_PreferLocalFile();
void toString_constructed_data();
void toString_constructed();
+ void toDisplayString_PreferLocalFile_data();
+ void toDisplayString_PreferLocalFile();
void toAndFromStringList_data();
void toAndFromStringList();
void isParentOf_data();
@@ -311,6 +291,11 @@ void tst_QUrl::assignment()
QCOMPARE(url, copy);
}
+void tst_QUrl::orderingCompiles()
+{
+ QTestPrivate::testAllComparisonOperatorsCompile<QUrl>();
+}
+
void tst_QUrl::comparison()
{
QUrl url1("http://qt-project.org/");
@@ -459,18 +444,19 @@ void tst_QUrl::comparison2()
QFETCH(QUrl, url2);
QFETCH(int, ordering);
+ const Qt::weak_ordering expectedOrdering = [&ordering] {
+ if (ordering > 0)
+ return Qt::weak_ordering::greater;
+ else if (ordering < 0)
+ return Qt::weak_ordering::less;
+ return Qt::weak_ordering::equivalent;
+ }();
+
QCOMPARE(url1.toString() == url2.toString(), ordering == 0);
- QCOMPARE(url1 == url2, ordering == 0);
- QCOMPARE(url1 != url2, ordering != 0);
+ QT_TEST_ALL_COMPARISON_OPS(url1, url2, expectedOrdering);
if (ordering == 0)
QCOMPARE(qHash(url1), qHash(url2));
- QCOMPARE(url1 < url2, ordering < 0);
- QCOMPARE(!(url1 < url2), ordering >= 0);
-
- QCOMPARE(url2 < url1, ordering > 0);
- QCOMPARE(!(url2 < url1), ordering <= 0);
-
// redundant checks (the above should catch these)
QCOMPARE(url1 < url2 || url2 < url1, ordering != 0);
QVERIFY(!(url1 < url2 && url2 < url1));
@@ -1112,7 +1098,7 @@ void tst_QUrl::toAndFromStringList()
QFETCH(QStringList, strings);
const QList<QUrl> urls = QUrl::fromStringList(strings);
- QCOMPARE(urls.count(), strings.count());
+ QCOMPARE(urls.size(), strings.size());
const QStringList converted = QUrl::toStringList(urls);
QCOMPARE(converted, strings);
}
@@ -1210,6 +1196,32 @@ void tst_QUrl::toString_constructed()
QCOMPARE(url.toEncoded(formattingOptions), asEncoded);
}
+void tst_QUrl::toDisplayString_PreferLocalFile_data()
+{
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QString>("string");
+
+ QTest::newRow("basic") << QUrl::fromLocalFile("/home/charles/foomoo")
+ << QString::fromLatin1("/home/charles/foomoo");
+ QTest::newRow("with%") << QUrl::fromLocalFile("/home/charles/foo%20moo")
+ << QString::fromLatin1("/home/charles/foo%20moo");
+ QTest::newRow("non-local") << QUrl("file://host/foo")
+ << QString::fromLatin1("//host/foo");
+ QTest::newRow("query-and-fragment") << QUrl("file://user:pass@example.org/a?b=c%20d%23e#frag%23ment")
+ << QString::fromLatin1("file://user@example.org/a?b=c d%23e#frag%23ment");
+ QTest::newRow("http") << QUrl("http://user:pass@example.org/a?b=c%20d%23e#frag%23ment")
+ << QString::fromLatin1("http://user@example.org/a?b=c d%23e#frag%23ment");
+}
+
+void tst_QUrl::toDisplayString_PreferLocalFile()
+{
+ QFETCH(QUrl, url);
+ QFETCH(QString, string);
+
+ if (url.isLocalFile() && url.query().isEmpty() && url.fragment().isEmpty())
+ QCOMPARE(url.toLocalFile(), string);
+ QCOMPARE(url.toDisplayString(QUrl::PreferLocalFile), string);
+}
void tst_QUrl::isParentOf()
{
@@ -1226,38 +1238,43 @@ void tst_QUrl::toLocalFile_data()
QTest::addColumn<QString>("theUrl");
QTest::addColumn<QString>("theFile");
- QTest::newRow("data0") << QString::fromLatin1("file:/a.txt") << QString::fromLatin1("/a.txt");
- QTest::newRow("data4") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("/a.txt");
- QTest::newRow("data4a") << QString::fromLatin1("webdavs://somewebdavhost/somedir/somefile")
+ QTest::newRow("file:/") << QString::fromLatin1("file:/a.txt") << QString::fromLatin1("/a.txt");
+ QTest::newRow("file:///") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("/a.txt");
+ QTest::newRow("file:////") << QString::fromLatin1("file:////somehost/somedir/somefile") << QString::fromLatin1("//somehost/somedir/somefile");
+ QTest::newRow("FILE:/") << QString::fromLatin1("FILE:/a.txt") << QString::fromLatin1("/a.txt");
+
+ QTest::newRow("path-delimiter") << QString::fromLatin1("file:///Mambo <%235>.mp3") << QString::fromLatin1("/Mambo <#5>.mp3");
+ QTest::newRow("path-percent") << QString::fromLatin1("file:///a%25.txt") << QString::fromLatin1("/a%.txt");
+ QTest::newRow("path-percent-percent") << QString::fromLatin1("file:///a%25%25.txt") << QString::fromLatin1("/a%%.txt");
+ QTest::newRow("path-percent-a-percent") << QString::fromLatin1("file:///a%25a%25.txt") << QString::fromLatin1("/a%a%.txt");
+ QTest::newRow("path-control-char") << QString::fromLatin1("file:///a%1f.txt") << QString::fromLatin1("/a\x1f.txt");
+ QTest::newRow("path-percent-hex-hex") << QString::fromLatin1("file:///%2580.txt") << QString::fromLatin1("/%80.txt");
+
+ QTest::newRow("webdavs") << QString::fromLatin1("webdavs://somewebdavhost/somedir/somefile")
#ifdef Q_OS_WIN // QTBUG-42346, WebDAV is visible as local file on Windows only.
- << QString::fromLatin1("//somewebdavhost@SSL/somedir/somefile");
+ << QString::fromLatin1("//somewebdavhost@SSL/somedir/somefile");
#else
- << QString();
+ << QString();
#endif
#ifdef Q_OS_WIN
- QTest::newRow("data5") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("c:/a.txt");
+ QTest::newRow("windows-drive-absolute") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("c:/a.txt");
#else
- QTest::newRow("data5") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("/c:/a.txt");
+ QTest::newRow("windows-drive-absolute") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("/c:/a.txt");
#endif
- QTest::newRow("data6") << QString::fromLatin1("file://somehost/somedir/somefile") << QString::fromLatin1("//somehost/somedir/somefile");
- QTest::newRow("data7") << QString::fromLatin1("file://somehost/") << QString::fromLatin1("//somehost/");
- QTest::newRow("data8") << QString::fromLatin1("file://somehost") << QString::fromLatin1("//somehost");
- QTest::newRow("data9") << QString::fromLatin1("file:////somehost/somedir/somefile") << QString::fromLatin1("//somehost/somedir/somefile");
- QTest::newRow("data10") << QString::fromLatin1("FILE:/a.txt") << QString::fromLatin1("/a.txt");
- QTest::newRow("data11") << QString::fromLatin1("file:///Mambo <%235>.mp3") << QString::fromLatin1("/Mambo <#5>.mp3");
- QTest::newRow("data12") << QString::fromLatin1("file:///a%25.txt") << QString::fromLatin1("/a%.txt");
- QTest::newRow("data13") << QString::fromLatin1("file:///a%25%25.txt") << QString::fromLatin1("/a%%.txt");
- QTest::newRow("data14") << QString::fromLatin1("file:///a%25a%25.txt") << QString::fromLatin1("/a%a%.txt");
- QTest::newRow("data15") << QString::fromLatin1("file:///a%1f.txt") << QString::fromLatin1("/a\x1f.txt");
- QTest::newRow("data16") << QString::fromLatin1("file:///%2580.txt") << QString::fromLatin1("/%80.txt");
+ QTest::newRow("windows-unc-path") << QString::fromLatin1("file://somehost/somedir/somefile") << QString::fromLatin1("//somehost/somedir/somefile");
+ QTest::newRow("windows-unc-root") << QString::fromLatin1("file://somehost/") << QString::fromLatin1("//somehost/");
+ QTest::newRow("windows-unc-nopath") << QString::fromLatin1("file://somehost") << QString::fromLatin1("//somehost");
+ QTest::newRow("windows-extlen-path") << QString::fromLatin1("file:////%3F/somedir/somefile") << QString::fromLatin1("//?/somedir/somefile");
+ QTest::newRow("windows-wsl-path") << QString::fromLatin1("file:////wsl$/somedir/somefile") << QString::fromLatin1("//wsl$/somedir/somefile");
+ QTest::newRow("windows-device-path") << QString::fromLatin1("file:////./somedir/somefile") << QString::fromLatin1("//./somedir/somefile");
// and some that result in empty (i.e., not local)
- QTest::newRow("xdata0") << QString::fromLatin1("/a.txt") << QString();
- QTest::newRow("xdata1") << QString::fromLatin1("//a.txt") << QString();
- QTest::newRow("xdata2") << QString::fromLatin1("///a.txt") << QString();
- QTest::newRow("xdata3") << QString::fromLatin1("foo:/a.txt") << QString();
- QTest::newRow("xdata4") << QString::fromLatin1("foo://a.txt") << QString();
- QTest::newRow("xdata5") << QString::fromLatin1("foo:///a.txt") << QString();
+ QTest::newRow("noscheme-absolute") << QString::fromLatin1("/a.txt") << QString();
+ QTest::newRow("noscheme-host") << QString::fromLatin1("//a.txt") << QString();
+ QTest::newRow("noscheme-host-path") << QString::fromLatin1("///a.txt") << QString();
+ QTest::newRow("fooscheme-absolute") << QString::fromLatin1("foo:/a.txt") << QString();
+ QTest::newRow("fooscheme-host") << QString::fromLatin1("foo://a.txt") << QString();
+ QTest::newRow("fooscheme-host-path") << QString::fromLatin1("foo:///a.txt") << QString();
}
void tst_QUrl::toLocalFile()
@@ -1276,21 +1293,57 @@ void tst_QUrl::fromLocalFile_data()
QTest::addColumn<QString>("theUrl");
QTest::addColumn<QString>("thePath");
- QTest::newRow("data0") << QString::fromLatin1("/a.txt") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("/a.txt");
- QTest::newRow("data1") << QString::fromLatin1("a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt");
- QTest::newRow("data2") << QString::fromLatin1("/a/b.txt") << QString::fromLatin1("file:///a/b.txt") << QString::fromLatin1("/a/b.txt");
- QTest::newRow("data3") << QString::fromLatin1("c:/a.txt") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("/c:/a.txt");
- QTest::newRow("data4") << QString::fromLatin1("//somehost/somedir/somefile") << QString::fromLatin1("file://somehost/somedir/somefile")
- << QString::fromLatin1("/somedir/somefile");
- QTest::newRow("data4a") << QString::fromLatin1("//somewebdavhost@SSL/somedir/somefile")
- << QString::fromLatin1("webdavs://somewebdavhost/somedir/somefile")
- << QString::fromLatin1("/somedir/somefile");
- QTest::newRow("data5") << QString::fromLatin1("//somehost") << QString::fromLatin1("file://somehost")
- << QString::fromLatin1("");
- QTest::newRow("data6") << QString::fromLatin1("//somehost/") << QString::fromLatin1("file://somehost/")
- << QString::fromLatin1("/");
- QTest::newRow("data7") << QString::fromLatin1("/Mambo <#5>.mp3") << QString::fromLatin1("file:///Mambo <%235>.mp3")
- << QString::fromLatin1("/Mambo <#5>.mp3");
+ QTest::newRow("absolute-path") << QString::fromLatin1("/a.txt") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("/a.txt");
+ QTest::newRow("relative-path") << QString::fromLatin1("a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt");
+ QTest::newRow("absolute-two-path") << QString::fromLatin1("/a/b.txt") << QString::fromLatin1("file:///a/b.txt") << QString::fromLatin1("/a/b.txt");
+ QTest::newRow("path-delimiters") << QString::fromLatin1("/Mambo <#5>.mp3") << QString::fromLatin1("file:///Mambo <%235>.mp3")
+ << QString::fromLatin1("/Mambo <#5>.mp3");
+
+ // Windows absolute details
+ QTest::newRow("windows-drive") << QString::fromLatin1("c:/a.txt") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("/c:/a.txt");
+
+ // Windows UNC paths
+ for (const char *suffix : { "", "/", "/somedir/somefile" }) {
+ const char *pathDescription =
+ strlen(suffix) == 0 ? "nopath" :
+ strlen(suffix) > 1 ? "path" : "root";
+
+ QTest::addRow("windows-unc-%s", pathDescription)
+ << QString("//somehost") + suffix
+ << QString("file://somehost") + suffix
+ << QString(suffix);
+#ifdef Q_OS_WIN32
+ // debackslashification only happens on Windows
+ QString suffixWithBackslashes(suffix);
+ suffixWithBackslashes.replace('/', '\\');
+
+ QTest::addRow("windows-backslash-unc-%s", pathDescription)
+ << QString(QString("\\\\somehost") + suffixWithBackslashes)
+ << QString("file://somehost") + suffix
+ << QString(suffix);
+ QTest::addRow("windows-backslash-extlen-%s", pathDescription)
+ << QString(QString("\\\\?") + suffixWithBackslashes)
+ << QString("file:////%3F") + suffix
+ << QString("//?") + suffix;
+#endif
+ QTest::addRow("windows-extlen-%s", pathDescription)
+ << QString("//?") + suffix
+ << QString("file:////%3F") + suffix
+ << QString("//?") + suffix;
+ QTest::addRow("windows-wsl-%s", pathDescription)
+ << QString("//wsl$") + suffix
+ << QString("file:////wsl$") + suffix
+ << QString("//wsl$") + suffix;
+ QTest::addRow("windows-device--%s", pathDescription)
+ << QString("//.") + suffix
+ << QString("file:////.") + suffix
+ << QString("//.") + suffix;
+ }
+
+ QTest::newRow("windows-webdav")
+ << QString::fromLatin1("//somewebdavhost@SSL/somedir/somefile")
+ << QString::fromLatin1("webdavs://somewebdavhost/somedir/somefile")
+ << QString::fromLatin1("/somedir/somefile");
}
void tst_QUrl::fromLocalFile()
@@ -1311,19 +1364,19 @@ void tst_QUrl::fromLocalFileNormalize_data()
QTest::addColumn<QString>("theUrl");
QTest::addColumn<QString>("urlWithNormalizedPath");
- QTest::newRow("data0") << QString::fromLatin1("/a.txt") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("file:///a.txt");
- QTest::newRow("data1") << QString::fromLatin1("a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("file:a.txt");
- QTest::newRow("data8") << QString::fromLatin1("/a%.txt") << QString::fromLatin1("file:///a%25.txt")
- << QString::fromLatin1("file:///a%25.txt");
- QTest::newRow("data9") << QString::fromLatin1("/a%25.txt") << QString::fromLatin1("file:///a%2525.txt")
- << QString::fromLatin1("file:///a%2525.txt");
- QTest::newRow("data10") << QString::fromLatin1("/%80.txt") << QString::fromLatin1("file:///%2580.txt")
- << QString::fromLatin1("file:///%2580.txt");
- QTest::newRow("data11") << QString::fromLatin1("./a.txt") << QString::fromLatin1("file:./a.txt") << QString::fromLatin1("file:a.txt");
- QTest::newRow("data12") << QString::fromLatin1("././a.txt") << QString::fromLatin1("file:././a.txt") << QString::fromLatin1("file:a.txt");
- QTest::newRow("data13") << QString::fromLatin1("b/../a.txt") << QString::fromLatin1("file:b/../a.txt") << QString::fromLatin1("file:a.txt");
- QTest::newRow("data14") << QString::fromLatin1("/b/../a.txt") << QString::fromLatin1("file:///b/../a.txt") << QString::fromLatin1("file:///a.txt");
- QTest::newRow("data15") << QString::fromLatin1("/b/.") << QString::fromLatin1("file:///b/.") << QString::fromLatin1("file:///b");
+ QTest::newRow("absolute-path") << QString::fromLatin1("/a.txt") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("file:///a.txt");
+ QTest::newRow("relative-path") << QString::fromLatin1("a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("file:a.txt");
+ QTest::newRow("percent") << QString::fromLatin1("/a%.txt") << QString::fromLatin1("file:///a%25.txt")
+ << QString::fromLatin1("file:///a%25.txt");
+ QTest::newRow("percent25") << QString::fromLatin1("/a%25.txt") << QString::fromLatin1("file:///a%2525.txt")
+ << QString::fromLatin1("file:///a%2525.txt");
+ QTest::newRow("percent80") << QString::fromLatin1("/%80.txt") << QString::fromLatin1("file:///%2580.txt")
+ << QString::fromLatin1("file:///%2580.txt");
+ QTest::newRow("relative-dot") << QString::fromLatin1("./a.txt") << QString::fromLatin1("file:./a.txt") << QString::fromLatin1("file:a.txt");
+ QTest::newRow("relative-dot-dot") << QString::fromLatin1("././a.txt") << QString::fromLatin1("file:././a.txt") << QString::fromLatin1("file:a.txt");
+ QTest::newRow("relative-path-dotdot") << QString::fromLatin1("b/../a.txt") << QString::fromLatin1("file:b/../a.txt") << QString::fromLatin1("file:a.txt");
+ QTest::newRow("absolute-path-dotdot") << QString::fromLatin1("/b/../a.txt") << QString::fromLatin1("file:///b/../a.txt") << QString::fromLatin1("file:///a.txt");
+ QTest::newRow("absolute-path-dot") << QString::fromLatin1("/b/.") << QString::fromLatin1("file:///b/.") << QString::fromLatin1("file:///b");
}
void tst_QUrl::fromLocalFileNormalize()
@@ -1342,7 +1395,7 @@ void tst_QUrl::fromLocalFileNormalize()
void tst_QUrl::macTypes()
{
-#ifndef Q_OS_MAC
+#ifndef Q_OS_DARWIN
QSKIP("This is a Mac-only test");
#else
extern void tst_QUrl_mactypes(); // in tst_qurl_mac.mm
@@ -1803,8 +1856,8 @@ void tst_QUrl::ipvfuture_data()
QTest::newRow("non-hex-version") << "x://[vz.1234]" << false;
QTest::newRow("digit-ver") << "x://[v7.1]" << true << "x://[v7.1]";
- QTest::newRow("lowercase-hex-ver") << "x://[va.1]" << true << "x://[vA.1]";
- QTest::newRow("lowercase-hex-ver") << "x://[vA.1]" << true << "x://[vA.1]";
+ QTest::newRow("lowercase-hex-ver-lower") << "x://[va.1]" << true << "x://[vA.1]";
+ QTest::newRow("lowercase-hex-ver-upper") << "x://[vA.1]" << true << "x://[vA.1]";
QTest::newRow("data-digits") << "x://[v7.1234]" << true << "x://[v7.1234]";
QTest::newRow("data-unreserved") << "x://[v7.hello~-WORLD_.com]" << true << "x://[v7.hello~-WORLD_.com]";
@@ -1852,6 +1905,8 @@ void tst_QUrl::ipv6_data()
QTest::addColumn<bool>("isValid");
QTest::addColumn<QString>("output");
+ QTest::newRow("empty") << "//[]" << false << "";
+
QTest::newRow("case 1") << QString::fromLatin1("//[56:56:56:56:56:56:56:56]") << true
<< "//[56:56:56:56:56:56:56:56]";
QTest::newRow("case 2") << QString::fromLatin1("//[::56:56:56:56:56:56:56]") << true
@@ -2014,8 +2069,9 @@ void tst_QUrl::hasQuery()
void tst_QUrl::nameprep()
{
- QUrl url(QString::fromUtf8("http://www.fu""\xc3""\x9f""ball.de/"));
- QCOMPARE(url.toString(), QString::fromLatin1("http://www.fussball.de/"));
+ // U+FB01 LATIN SMALL LIGATURE FI
+ QUrl url(u"http://www.\uFB01le.de/"_s);
+ QCOMPARE(url.toString(), QStringLiteral(u"http://www.file.de/"));
}
void tst_QUrl::isValid()
@@ -2078,14 +2134,15 @@ void tst_QUrl::isValid()
}
{
- QUrl url = QUrl::fromEncoded("foo://%f0%9f%93%99.example.la/g");
+ // U+1F100 DIGIT ZERO FULL STOP
+ QUrl url = QUrl::fromEncoded("foo://%f0%9f%84%80.example.la/g");
QVERIFY(!url.isValid());
QVERIFY(url.toString().isEmpty());
QCOMPARE(url.path(), QString("/g"));
- url.setHost("%f0%9f%93%99.example.la/");
+ url.setHost("%f0%9f%84%80.example.la/");
QVERIFY(!url.isValid());
QVERIFY(url.toString().isEmpty());
- url.setHost("\xf0\x9f\x93\x99.example.la/");
+ url.setHost("\xf0\x9f\x84\x80.example.la/");
QVERIFY(!url.isValid());
QVERIFY(url.toString().isEmpty());
QVERIFY2(url.errorString().contains("Invalid hostname"),
@@ -3120,8 +3177,10 @@ void tst_QUrl::fromUserInput_data()
QTest::newRow("misc-1") << "user:pass@domain.com" << authUrl;
// FTP with double slashes in path
- QTest::newRow("ftp-double-slash-1") << "ftp.example.com//path" << QUrl("ftp://ftp.example.com/%2Fpath");
- QTest::newRow("ftp-double-slash-1") << "ftp://ftp.example.com//path" << QUrl("ftp://ftp.example.com/%2Fpath");
+ QTest::newRow("ftp-double-slash-no-scheme")
+ << "ftp.example.com//path" << QUrl("ftp://ftp.example.com/%2Fpath");
+ QTest::newRow("ftp-double-slash-scheme")
+ << "ftp://ftp.example.com//path" << QUrl("ftp://ftp.example.com/%2Fpath");
}
void tst_QUrl::fromUserInput()
@@ -3172,12 +3231,10 @@ void tst_QUrl::fromUserInputWithCwd_data()
QTest::newRow(QByteArray(fileName) + "-in-dot") << fileName << QStringLiteral(".") << url << url;
}
-#ifndef Q_OS_WINRT // WinRT cannot cd outside current / sandbox
QDir parent(base);
QVERIFY(parent.cdUp());
QUrl parentUrl = QUrl::fromLocalFile(parent.path());
QTest::newRow("dotdot") << ".." << base << parentUrl << parentUrl;
-#endif
QTest::newRow("nonexisting") << "nonexisting" << base << QUrl("http://nonexisting") << QUrl::fromLocalFile(base + "/nonexisting");
QTest::newRow("short-url") << "example.org" << base << QUrl("http://example.org") << QUrl::fromLocalFile(base + "/example.org");
@@ -3387,61 +3444,6 @@ void tst_QUrl::acceptEmptyAuthoritySegments()
QCOMPARE(QUrl(file_uni_bar, QUrl::StrictMode).toString(), file_triple_bar);
}
-void tst_QUrl::effectiveTLDs_data()
-{
- // See also: tst_QNetworkCookieJar::setCookiesFromUrl().
- // in tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
- QTest::addColumn<QUrl>("domain");
- QTest::addColumn<QString>("TLD");
- // TODO: autogenerate test-cases from:
- // https://raw.githubusercontent.com/publicsuffix/list/master/tests/test_psl.txt
- // checkPublicSuffix(domain, tail) appears in the list if
- // either tail is null and domain is public or
- // tail is the "registrable" part of domain; i.e. its minimal non-public tail.
-
- QTest::newRow("yes0") << QUrl::fromEncoded("http://test.co.uk") << ".co.uk";
- QTest::newRow("yes1") << QUrl::fromEncoded("http://test.com") << ".com";
- QTest::newRow("yes2") << QUrl::fromEncoded("http://www.test.de") << ".de";
- QTest::newRow("yes3") << QUrl::fromEncoded("http://test.ulm.museum") << ".ulm.museum";
- QTest::newRow("yes4") << QUrl::fromEncoded("http://www.com.krodsherad.no") << ".krodsherad.no";
- QTest::newRow("yes5") << QUrl::fromEncoded("http://www.co.uk.1.bg") << ".1.bg";
- QTest::newRow("yes6") << QUrl::fromEncoded("http://www.com.com.cn") << ".com.cn";
- QTest::newRow("yes7") << QUrl::fromEncoded("http://www.test.org.ws") << ".org.ws";
- QTest::newRow("yes9") << QUrl::fromEncoded("http://www.com.co.uk.wallonie.museum") << ".wallonie.museum";
- QTest::newRow("yes10") << QUrl::fromEncoded("http://www.com.evje-og-hornnes.no") << ".evje-og-hornnes.no";
- QTest::newRow("yes11") << QUrl::fromEncoded("http://www.bla.kamijima.ehime.jp") << ".kamijima.ehime.jp";
- QTest::newRow("yes12") << QUrl::fromEncoded("http://www.bla.kakuda.miyagi.jp") << ".kakuda.miyagi.jp";
- QTest::newRow("yes13") << QUrl::fromEncoded("http://mypage.betainabox.com") << ".betainabox.com";
- QTest::newRow("yes14") << QUrl::fromEncoded("http://mypage.rhcloud.com") << ".rhcloud.com";
- QTest::newRow("yes15") << QUrl::fromEncoded("http://mypage.int.az") << ".int.az";
- QTest::newRow("yes16") << QUrl::fromEncoded("http://anything.pagespeedmobilizer.com") << ".pagespeedmobilizer.com";
- QTest::newRow("yes17") << QUrl::fromEncoded("http://anything.eu-central-1.compute.amazonaws.com") << ".eu-central-1.compute.amazonaws.com";
- QTest::newRow("yes18") << QUrl::fromEncoded("http://anything.ltd.hk") << ".ltd.hk";
- QTest::newRow("trentino.it")
- << QUrl::fromEncoded("http://any.thing.trentino.it") << ".trentino.it";
- QTest::newRow("net.ni") << QUrl::fromEncoded("http://test.net.ni") << ".net.ni";
- QTest::newRow("dyn.cosidns.de")
- << QUrl::fromEncoded("http://test.dyn.cosidns.de") << ".dyn.cosidns.de";
- QTest::newRow("freeddns.org")
- << QUrl::fromEncoded("http://test.freeddns.org") << ".freeddns.org";
- QTest::newRow("app.os.stg.fedoraproject.org")
- << QUrl::fromEncoded("http://test.app.os.stg.fedoraproject.org")
- << ".app.os.stg.fedoraproject.org";
- QTest::newRow("development.run") << QUrl::fromEncoded("http://test.development.run") << ".development.run";
- QTest::newRow("crafting.xyz") << QUrl::fromEncoded("http://test.crafting.xyz") << ".crafting.xyz";
- QTest::newRow("nym.ie") << QUrl::fromEncoded("http://shamus.nym.ie") << ".nym.ie";
- QTest::newRow("vapor.cloud") << QUrl::fromEncoded("http://test.vapor.cloud") << ".vapor.cloud";
- QTest::newRow("official.academy") << QUrl::fromEncoded("http://acredited.official.academy") << ".official.academy";
-}
-
-void tst_QUrl::effectiveTLDs()
-{
- QFETCH(QUrl, domain);
- QFETCH(QString, TLD);
- QCOMPARE(domain.topLevelDomain(QUrl::PrettyDecoded), TLD);
- QCOMPARE(domain.topLevelDomain(QUrl::FullyDecoded), TLD);
-}
-
void tst_QUrl::lowercasesScheme()
{
QUrl url;
@@ -3774,13 +3776,13 @@ void tst_QUrl::setComponents_data()
<< PrettyDecoded << QString() << "foo:/path";
QTest::newRow("host-empty") << QUrl("foo://example.com/path")
<< int(Host) << "" << Tolerant << true
- << PrettyDecoded << QString() << "foo:///path";
+ << PrettyDecoded << "" << "foo:///path";
QTest::newRow("authority-null") << QUrl("foo://example.com/path")
<< int(Authority) << QString() << Tolerant << true
<< PrettyDecoded << QString() << "foo:/path";
QTest::newRow("authority-empty") << QUrl("foo://example.com/path")
<< int(Authority) << "" << Tolerant << true
- << PrettyDecoded << QString() << "foo:///path";
+ << PrettyDecoded << "" << "foo:///path";
QTest::newRow("query-null") << QUrl("http://example.com/?q=foo")
<< int(Query) << QString() << Tolerant << true
<< PrettyDecoded << QString() << "http://example.com/";
@@ -3807,106 +3809,106 @@ void tst_QUrl::setComponents_data()
QTest::newRow("invalid-username-1") << QUrl("http://example.com")
<< int(UserName) << "{}" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-username-2") << QUrl("http://example.com")
<< int(UserName) << "foo/bar" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-username-3") << QUrl("http://example.com")
<< int(UserName) << "foo:bar" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-password-1") << QUrl("http://example.com")
<< int(Password) << "{}" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-password-2") << QUrl("http://example.com")
<< int(Password) << "foo/bar" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-password-3") << QUrl("http://example.com")
<< int(Password) << "foo:bar" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-userinfo-1") << QUrl("http://example.com")
<< int(UserInfo) << "{}" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-userinfo-2") << QUrl("http://example.com")
<< int(UserInfo) << "foo/bar" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-host-1") << QUrl("http://example.com")
<< int(Host) << "-not-valid-" << Tolerant << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-host-2") << QUrl("http://example.com")
<< int(Host) << "%31%30.%30.%30.%31" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-authority-1") << QUrl("http://example.com")
<< int(Authority) << "-not-valid-" << Tolerant << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << "" << QString();
QTest::newRow("invalid-authority-2") << QUrl("http://example.com")
<< int(Authority) << "%31%30.%30.%30.%31" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << "" << QString();
QTest::newRow("invalid-path-0") << QUrl("http://example.com")
<< int(Path) << "{}" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-query-1") << QUrl("http://example.com")
<< int(Query) << "{}" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("invalid-fragment-1") << QUrl("http://example.com")
<< int(Fragment) << "{}" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
// these test cases are "compound invalid":
// they produces isValid == false, but the original is still available
QTest::newRow("invalid-path-1") << QUrl("/relative")
<< int(Path) << "c:/" << Strict << false
- << PrettyDecoded << "c:/" << "";
+ << PrettyDecoded << "c:/" << QString();
QTest::newRow("invalid-path-2") << QUrl("http://example.com")
<< int(Path) << "relative" << Strict << false
- << PrettyDecoded << "relative" << "";
+ << PrettyDecoded << "relative" << QString();
QTest::newRow("invalid-path-3") << QUrl("trash:/")
<< int(Path) << "//path" << Tolerant << false
- << PrettyDecoded << "//path" << "";
+ << PrettyDecoded << "//path" << QString();
// -- test bad percent encoding --
// unnecessary to test the scheme, since percent-decoding is not performed in it;
// see tests above
QTest::newRow("bad-percent-username") << QUrl("http://example.com")
<< int(UserName) << "bar%foo" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-password") << QUrl("http://user@example.com")
<< int(Password) << "bar%foo" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-userinfo-1") << QUrl("http://example.com")
<< int(UserInfo) << "bar%foo" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-userinfo-2") << QUrl("http://example.com")
<< int(UserInfo) << "bar%:foo" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-userinfo-3") << QUrl("http://example.com")
<< int(UserInfo) << "bar:%foo" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-authority-1") << QUrl("http://example.com")
<< int(Authority) << "bar%foo@example.org" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-authority-2") << QUrl("http://example.com")
<< int(Authority) << "bar%:foo@example.org" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-authority-3") << QUrl("http://example.com")
<< int(Authority) << "bar:%foo@example.org" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-authority-4") << QUrl("http://example.com")
<< int(Authority) << "bar:foo@bar%foo" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-host") << QUrl("http://example.com")
<< int(Host) << "bar%foo" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-path") << QUrl("http://example.com")
<< int(Path) << "/bar%foo" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-query") << QUrl("http://example.com")
<< int(Query) << "bar%foo" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("bad-percent-fragment") << QUrl("http://example.com")
<< int(Fragment) << "bar%foo" << Strict << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
// -- test decoded behaviour --
// '%' characters are not permitted in the scheme, this tests that it fails to set anything
@@ -3922,7 +3924,7 @@ void tst_QUrl::setComponents_data()
// '%' characters are not permitted in the hostname, these test that it fails to set anything
QTest::newRow("invalid-host-encode") << QUrl("http://example.com")
<< int(Host) << "ex%61mple.com" << Decoded << false
- << PrettyDecoded << "" << "";
+ << PrettyDecoded << QString() << QString();
QTest::newRow("path-encode") << QUrl("http://example.com/foo")
<< int(Path) << "/bar%23" << Decoded << true
<< PrettyDecoded << "/bar%2523" << "http://example.com/bar%2523";
@@ -3961,41 +3963,44 @@ void tst_QUrl::setComponents()
QFETCH(int, encoding);
QFETCH(QString, output);
+#define QNULLCOMPARE(a, b) \
+ do { QCOMPARE(a, b); QCOMPARE(a.isNull(), b.isNull()); } while (false)
+
switch (component) {
case Scheme:
// scheme is only parsed in strict mode
copy.setScheme(newValue);
- QCOMPARE(copy.scheme(), output);
+ QCOMPARE(copy.scheme(), output); // schemes don't become null
break;
case Path:
copy.setPath(newValue, QUrl::ParsingMode(parsingMode));
- QCOMPARE(copy.path(QUrl::ComponentFormattingOptions(encoding)), output);
+ QNULLCOMPARE(copy.path(QUrl::ComponentFormattingOptions(encoding)), output);
break;
case UserInfo:
copy.setUserInfo(newValue, QUrl::ParsingMode(parsingMode));
- QCOMPARE(copy.userInfo(QUrl::ComponentFormattingOptions(encoding)), output);
+ QNULLCOMPARE(copy.userInfo(QUrl::ComponentFormattingOptions(encoding)), output);
break;
case UserName:
copy.setUserName(newValue, QUrl::ParsingMode(parsingMode));
- QCOMPARE(copy.userName(QUrl::ComponentFormattingOptions(encoding)), output);
+ QNULLCOMPARE(copy.userName(QUrl::ComponentFormattingOptions(encoding)), output);
break;
case Password:
copy.setPassword(newValue, QUrl::ParsingMode(parsingMode));
- QCOMPARE(copy.password(QUrl::ComponentFormattingOptions(encoding)), output);
+ QNULLCOMPARE(copy.password(QUrl::ComponentFormattingOptions(encoding)), output);
break;
case Host:
copy.setHost(newValue, QUrl::ParsingMode(parsingMode));
- QCOMPARE(copy.host(QUrl::ComponentFormattingOptions(encoding)), output);
+ QNULLCOMPARE(copy.host(QUrl::ComponentFormattingOptions(encoding)), output);
break;
case Authority:
copy.setAuthority(newValue, QUrl::ParsingMode(parsingMode));
- QCOMPARE(copy.authority(QUrl::ComponentFormattingOptions(encoding)), output);
+ QNULLCOMPARE(copy.authority(QUrl::ComponentFormattingOptions(encoding)), output);
break;
case Query:
@@ -4010,6 +4015,7 @@ void tst_QUrl::setComponents()
QCOMPARE(copy.fragment(QUrl::ComponentFormattingOptions(encoding)), output);
break;
}
+#undef QNULLCOMPARE
QFETCH(bool, isValid);
QCOMPARE(copy.isValid(), isValid);
@@ -4080,7 +4086,7 @@ public:
for (int i = 0 ; i < m_urls.size(); ++i)
m_urls[i] = QUrl::fromEncoded("http://www.kde.org", QUrl::StrictMode);
}
- QVector<QUrl> m_urls;
+ QList<QUrl> m_urls;
};
static const UrlStorage * s_urlStorage = nullptr;
@@ -4120,12 +4126,30 @@ void tst_QUrl::testThreadingHelper()
void tst_QUrl::testThreading()
{
+ enum { Count = 100 };
+
+ if (QTestPrivate::isRunningArmOnX86())
+ QSKIP("This test fails in QEMU and looks like because of a data race, QTBUG-93176");
s_urlStorage = new UrlStorage;
- QThreadPool::globalInstance()->setMaxThreadCount(100);
- QFutureSynchronizer<void> sync;
- for (int i = 0; i < 100; ++i)
- sync.addFuture(QtConcurrent::run(this, &tst_QUrl::testThreadingHelper));
- sync.waitForFinished();
+ QThreadPool::globalInstance()->setMaxThreadCount(Count);
+
+ // Written this way because wasm need the eventloop
+ QList<QFuture<void>> futures;
+ futures.reserve(Count);
+
+ for (int i = 0; i < Count; ++i)
+ futures.push_back(QtConcurrent::run(&tst_QUrl::testThreadingHelper, this));
+
+ QEventLoop loop;
+ std::atomic<int> remaining = Count;
+ for (int i = 0; i < Count; ++i) {
+ futures[i].then([&]() {
+ if (!--remaining)
+ loop.quit();
+ });
+ }
+ loop.exec();
+
delete s_urlStorage;
}