2014-11-13 01:04:59 +02:00
|
|
|
// krazy:excludeall=qclasses
|
|
|
|
/* This file is part of the KDE libraries
|
|
|
|
Copyright (c) 1999-2005 Waldo Bastian <bastian@kde.org>
|
|
|
|
Copyright (c) 2000-2005 David Faure <faure@kde.org>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License version 2 as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kurltest.h"
|
|
|
|
|
|
|
|
#include "qtest_kde.h"
|
|
|
|
|
2023-06-23 14:44:33 +03:00
|
|
|
QTEST_KDEMAIN_CORE(KUrlTest)
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
#include "kurl.h"
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
2023-06-23 14:44:33 +03:00
|
|
|
Q_DECLARE_METATYPE(KUrl::EqualsOptions);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-06-25 06:31:53 +03:00
|
|
|
void KUrlTest::testHash_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KUrl>("url");
|
|
|
|
|
|
|
|
QTest::newRow("null")
|
|
|
|
<< KUrl();
|
|
|
|
QTest::newRow("empty")
|
|
|
|
<< KUrl("");
|
|
|
|
QTest::newRow("local file 1")
|
|
|
|
<< KUrl("file:///");
|
|
|
|
QTest::newRow("local file 2")
|
|
|
|
<< KUrl("file:///home/kde/foo?bar=baz#foobar");
|
|
|
|
QTest::newRow("local file 3")
|
|
|
|
<< KUrl("kde//foo?bar=baz#foobar");
|
|
|
|
QTest::newRow("ftp url - 3 trailing slashes")
|
|
|
|
<< KUrl("ftp://ftp.kde.org/foo?bar=baz#foobar");
|
|
|
|
}
|
|
|
|
|
|
|
|
void KUrlTest::testHash()
|
|
|
|
{
|
|
|
|
QFETCH(KUrl, url);
|
|
|
|
|
|
|
|
KUrl testurl;
|
|
|
|
testurl.setScheme(url.scheme());
|
|
|
|
testurl.setAuthority(url.authority());
|
|
|
|
testurl.setPath(url.path());
|
|
|
|
testurl.setQuery(url.query());
|
|
|
|
testurl.setFragment(url.fragment());
|
|
|
|
// qDebug() << Q_FUNC_INFO << url << testurl;
|
|
|
|
if (testurl.path().isEmpty() || testurl.url().contains(QLatin1String("kde//"))) {
|
|
|
|
QEXPECT_FAIL("", "The legacy of KUrl::setPath()", Continue);
|
|
|
|
}
|
|
|
|
QCOMPARE(url.url(), testurl.url());
|
|
|
|
// qDebug() << qHash(url) << qHash(testurl);
|
|
|
|
if (testurl.path().isEmpty() || testurl.url().contains(QLatin1String("kde//"))) {
|
|
|
|
QEXPECT_FAIL("", "The legacy of KUrl::setPath()", Continue);
|
|
|
|
}
|
|
|
|
QCOMPARE(qHash(url), qHash(testurl));
|
|
|
|
}
|
2023-06-24 21:23:45 +03:00
|
|
|
|
|
|
|
void KUrlTest::testQueryAndFragment_data()
|
|
|
|
{
|
2023-06-25 06:31:53 +03:00
|
|
|
QTest::addColumn<KUrl>("url");
|
2023-06-24 21:23:45 +03:00
|
|
|
QTest::addColumn<QString>("query");
|
|
|
|
QTest::addColumn<QString>("fragment");
|
|
|
|
|
|
|
|
QTest::newRow("local file 1")
|
|
|
|
<< KUrl("file:///")
|
|
|
|
<< QString()
|
|
|
|
<< QString();
|
|
|
|
QTest::newRow("local file 1 - with query and fragment")
|
|
|
|
<< KUrl("file:///?foo=bar#baz")
|
|
|
|
<< QString::fromLatin1("foo=bar")
|
|
|
|
<< QString::fromLatin1("baz");
|
|
|
|
QTest::newRow("local file 2")
|
|
|
|
<< KUrl("file:///home/kde/?foo=bar#baz")
|
|
|
|
<< QString::fromLatin1("foo=bar")
|
|
|
|
<< QString::fromLatin1("baz");
|
|
|
|
QTest::newRow("local file 3")
|
|
|
|
<< KUrl("kde//?foo=bar#baz")
|
|
|
|
<< QString::fromLatin1("foo=bar")
|
|
|
|
<< QString::fromLatin1("baz");
|
2023-06-25 03:15:21 +03:00
|
|
|
// NOTE: not supported and will trigger the fatal message in kCheckLocalFile()
|
2023-06-24 21:23:45 +03:00
|
|
|
QTest::newRow("local file 4")
|
|
|
|
<< KUrl("/foo?bar=baz#foobar")
|
|
|
|
<< QString()
|
|
|
|
<< QString();
|
|
|
|
QTest::newRow("ftp url - 3 trailing slashes")
|
|
|
|
<< KUrl("ftp://ftp.kde.org///?foo=bar#baz")
|
|
|
|
<< QString::fromLatin1("foo=bar")
|
|
|
|
<< QString::fromLatin1("baz");
|
|
|
|
}
|
|
|
|
|
|
|
|
void KUrlTest::testQueryAndFragment()
|
|
|
|
{
|
|
|
|
QFETCH(KUrl, url);
|
|
|
|
QFETCH(QString, query);
|
|
|
|
QFETCH(QString, fragment);
|
|
|
|
|
|
|
|
QCOMPARE(url.query(), query);
|
|
|
|
QCOMPARE(url.fragment(), fragment);
|
|
|
|
}
|
|
|
|
|
2023-06-23 17:53:20 +03:00
|
|
|
void KUrlTest::testcleanPath_data()
|
|
|
|
{
|
2023-06-25 06:31:53 +03:00
|
|
|
QTest::addColumn<KUrl>("url");
|
2023-06-23 17:53:20 +03:00
|
|
|
QTest::addColumn<KUrl>("url2");
|
|
|
|
|
|
|
|
QTest::newRow("local file 1")
|
|
|
|
<< KUrl("file:///")
|
|
|
|
<< KUrl("file:///");
|
|
|
|
QTest::newRow("local file 2")
|
|
|
|
<< KUrl("file:///home/kde/")
|
|
|
|
<< KUrl("file:///home/kde");
|
|
|
|
QTest::newRow("local file 3")
|
|
|
|
<< KUrl("kde//")
|
|
|
|
<< KUrl("kde");
|
|
|
|
QTest::newRow("ftp url - 3 trailing slashes")
|
|
|
|
<< KUrl("ftp://ftp.kde.org///")
|
|
|
|
<< KUrl("ftp://ftp.kde.org/");
|
|
|
|
}
|
|
|
|
|
|
|
|
void KUrlTest::testcleanPath()
|
|
|
|
{
|
|
|
|
QFETCH(KUrl, url);
|
|
|
|
QFETCH(KUrl, url2);
|
|
|
|
|
|
|
|
KUrl copy(url);
|
|
|
|
copy.cleanPath();
|
|
|
|
QCOMPARE(copy, url2);
|
|
|
|
}
|
|
|
|
|
2023-06-23 14:44:33 +03:00
|
|
|
void KUrlTest::testEquals_data()
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-06-25 06:31:53 +03:00
|
|
|
QTest::addColumn<KUrl>("url");
|
2023-06-23 14:44:33 +03:00
|
|
|
QTest::addColumn<KUrl>("url2");
|
|
|
|
QTest::addColumn<KUrl::EqualsOptions>("options");
|
|
|
|
QTest::addColumn<bool>("equals");
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-06-23 14:44:33 +03:00
|
|
|
QTest::newRow("local file 1")
|
|
|
|
<< KUrl("file:///")
|
|
|
|
<< KUrl("file:///")
|
|
|
|
<< KUrl::EqualsOptions(KUrl::CompareWithoutTrailingSlash)
|
|
|
|
<< true;
|
|
|
|
QTest::newRow("local file 2")
|
|
|
|
<< KUrl("file:///home/kde/")
|
|
|
|
<< KUrl("file:///home/kde")
|
|
|
|
<< KUrl::EqualsOptions(KUrl::CompareWithoutTrailingSlash)
|
|
|
|
<< true;
|
2023-06-23 17:53:20 +03:00
|
|
|
QTest::newRow("local file 3")
|
|
|
|
<< KUrl("file:///home/kde//")
|
|
|
|
<< KUrl("file:///home/kde")
|
|
|
|
<< KUrl::EqualsOptions(KUrl::CompareWithoutTrailingSlash)
|
|
|
|
<< true;
|
2023-06-23 14:44:33 +03:00
|
|
|
QTest::newRow("ftp url - 3 trailing slashes")
|
|
|
|
<< KUrl("ftp://ftp.kde.org///")
|
|
|
|
<< KUrl("ftp://ftp.kde.org/")
|
|
|
|
<< KUrl::EqualsOptions(KUrl::CompareWithoutTrailingSlash)
|
|
|
|
<< true;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-06-23 14:44:33 +03:00
|
|
|
void KUrlTest::testEquals()
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-06-23 14:44:33 +03:00
|
|
|
QFETCH(KUrl, url);
|
|
|
|
QFETCH(KUrl, url2);
|
|
|
|
QFETCH(KUrl::EqualsOptions, options);
|
|
|
|
QFETCH(bool, equals);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-06-23 14:44:33 +03:00
|
|
|
QCOMPARE(url.equals(url2, options), equals);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KUrlTest::testUriMode()
|
|
|
|
{
|
2023-06-23 14:44:33 +03:00
|
|
|
KUrl url1;
|
|
|
|
url1 = "mailto:User@Host.COM?subject=Hello";
|
|
|
|
QCOMPARE(url1.path(), QString("User@Host.COM"));
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KUrlTest::testToLocalFile()
|
|
|
|
{
|
2023-06-23 14:44:33 +03:00
|
|
|
const QString localFile("/tmp/print.pdf");
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-06-23 14:44:33 +03:00
|
|
|
const KUrl urlWithHost("file://localhost/tmp/print.pdf");
|
|
|
|
const KUrl urlWithoutHost("file:///tmp/print.pdf");
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-06-23 14:44:33 +03:00
|
|
|
QCOMPARE(urlWithHost.toLocalFile(), localFile);
|
|
|
|
QCOMPARE(urlWithoutHost.toLocalFile(), localFile );
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KUrlTest::testUrl_data()
|
|
|
|
{
|
2023-06-25 06:31:53 +03:00
|
|
|
QTest::addColumn<KUrl>("url");
|
2023-06-23 14:44:33 +03:00
|
|
|
QTest::addColumn<QString>("urlLTS");
|
|
|
|
QTest::addColumn<QString>("urlRTS");
|
|
|
|
QTest::addColumn<QString>("urlATS");
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
QTest::newRow("local file 1")
|
|
|
|
<< KUrl("file:///")
|
|
|
|
<< QString::fromLatin1("file:///")
|
|
|
|
<< QString::fromLatin1("file:///")
|
|
|
|
<< QString::fromLatin1("file:///");
|
|
|
|
QTest::newRow("local file 2")
|
|
|
|
<< KUrl("file:///home/kde/")
|
|
|
|
<< QString::fromLatin1("file:///home/kde/")
|
|
|
|
<< QString::fromLatin1("file:///home/kde")
|
|
|
|
<< QString::fromLatin1("file:///home/kde/");
|
|
|
|
QTest::newRow("local file 3")
|
|
|
|
<< KUrl("file:///home/kde//")
|
|
|
|
<< QString::fromLatin1("file:///home/kde//")
|
|
|
|
<< QString::fromLatin1("file:///home/kde")
|
|
|
|
<< QString::fromLatin1("file:///home/kde//");
|
|
|
|
|
|
|
|
QTest::newRow("ftp url")
|
|
|
|
<< KUrl("ftp://ftp.kde.org/")
|
|
|
|
<< QString::fromLatin1("ftp://ftp.kde.org/")
|
2023-06-24 20:54:23 +03:00
|
|
|
<< QString::fromLatin1("ftp://ftp.kde.org")
|
2014-11-13 01:04:59 +02:00
|
|
|
<< QString::fromLatin1("ftp://ftp.kde.org/");
|
|
|
|
QTest::newRow("ftp url - 3 trailing slashes")
|
|
|
|
<< KUrl("ftp://ftp.kde.org///")
|
|
|
|
<< QString::fromLatin1("ftp://ftp.kde.org///")
|
2023-06-24 20:54:23 +03:00
|
|
|
<< QString::fromLatin1("ftp://ftp.kde.org")
|
2014-11-13 01:04:59 +02:00
|
|
|
<< QString::fromLatin1("ftp://ftp.kde.org///");
|
|
|
|
}
|
|
|
|
|
|
|
|
void KUrlTest::testUrl()
|
|
|
|
{
|
2023-06-23 14:44:33 +03:00
|
|
|
QFETCH(KUrl, url);
|
|
|
|
QFETCH(QString, urlLTS);
|
|
|
|
QFETCH(QString, urlRTS);
|
|
|
|
QFETCH(QString, urlATS);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-06-23 14:44:33 +03:00
|
|
|
QCOMPARE(url.url(KUrl::LeaveTrailingSlash), urlLTS);
|
|
|
|
QCOMPARE(url.url(KUrl::RemoveTrailingSlash), urlRTS);
|
|
|
|
QCOMPARE(url.url(KUrl::AddTrailingSlash), urlATS);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KUrlTest::testToStringList()
|
|
|
|
{
|
|
|
|
KUrl::List urls;
|
|
|
|
urls << KUrl("file:///")
|
|
|
|
<< KUrl("file:///home/kde/")
|
|
|
|
<< KUrl("file:///home/kde//")
|
|
|
|
<< KUrl("ftp://ftp.kde.org/")
|
|
|
|
<< KUrl("ftp://ftp.kde.org///");
|
|
|
|
|
|
|
|
//kDebug() << urls.toStringList(KUrl::LeaveTrailingSlash);
|
2023-06-23 14:44:33 +03:00
|
|
|
QCOMPARE(
|
|
|
|
urls.toStringList(KUrl::LeaveTrailingSlash),
|
|
|
|
QStringList()
|
|
|
|
<< QLatin1String("file:///")
|
|
|
|
<< QLatin1String("file:///home/kde/")
|
|
|
|
<< QLatin1String("file:///home/kde//")
|
|
|
|
<< QLatin1String("ftp://ftp.kde.org/")
|
|
|
|
<< QLatin1String("ftp://ftp.kde.org///")
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
//kDebug() << urls.toStringList(KUrl::RemoveTrailingSlash);
|
2023-06-23 14:44:33 +03:00
|
|
|
QCOMPARE(
|
|
|
|
urls.toStringList(KUrl::RemoveTrailingSlash),
|
|
|
|
QStringList()
|
|
|
|
<< QLatin1String("file:///")
|
|
|
|
<< QLatin1String("file:///home/kde")
|
|
|
|
<< QLatin1String("file:///home/kde")
|
2023-06-24 20:54:23 +03:00
|
|
|
<< QLatin1String("ftp://ftp.kde.org")
|
|
|
|
<< QLatin1String("ftp://ftp.kde.org")
|
2023-06-23 14:44:33 +03:00
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
//kDebug() << urls.toStringList(KUrl::AddTrailingSlash);
|
2023-06-23 14:44:33 +03:00
|
|
|
QCOMPARE(
|
|
|
|
urls.toStringList(KUrl::AddTrailingSlash),
|
|
|
|
QStringList()
|
|
|
|
<< QLatin1String("file:///")
|
|
|
|
<< QLatin1String("file:///home/kde/")
|
|
|
|
<< QLatin1String("file:///home/kde//")
|
|
|
|
<< QLatin1String("ftp://ftp.kde.org/")
|
|
|
|
<< QLatin1String("ftp://ftp.kde.org///")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_kurltest.cpp"
|