summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <[email protected]>2025-02-25 14:31:07 -0300
committerQt Cherry-pick Bot <[email protected]>2025-03-04 22:21:55 +0000
commit8f5e26f51fb8f392604a075e1053925a01066a07 (patch)
treeb4db4e2b9b470602b3aa600832968a8a7e9c4599
parent52a5ac76909edabf72fc659ab47ac2b6d84423dc (diff)
tst_QUrl: improve toNSURL()/toCFURL() tests
This extends the test with a few more rows, and with delimiters that the Apple APIs seem to encode differently. Rather, it's QUrl that deviates slightly from the standard: we keep the delimiters unchanged, regardless, like browsers do. Task-number: QTBUG-134073 Pick-to: 6.5 Change-Id: I20a7b66a9959b17597cffffdf3652b9167d00d07 Reviewed-by: Tor Arne Vestbø <[email protected]> (cherry picked from commit 31753e722cd441de371be8f1e11b3bf089b187e2) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit 6deb5098a10b8b3fdfab0aab51c6bf78c0dce7f4)
-rw-r--r--tests/auto/corelib/io/qurl/CMakeLists.txt2
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp15
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl_mac.mm77
3 files changed, 78 insertions, 16 deletions
diff --git a/tests/auto/corelib/io/qurl/CMakeLists.txt b/tests/auto/corelib/io/qurl/CMakeLists.txt
index d105b323df0..4d135d2375c 100644
--- a/tests/auto/corelib/io/qurl/CMakeLists.txt
+++ b/tests/auto/corelib/io/qurl/CMakeLists.txt
@@ -25,4 +25,6 @@ qt_internal_add_test(tst_qurl
qt_internal_extend_target(tst_qurl CONDITION APPLE
SOURCES
tst_qurl_mac.mm
+ LIBRARIES
+ Qt::CorePrivate
)
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 2216f81f470..fbc2ec9df1c 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -63,6 +63,7 @@ private slots:
void fromLocalFileNormalize();
void fromLocalFileNormalizeNonRoundtrip_data();
void fromLocalFileNormalizeNonRoundtrip();
+ void macTypes_data();
void macTypes();
void relative();
void compat_legacy();
@@ -1617,13 +1618,21 @@ void tst_QUrl::fromLocalFileNormalizeNonRoundtrip()
QCOMPARE(url.toString(QUrl::NormalizePathSegments), urlWithNormalizedPath);
}
-void tst_QUrl::macTypes()
+void tst_QUrl::macTypes_data()
{
#ifndef Q_OS_DARWIN
QSKIP("This is a Mac-only test");
#else
- extern void tst_QUrl_mactypes(); // in tst_qurl_mac.mm
- void tst_QUrl_mactypes();
+ extern void tst_QUrl_mactypes_data();
+ tst_QUrl_mactypes_data();
+#endif
+}
+
+void tst_QUrl::macTypes()
+{
+#ifdef Q_OS_DARWIN
+ extern void tst_QUrl_mactypes();
+ tst_QUrl_mactypes();
#endif
}
diff --git a/tests/auto/corelib/io/qurl/tst_qurl_mac.mm b/tests/auto/corelib/io/qurl/tst_qurl_mac.mm
index a7cf3ebee52..8c6770016cc 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl_mac.mm
+++ b/tests/auto/corelib/io/qurl/tst_qurl_mac.mm
@@ -2,24 +2,75 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
+#include <QtCore/private/qcore_mac_p.h>
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h>
-void tst_QUrl_macTypes()
+using namespace Qt::StringLiterals;
+
+void tst_QUrl_mactypes_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("cfOutput");
+ QTest::addColumn<QString>("nsOutput");
+
+ auto addSimple = [](const char *label, QLatin1StringView urll1) {
+ QString url = urll1;
+ QTest::addRow("%s", label) << url << url << url;
+ };
+ addSimple("empty", {});
+
+ addSimple("https-empty-path", "https://example.com"_L1);
+ addSimple("https-nonempty-path", "https://example.com/"_L1);
+ addSimple("https-query", "https://example.com/?a=b"_L1);
+ addSimple("https-fragment", "https://example.com/#id"_L1);
+ addSimple("https-query-fragment", "https://example.com/?a=b#id"_L1);
+ addSimple("file-root", "file:///"_L1);
+ addSimple("file-path", "file:///etc/passwd"_L1);
+
+ addSimple("file-relative", "file:README.txt"_L1);
+ addSimple("file-relative-dotdot", "file:../README.txt"_L1);
+ addSimple("uri-relative", "README.txt"_L1);
+ addSimple("uri-relative-dotdot", "../README.txt"_L1);
+
+ // QUrl retains [] unencoded, unlike CFURL & NSURL
+ QTest::newRow("gen-delims") << "x://:@host/:@/[]?:/?@[]?#:/?@[]"
+ << "x://:@host/:@/%5B%5D?:/?@%5B%5D?#:/?@%5B%5D"
+ << "x://:@host/:@/%5B%5D?:/?@%5B%5D?#:/?@%5B%5D";
+}
+
+void tst_QUrl_mactypes()
{
- {
- QUrl qtUrl("example.com");
- const CFURLRef cfUrl = qtUrl.toCFURL();
- QCOMPARE(QUrl::fromCFURL(cfUrl), qtUrl);
- qtUrl.setUrl("www.example.com");
- QVERIFY(QUrl::fromCFURL(cfUrl) != qtUrl);
+ QFETCH(QString, input);
+ QFETCH(QString, cfOutput);
+ QFETCH(QString, nsOutput);
+ QUrl qtUrl(input);
+ QUrl otherUrl = qtUrl.isEmpty() ? QUrl("https://example.com") : QUrl();
+
+ // confirm the conversions result in what we expect it to result
+ CFURLRef cfUrl = qtUrl.toCFURL();
+ QCFString cfStr = CFURLGetString(cfUrl);
+ QCOMPARE(QString(cfStr), cfOutput);
+
+ const NSURL *nsUrl = qtUrl.toNSURL();
+ QVERIFY(nsUrl);
+ const NSString *nsString = [nsUrl absoluteString];
+ QVERIFY(nsString);
+ QCOMPARE(QString::fromNSString(nsString), nsOutput);
+
+ // confirm that roundtripping works and the equality operator does too
+ QUrl qtCfUrl = QUrl::fromCFURL(cfUrl);
+ if (input == cfOutput) {
+ QCOMPARE(qtCfUrl, qtUrl);
+ QCOMPARE_NE(qtCfUrl, otherUrl);
}
- {
- QUrl qtUrl("example.com");
- const NSURL *nsUrl = qtUrl.toNSURL();
- QCOMPARE(QUrl::fromNSURL(nsUrl), qtUrl);
- qtUrl.setUrl("www.example.com");
- QVERIFY(QUrl::fromNSURL(nsUrl) != qtUrl);
+ QCOMPARE(qtCfUrl.isEmpty(), qtUrl.isEmpty());
+
+ QUrl qtNsUrl = QUrl::fromNSURL(nsUrl);
+ if (input == nsOutput) {
+ QCOMPARE(qtNsUrl, qtUrl);
+ QCOMPARE_NE(qtNsUrl, otherUrl);
}
+ QCOMPARE(qtNsUrl.isEmpty(), qtUrl.isEmpty());
}