Commit 5e40901b authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Add autotests for locations runner

Automation of all the test plans that have been
described in the previous MRs and checking for all
reported bugs.
parent 7e3a4231
......@@ -4,9 +4,9 @@ set(krunner_locations_SRCS
locationrunner.cpp
)
add_library(krunner_locations MODULE ${krunner_locations_SRCS})
kcoreaddons_desktop_to_json(krunner_locations plasma-runner-locations.desktop)
target_link_libraries(krunner_locations
add_library(locations MODULE ${krunner_locations_SRCS})
kcoreaddons_desktop_to_json(locations plasma-runner-locations.desktop)
target_link_libraries(locations
KF5::KIOCore
KF5::KIOWidgets
KF5::I18n
......@@ -14,4 +14,8 @@ target_link_libraries(krunner_locations
KF5::Notifications
)
install(TARGETS krunner_locations DESTINATION "${KDE_INSTALL_PLUGINDIR}/kf5/krunner" )
install(TARGETS locations DESTINATION "${KDE_INSTALL_PLUGINDIR}/kf5/krunner" )
if(BUILD_TESTING)
add_subdirectory(autotests)
endif()
ecm_add_test(locationsrunnertest.cpp TEST_NAME locationsrunnertest LINK_LIBRARIES Qt::Test KF5::Runner KF5::KIOCore)
configure_krunner_test(locationsrunnertest locations)
#include <KApplicationTrader>
#include <KIOCore/KProtocolInfo>
#include <KRunner/AbstractRunnerTest>
#include <KShell>
#include <QMimeData>
#include <QTest>
class ConverterRunnerTest : public AbstractRunnerTest
{
Q_OBJECT
private:
QString normalHomeFile;
QString executableHomeFile;
private Q_SLOTS:
void initTestCase();
void shouldNotProduceResult();
void shouldNotProduceResult_data();
void shouldProduceResult();
void shouldProduceResult_data();
void testMimeData();
};
void ConverterRunnerTest::initTestCase()
{
initProperties();
const QFileInfoList entries = QDir::home().entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Hidden);
for (const QFileInfo &entry : entries) {
if (entry.isExecutable()) {
executableHomeFile = entry.absoluteFilePath();
} else {
normalHomeFile = entry.absoluteFilePath();
}
}
QVERIFY(!normalHomeFile.isEmpty());
QVERIFY(!executableHomeFile.isEmpty());
}
void ConverterRunnerTest::shouldNotProduceResult()
{
QFETCH(QString, query);
launchQuery(query);
QVERIFY(manager->matches().isEmpty());
}
void ConverterRunnerTest::shouldProduceResult()
{
QFETCH(QString, query);
QFETCH(QVariant, data);
launchQuery(query);
const QList<Plasma::QueryMatch> matches = manager->matches();
QCOMPARE(1, matches.size());
QCOMPARE(matches.first().data(), data);
}
void ConverterRunnerTest::shouldNotProduceResult_data()
{
QTest::addColumn<QString>("query");
QTest::newRow("executable name") << "ls";
QTest::newRow("executable file path") << "/bin/ls";
QTest::newRow("executable file in home dir") << executableHomeFile;
QTest::newRow("executable path and argument") << "/bin/ls -Al";
QTest::newRow("non existent file") << QDir::homePath() + "_thisfiledoesnotexist.abc";
QTest::newRow("non existent file URL") << QUrl::fromLocalFile(QDir::homePath() + "_thisfiledoesnotexist.abc").toString();
QTest::newRow("nonexistent file with $HOME as env variable") << "$HOME/_thisfiledoesnotexist.abc";
QTest::newRow("nonexistent protocol") << "thisprotocoldoesnotexist:test123";
}
void ConverterRunnerTest::shouldProduceResult_data()
{
QTest::addColumn<QString>("query");
QTest::addColumn<QVariant>("data");
const QUrl homeURL = QUrl::fromLocalFile(QDir::homePath());
QTest::newRow("folder") << QDir::homePath() << QVariant(homeURL);
QTest::newRow("folder tilde") << KShell::tildeCollapse(QDir::homePath()) << QVariant(homeURL);
QTest::newRow("folder URL") << homeURL.toString() << QVariant(homeURL);
QTest::newRow("file") << normalHomeFile << QVariant(QUrl::fromLocalFile(normalHomeFile));
QTest::newRow("file tilde") << KShell::tildeCollapse(normalHomeFile) << QVariant(QUrl::fromLocalFile(normalHomeFile));
QTest::newRow("file with $HOME as env variable") << KShell::tildeCollapse(normalHomeFile).replace("~", "$HOME") << QVariant(QUrl::fromLocalFile(normalHomeFile));
QTest::newRow("file URL") << QUrl::fromLocalFile(normalHomeFile).toString() << QVariant(QUrl::fromLocalFile(normalHomeFile));
QTest::newRow("file URL to executable") << QUrl::fromLocalFile(executableHomeFile).toString() << QVariant(QUrl::fromLocalFile(executableHomeFile));
if (KProtocolInfo::isHelperProtocol("vnc")) {
QTest::newRow("vnc URL") << "vnc:foo" << QVariant("vnc:foo");
}
if (KApplicationTrader::preferredService("x-scheme-handler/rtmp")) {
QTest::newRow("rtmp URL") << "rtmp:foo" << QVariant("rtmp:foo");
}
if (KApplicationTrader::preferredService("x-scheme-handler/mailto")) {
// The mailto protocol is not provided by KIO, but by installed apps. BUG: 416257
QTest::newRow("mailto URL") << "mailto:user.user@user.com" << QVariant("mailto:user.user@user.com");
}
QTest::newRow("ssh URL") << "ssh:localhost" << QVariant("ssh:localhost");
QTest::newRow("help URL") << "help:krunner" << QVariant("help:krunner");
QTest::newRow("smb URL") << "smb:server/path" << QVariant("smb:server/path");
QTest::newRow("smb URL shorthand syntax") << R"(\\server\path)" << QVariant("smb://server/path");
}
void ConverterRunnerTest::testMimeData()
{
launchQuery(QDir::homePath());
QMimeData *data = manager->mimeDataForMatch(manager->matches().constFirst());
QVERIFY(data);
QCOMPARE(data->urls(), QList<QUrl>{QUrl::fromLocalFile(QDir::homePath())});
}
QTEST_MAIN(ConverterRunnerTest)
#include "locationsrunnertest.moc"
Supports Markdown
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