File indexing completed on 2024-04-14 04:52:03

0001 /***************************************************************************
0002  *   Copyright (C) 2011 Matthias Fuchs <mat69@gmx.net>                     *
0003  *   Code mostly from email from Will Stephenson <wstephenson@suse.de>     *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
0019  ***************************************************************************/
0020 
0021 #include "metalinktest.h"
0022 #include "../ui/metalinkcreator/metalinker.h"
0023 
0024 #include <QUrl>
0025 #include <QtTest>
0026 
0027 void MetalinkTest::testFilePath()
0028 {
0029     QFETCH(QString, string);
0030     QFETCH(bool, result);
0031 
0032     KGetMetalink::File file;
0033     file.name = string;
0034 
0035     QCOMPARE(file.isValidNameAttribute(), result);
0036 }
0037 
0038 void MetalinkTest::testFilePath_data()
0039 {
0040     QTest::addColumn<QString>("string");
0041     QTest::addColumn<bool>("result");
0042 
0043     QTest::newRow("traversal up relative to root") << "/../foo/bla" << false;
0044     QTest::newRow("traversal up at beginning") << "../foo/bla" << false;
0045     QTest::newRow("traversal up inside") << "bla/../foo/bla" << false;
0046     QTest::newRow("traversal up at end") << "foo/bla/.." << false;
0047     QTest::newRow("no file name") << "foo/bla/" << false;
0048     QTest::newRow("acceptable traversal down, contains path component") << "foo/bla" << true;
0049 }
0050 
0051 void MetalinkTest::testUrl()
0052 {
0053     QFETCH(QUrl, url);
0054     QFETCH(bool, result);
0055 
0056     KGetMetalink::Url data;
0057     data.url = url;
0058 
0059     QCOMPARE(data.isValid(), result);
0060 }
0061 
0062 void MetalinkTest::testUrl_data()
0063 {
0064     QTest::addColumn<QUrl>("url");
0065     QTest::addColumn<bool>("result");
0066 
0067     QTest::newRow("empty url") << QUrl() << false;
0068     QTest::newRow("no host") << QUrl("http://") << false;
0069     QTest::newRow("empty protocol") << QUrl("www.example.com") << false;
0070     QTest::newRow("valid url") << QUrl("http://www.example.com") << true;
0071 }
0072 
0073 void MetalinkTest::testMetaUrl()
0074 {
0075     QFETCH(QUrl, url);
0076     QFETCH(QString, type);
0077     QFETCH(bool, result);
0078 
0079     KGetMetalink::Metaurl data;
0080     data.url = url;
0081     data.type = type;
0082 
0083     QCOMPARE(data.isValid(), result);
0084 }
0085 
0086 void MetalinkTest::testMetaUrl_data()
0087 {
0088     QTest::addColumn<QUrl>("url");
0089     QTest::addColumn<QString>("type");
0090     QTest::addColumn<bool>("result");
0091 
0092     QTest::newRow("empty url") << QUrl() << "torrent" << false;
0093     QTest::newRow("no host") << QUrl("http://") << "torrent" << false;
0094     QTest::newRow("empty protocol") << QUrl("www.example.com") << "torrent" << false;
0095     QTest::newRow("empty type") << QUrl("http://www.example.com") << QString() << false;
0096     QTest::newRow("valid url") << QUrl("http://www.example.com") << "torrent" << true;
0097 }
0098 
0099 QTEST_MAIN(MetalinkTest)
0100 
0101 #include "moc_metalinktest.cpp"