diff options
Diffstat (limited to 'tests/auto/corelib/io/qurl/tst_qurl.cpp')
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 346 |
1 files changed, 202 insertions, 144 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 56b20f33d4..bd454fb695 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -1,41 +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$ -** -****************************************************************************/ +// 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 <qmap.h> +#include <QtTest/private/qemulationdetector_p.h> + +using namespace Qt::StringLiterals; + Q_DECLARE_METATYPE(QUrl::FormattingOptions) class tst_QUrl : public QObject @@ -50,6 +32,7 @@ private slots: void hashInPath(); void unc(); void assignment(); + void orderingCompiles(); void comparison(); void comparison2_data(); void comparison2(); @@ -308,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/"); @@ -456,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)); @@ -1109,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); } @@ -1249,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() @@ -1299,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() @@ -1334,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() @@ -1365,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 @@ -1826,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]"; @@ -1875,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 @@ -2037,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() @@ -2101,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"), @@ -3143,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() @@ -3773,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() << QString(); QTest::newRow("invalid-authority-2") << QUrl("http://example.com") << int(Authority) << "%31%30.%30.%30.%31" << Strict << false - << PrettyDecoded << "" << ""; + << PrettyDecoded << QString() << 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 @@ -3888,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"; @@ -3927,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: @@ -3976,6 +4015,7 @@ void tst_QUrl::setComponents() QCOMPARE(copy.fragment(QUrl::ComponentFormattingOptions(encoding)), output); break; } +#undef QNULLCOMPARE QFETCH(bool, isValid); QCOMPARE(copy.isValid(), isValid); @@ -4086,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(&tst_QUrl::testThreadingHelper, this)); - 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; } |