Commit 6adea54e authored by Kurt Hindenburg's avatar Kurt Hindenburg

Add BookMarkTest - currently only testing URL

Konsole mis-uses KBookmark; it is not really setup to handle commands
as bookmarks.  KBookmark encodes the URL which causes issues.  This
testing is currently determining if decoding the URL will work with
commands and URLs.

See BUG 311543, 368777 and possible others
parent 255b4f1c
/*
Copyright 2019 by Kurt Hindenburg <kurt.hindenburg@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
// Own
#include "BookMarkTest.h"
// Qt
#include <qtest.h>
// KDE
#include <KBookmarkManager>
using namespace Konsole;
/* This does not use Konsole's BookmarkHandler directly; it is used to
* test the code copied from there and to test any changes.
*/
/* Test that the URL (command) does not get mangled by KBookMark's encoding */
void BookMarkTest::testBookMarkURLs_data()
{
auto testData = QFINDTESTDATA(QLatin1String("data/bookmarks.xml"));
auto bookmarkManager = KBookmarkManager::managerForFile(testData, QStringLiteral("KonsoleTest"));
auto groupUrlList = bookmarkManager->root().groupUrlList();
// text explaining test, correct test result
QStringList bm_urls = {
QStringLiteral("simple command"), QStringLiteral("ssh machine"),
QStringLiteral("command with pipe (|)"), QStringLiteral("ssh machine | tee -a /var/log/system.log"),
QStringLiteral("file URL w/ non ASCII part"), QStringLiteral("file:///home/user/aκόσμε"),
QStringLiteral("command with double quotes"), QStringLiteral("isql-fb -u sysdba -p example \"test\""),
QStringLiteral("command with single quotes"), QStringLiteral("isql-fb -u sysdba -p example 'test'")
};
QTest::addColumn<QString>("text");
QTest::addColumn<QString>("result");
for (int i = 0; i < groupUrlList.size(); ++i) {
auto bm_url = groupUrlList.at(i);
// Current Konsole code using bm.url()
// The below is new to test decoding the url/command
auto bm = QUrl::fromPercentEncoding(bm_url.url().toUtf8());
QTest::newRow(bm_urls.at(i * 2).toUtf8().data())<< bm_urls.at((i * 2) +1) << bm;
}
}
// Only test top level URLs (no folders)
void BookMarkTest::testBookMarkURLs()
{
QFETCH(QString, text);
QFETCH(QString, result);
QCOMPARE(text, result);
}
/*
* When testing more than just URLs, the below loop can be used
auto bm = root.first();
int i = 0;
while (!bm.isNull()) {
auto bm_url = QUrl::fromPercentEncoding(bm.url().toString().toUtf8());
qWarning()<< i << ":" <<bm.url().toString();
i++;
bm = root.next(bm);
}
*/
QTEST_MAIN(BookMarkTest)
/*
Copyright 2019 by Kurt Hindenburg <kurt.hindenburg@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
#ifndef BOOKMARKTEST_H
#define BOOKMARKTEST_H
#include <QObject>
namespace Konsole
{
class BookMarkTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testBookMarkURLs_data();
void testBookMarkURLs();
private:
};
}
#endif // BOOKMARKTEST_H
......@@ -5,6 +5,12 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
set(KONSOLE_TEST_LIBS Qt5::Test konsoleprivate)
add_executable(BookMarkTest BookMarkTest.cpp)
ecm_mark_as_test(BookMarkTest)
ecm_mark_nongui_executable(BookMarkTest)
add_test(BookMarkTest BookMarkTest)
target_link_libraries(BookMarkTest ${KONSOLE_TEST_LIBS})
add_executable(CharacterColorTest CharacterColorTest.cpp)
ecm_mark_as_test(CharacterColorTest)
ecm_mark_nongui_executable(CharacterColorTest)
......
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xbel>
<xbel dbusName="KonsoleTest" xmlns:kdepriv="http://www.kde.org/kdepriv" xmlns:mime="http://www.freedesktop.org/standards/shared-mime-info" folded="no" xmlns:bookmark="http://www.freedesktop.org/standards/desktop-bookmarks">
<bookmark href="ssh machine">
<title>machine</title>
<info>
<metadata owner="http://freedesktop.org">
<bookmark:icon name="www"/>
</metadata>
</info>
</bookmark>
<bookmark href="ssh machine %7C tee -a /var/log/system.log">
<title>machine system.log</title>
<info>
<metadata owner="http://freedesktop.org">
<bookmark:icon name="www"/>
</metadata>
</info>
</bookmark>
<bookmark href="file:///home/user/a%CE%BA%E1%BD%B9%CF%83%CE%BC%CE%B5">
<title>folder</title>
<info>
<metadata owner="http://freedesktop.org">
<bookmark:icon name="utilities-terminal"/>
</metadata>
</info>
</bookmark>
<bookmark href="isql-fb -u sysdba -p example %22test%22">
<title>double quote</title>
<info>
<metadata owner="http://freedesktop.org">
<bookmark:icon name="utilities-terminal"/>
</metadata>
</info>
</bookmark>
<bookmark href="isql-fb -u sysdba -p example 'test'">
<title>single quote</title>
<info>
<metadata owner="http://freedesktop.org">
<bookmark:icon name="utilities-terminal"/>
</metadata>
</info>
</bookmark>
</xbel>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment