diff options
Diffstat (limited to 'tests/auto/corelib/io/qurl/tst_qurl.cpp')
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 140 |
1 files changed, 84 insertions, 56 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 59cbba9bca..2024968435 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -1,11 +1,12 @@ // Copyright (C) 2016 The Qt Company Ltd. // Copyright (C) 2016 Intel Corporation. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qurl.h> #include <QtCore/QDebug> #include <QTest> +#include <QtTest/private/qcomparisontesthelper_p.h> #include <QDirIterator> #include <qcoreapplication.h> @@ -31,6 +32,7 @@ private slots: void hashInPath(); void unc(); void assignment(); + void orderingCompiles(); void comparison(); void comparison2_data(); void comparison2(); @@ -289,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/"); @@ -437,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)); @@ -1387,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 @@ -3768,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/"; @@ -3801,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 @@ -3916,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"; @@ -3955,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: @@ -4004,6 +4015,7 @@ void tst_QUrl::setComponents() QCOMPARE(copy.fragment(QUrl::ComponentFormattingOptions(encoding)), output); break; } +#undef QNULLCOMPARE QFETCH(bool, isValid); QCOMPARE(copy.isValid(), isValid); @@ -4114,14 +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; } |