File indexing completed on 2024-04-28 05:50:33
0001 /* 0002 SPDX-FileCopyrightText: 2019 Kurt Hindenburg <kurt.hindenburg@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 // Own 0008 #include "BookMarkTest.h" 0009 0010 // Qt 0011 #include <QTest> 0012 0013 // KDE 0014 #include <KBookmarkManager> 0015 0016 using namespace Konsole; 0017 0018 /* This does not use Konsole's BookmarkHandler directly; it is used to 0019 * test the code copied from there and to test any changes. 0020 */ 0021 0022 /* Test that the URL (command) does not get mangled by KBookMark's encoding */ 0023 void BookMarkTest::testBookMarkURLs_data() 0024 { 0025 auto testData = QFINDTESTDATA(QStringLiteral("data/bookmarks.xml")); 0026 auto bookmarkManager = std::make_unique<KBookmarkManager>(testData); 0027 auto groupUrlList = bookmarkManager->root().groupUrlList(); 0028 0029 // text explaining test, correct test result 0030 QStringList bm_urls = {QStringLiteral("simple command"), 0031 QStringLiteral("ssh machine"), 0032 QStringLiteral("command with pipe (|)"), 0033 QStringLiteral("ssh machine | tee -a /var/log/system.log"), 0034 QStringLiteral("file URL w/ non ASCII part"), 0035 QStringLiteral("file:///home/user/aκόσμε"), 0036 QStringLiteral("command with double quotes"), 0037 QStringLiteral("isql-fb -u sysdba -p example \"test\""), 0038 QStringLiteral("command with single quotes"), 0039 QStringLiteral("isql-fb -u sysdba -p example 'test'"), 0040 QStringLiteral("command with %"), 0041 QStringLiteral("date +%m-%d-%Y")}; 0042 0043 QTest::addColumn<QString>("text"); 0044 QTest::addColumn<QString>("result"); 0045 for (int i = 0; i < groupUrlList.size(); ++i) { 0046 const auto &bm_url = groupUrlList.at(i); 0047 // Verify this line matching SessionControll.cpp to validate tests 0048 auto bm = QUrl::fromPercentEncoding(bm_url.toEncoded()); 0049 QTest::newRow(bm_urls.at(i * 2).toUtf8().data()) << bm_urls.at((i * 2) + 1) << bm; 0050 } 0051 } 0052 0053 // Only test top level URLs (no folders) 0054 void BookMarkTest::testBookMarkURLs() 0055 { 0056 QFETCH(QString, text); 0057 QFETCH(QString, result); 0058 0059 QCOMPARE(text, result); 0060 } 0061 0062 /* 0063 * When testing more than just URLs, the below loop can be used 0064 auto bm = root.first(); 0065 int i = 0; 0066 while (!bm.isNull()) { 0067 auto bm_url = QUrl::fromPercentEncoding(bm.url().toString().toUtf8()); 0068 qWarning()<< i << ":" <<bm.url().toString(); 0069 i++; 0070 bm = root.next(bm); 0071 } 0072 */ 0073 0074 QTEST_GUILESS_MAIN(BookMarkTest) 0075 0076 #include "moc_BookMarkTest.cpp"