File indexing completed on 2024-05-12 16:06:06
0001 /* 0002 SPDX-FileCopyrightText: 2013 Jaydeep Solanki <jaydp17@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include <QTest> 0008 0009 #include "../part/url_utils.h" 0010 0011 namespace Okular 0012 { 0013 class UrlDetectTest : public QObject 0014 { 0015 Q_OBJECT 0016 private Q_SLOTS: 0017 void testURL(); 0018 void testURL_data(); 0019 }; 0020 0021 void UrlDetectTest::testURL() 0022 { 0023 QFETCH(QString, selectedText); 0024 QFETCH(QString, url); 0025 QCOMPARE(UrlUtils::getUrl(selectedText), url); 0026 } 0027 0028 void UrlDetectTest::testURL_data() 0029 { 0030 QTest::addColumn<QString>("selectedText"); 0031 QTest::addColumn<QString>("url"); 0032 QTest::newRow("1") << QStringLiteral("asdfhttp://okular.org") << QString(); 0033 QTest::newRow("2") << QStringLiteral("google.com/index.php/") << QString(); 0034 QTest::newRow("3") << QStringLiteral("http://google.com)") << QString(); 0035 0036 QTest::newRow("4") << QStringLiteral("https://okular.org") << QStringLiteral("https://okular.org"); 0037 QTest::newRow("5") << QStringLiteral("www.google.com") << QStringLiteral("http://www.google.com"); 0038 QTest::newRow("6") << QStringLiteral("asdf http://okular.kde.org/") << QStringLiteral("http://okular.kde.org/"); 0039 QTest::newRow("7") << QStringLiteral("http://www.example.com/wpstyle/?p=364") << QStringLiteral("http://www.example.com/wpstyle/?p=364"); 0040 QTest::newRow("8") << QStringLiteral("asdf http://okular.org fdsa") << QStringLiteral("http://okular.org"); 0041 QTest::newRow("9") << QStringLiteral("http://google.com/ø") << QStringLiteral("http://google.com/ø"); 0042 QTest::newRow("10") << QStringLiteral("http://www.wolframalpha.com/input/?i=Plot[%281%2Be^%28-%282%29v%29%29^%28-2%29+%2B+%282%29+%281%2Be^v%29^%28-2%29%2C+{t%2C-0.5%2C+0.5}]") 0043 << QStringLiteral("http://www.wolframalpha.com/input/?i=Plot[%281%2Be^%28-%282%29v%29%29^%28-2%29+%2B+%282%29+%281%2Be^v%29^%28-2%29%2C+{t%2C-0.5%2C+0.5}]"); 0044 QTest::newRow("11") << QStringLiteral("http://uid:pass@example.com:8080") << QStringLiteral("http://uid:pass@example.com:8080"); 0045 QTest::newRow("12") << QStringLiteral("www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf") << QStringLiteral("http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf"); 0046 QTest::newRow("13") << QStringLiteral("http://IISServer/nwind?template=<ROOTxmlns:sql=\"urn:schemas-microsoft-com:xml-sql\"><sql:query>SELECTTOP2*FROM[OrderDetails]WHEREUnitPrice%26lt;10FORXMLAUTO</sql:query></ROOT>") 0047 << QStringLiteral("http://IISServer/nwind?template=<ROOTxmlns:sql=\"urn:schemas-microsoft-com:xml-sql\"><sql:query>SELECTTOP2*FROM[OrderDetails]WHEREUnitPrice%26lt;10FORXMLAUTO</sql:query></ROOT>"); 0048 QTest::newRow("14") << QStringLiteral("https://www.example.com/foo/?bar=baz&inga=42&quux") << QStringLiteral("https://www.example.com/foo/?bar=baz&inga=42&quux"); 0049 QTest::newRow("15") << QStringLiteral("http://foo.bar/#tag") << QStringLiteral("http://foo.bar/#tag"); 0050 } 0051 0052 } 0053 0054 QTEST_MAIN(Okular::UrlDetectTest) 0055 #include "urldetecttest.moc"