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.8 6.5 Change-Id: I20a7b66a9959b17597cffffdf3652b9167d00d07 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit 31753e722cd441de371be8f1e11b3bf089b187e2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
ee8cd91279
commit
6deb5098a1
@ -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
|
||||
)
|
||||
|
@ -63,6 +63,7 @@ private slots:
|
||||
void fromLocalFileNormalize();
|
||||
void fromLocalFileNormalizeNonRoundtrip_data();
|
||||
void fromLocalFileNormalizeNonRoundtrip();
|
||||
void macTypes_data();
|
||||
void macTypes();
|
||||
void relative();
|
||||
void compat_legacy();
|
||||
@ -1594,13 +1595,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
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
{
|
||||
{
|
||||
QUrl qtUrl("example.com");
|
||||
const CFURLRef cfUrl = qtUrl.toCFURL();
|
||||
QCOMPARE(QUrl::fromCFURL(cfUrl), qtUrl);
|
||||
qtUrl.setUrl("www.example.com");
|
||||
QVERIFY(QUrl::fromCFURL(cfUrl) != qtUrl);
|
||||
}
|
||||
{
|
||||
QUrl qtUrl("example.com");
|
||||
const NSURL *nsUrl = qtUrl.toNSURL();
|
||||
QCOMPARE(QUrl::fromNSURL(nsUrl), qtUrl);
|
||||
qtUrl.setUrl("www.example.com");
|
||||
QVERIFY(QUrl::fromNSURL(nsUrl) != qtUrl);
|
||||
}
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user