File indexing completed on 2022-11-29 18:25:10

0001 /* This file is part of the KDE project
0002 
0003    Copyright 1999      Waldo Bastian <bastian@kde.org>
0004    Copyright 2014      Albert Astals Cid <aacid@kde.org>
0005 
0006    This library is free software; you can redistribute it and/or modify
0007    it under the terms of the GNU Library General Public License as published
0008    by the Free Software Foundation; either version 2 of the License or
0009    ( at your option ) version 3 or, at the discretion of KDE e.V.
0010    ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version.
0011 
0012    This library is distributed in the hope that it will be useful,
0013    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015    Library General Public License for more details.
0016 
0017    You should have received a copy of the GNU Library General Public License
0018    along with this library; see the file COPYING.LIB.  If not, write to
0019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020    Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #include <QTest>
0024 
0025 #include <kcmdlineargs.h>
0026 
0027 class KCmdLineArgsTest : public QObject
0028 {
0029 public Q_SLOTS:
0030     void testmakeURL()
0031     {
0032         // Check how KCmdLineArgs::url() works
0033         QUrl u = KCmdLineArgs::makeURL(QByteArray("/tmp"));
0034         QCOMPARE(u.toLocalFile(), QLatin1String("/tmp"));
0035         u = KCmdLineArgs::makeURL(QByteArray("foo"));
0036         QCOMPARE(u.toLocalFile(), QDir::currentPath() + QLatin1String("/foo"));
0037         u = KCmdLineArgs::makeURL(QByteArray("http://www.kde.org"));
0038         QCOMPARE(u.toString(), QLatin1String("http://www.kde.org"));
0039 
0040         QFile file(QLatin1String("a:b"));
0041 #ifndef Q_OS_WIN
0042         bool ok = file.open(QIODevice::WriteOnly);
0043         Q_UNUSED(ok) // silence warnings
0044         QVERIFY(ok);
0045 #endif
0046         u = KCmdLineArgs::makeURL(QByteArray("a:b"));
0047         QVERIFY(u.isLocalFile());
0048         QVERIFY(u.toLocalFile().endsWith(QLatin1String("a:b")));
0049     }
0050 };
0051 
0052 QTEST_MAIN(KCmdLineArgsTest)