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
|
qt_internal_extend_target(tst_qurl CONDITION APPLE
|
||||||
SOURCES
|
SOURCES
|
||||||
tst_qurl_mac.mm
|
tst_qurl_mac.mm
|
||||||
|
LIBRARIES
|
||||||
|
Qt::CorePrivate
|
||||||
)
|
)
|
||||||
|
@ -63,6 +63,7 @@ private slots:
|
|||||||
void fromLocalFileNormalize();
|
void fromLocalFileNormalize();
|
||||||
void fromLocalFileNormalizeNonRoundtrip_data();
|
void fromLocalFileNormalizeNonRoundtrip_data();
|
||||||
void fromLocalFileNormalizeNonRoundtrip();
|
void fromLocalFileNormalizeNonRoundtrip();
|
||||||
|
void macTypes_data();
|
||||||
void macTypes();
|
void macTypes();
|
||||||
void relative();
|
void relative();
|
||||||
void compat_legacy();
|
void compat_legacy();
|
||||||
@ -1594,13 +1595,21 @@ void tst_QUrl::fromLocalFileNormalizeNonRoundtrip()
|
|||||||
QCOMPARE(url.toString(QUrl::NormalizePathSegments), urlWithNormalizedPath);
|
QCOMPARE(url.toString(QUrl::NormalizePathSegments), urlWithNormalizedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QUrl::macTypes()
|
void tst_QUrl::macTypes_data()
|
||||||
{
|
{
|
||||||
#ifndef Q_OS_DARWIN
|
#ifndef Q_OS_DARWIN
|
||||||
QSKIP("This is a Mac-only test");
|
QSKIP("This is a Mac-only test");
|
||||||
#else
|
#else
|
||||||
extern void tst_QUrl_mactypes(); // in tst_qurl_mac.mm
|
extern void tst_QUrl_mactypes_data();
|
||||||
void tst_QUrl_mactypes();
|
tst_QUrl_mactypes_data();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QUrl::macTypes()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_DARWIN
|
||||||
|
extern void tst_QUrl_mactypes();
|
||||||
|
tst_QUrl_mactypes();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,24 +2,75 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
#include <QtCore/private/qcore_mac_p.h>
|
||||||
|
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#include <Foundation/Foundation.h>
|
#include <Foundation/Foundation.h>
|
||||||
|
|
||||||
void tst_QUrl_macTypes()
|
using namespace Qt::StringLiterals;
|
||||||
|
|
||||||
|
void tst_QUrl_mactypes_data()
|
||||||
{
|
{
|
||||||
{
|
QTest::addColumn<QString>("input");
|
||||||
QUrl qtUrl("example.com");
|
QTest::addColumn<QString>("cfOutput");
|
||||||
const CFURLRef cfUrl = qtUrl.toCFURL();
|
QTest::addColumn<QString>("nsOutput");
|
||||||
QCOMPARE(QUrl::fromCFURL(cfUrl), qtUrl);
|
|
||||||
qtUrl.setUrl("www.example.com");
|
auto addSimple = [](const char *label, QLatin1StringView urll1) {
|
||||||
QVERIFY(QUrl::fromCFURL(cfUrl) != qtUrl);
|
QString url = urll1;
|
||||||
}
|
QTest::addRow("%s", label) << url << url << url;
|
||||||
{
|
};
|
||||||
QUrl qtUrl("example.com");
|
addSimple("empty", {});
|
||||||
const NSURL *nsUrl = qtUrl.toNSURL();
|
|
||||||
QCOMPARE(QUrl::fromNSURL(nsUrl), qtUrl);
|
addSimple("https-empty-path", "https://example.com"_L1);
|
||||||
qtUrl.setUrl("www.example.com");
|
addSimple("https-nonempty-path", "https://example.com/"_L1);
|
||||||
QVERIFY(QUrl::fromNSURL(nsUrl) != qtUrl);
|
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