Commit e21d625a authored by Harald Sitter's avatar Harald Sitter
Browse files

add simple test rig for service runner

Summary:
- make sure that chrome apps have lower relevance than chrome itself
- makes sure that konsole has higher relevance than yakuake (latter
  only references onsole in the comment entry)

Test Plan:
- it passes and at a glance doesn't seem to break my production sycoca

Would be cool if @dfaure could take a look at the ksycoca setup to make sure the test doesn't negatively impact the production cache.

Reviewers: broulik, dfaure

Reviewed By: dfaure

Subscribers: dfaure, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D3707
parent b561844a
......@@ -19,6 +19,17 @@ target_link_libraries(krunner_services
KF5::Activities
)
add_library(krunner_services_test STATIC ${krunner_services_SRCS})
target_link_libraries(krunner_services_test
KF5::KIOWidgets
KF5::I18n
KF5::Runner
KF5::Service
KF5::Activities
)
install(TARGETS krunner_services DESTINATION ${KDE_INSTALL_PLUGINDIR} )
install(FILES plasma-runner-services.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
add_subdirectory(autotests)
remove_definitions(-DQT_NO_CAST_FROM_ASCII)
include(ECMAddTests)
ecm_add_test(servicerunnertest.cpp TEST_NAME servicerunnertest
LINK_LIBRARIES Qt5::Test krunner_services_test)
[Desktop Entry]
Version=1.0
Terminal=false
Type=Application
Name=Signal ServiceRunnerTest
Exec=/opt/google/chrome/google-chrome --profile-directory=Default --app-id=bikioccmkafdpakkkcpdbppfkghcmihk
Icon=chrome-bikioccmkafdpakkkcpdbppfkghcmihk-Default
StartupWMClass=crx_bikioccmkafdpakkkcpdbppfkghcmihk
[Desktop Entry]
Version=1.0
Name=Google Chrome ServiceRunnerTest
GenericName=Web Browser
Comment=Access the Internet
Exec=/usr/bin/google-chrome-stable %U
Terminal=false
Icon=google-chrome
Type=Application
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml_xml;image/webp;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ftp;
X-Ayatana-Desktop-Shortcuts=NewWindow;NewIncognito
[NewWindow Shortcut Group]
Name=New Window ServiceRunnerTest
Exec=/usr/bin/google-chrome-stable
TargetEnvironment=Unity
[NewIncognito Shortcut Group]
Name=New Incognito Window ServiceRunnerTest
Exec=/usr/bin/google-chrome-stable --incognito
TargetEnvironment=Unity
[Desktop Entry]
Type=Application
Exec=konsole
Icon=utilities-terminal
Terminal=false
Categories=Qt;KDE;System;TerminalEmulator;
Actions=NewWindow;NewTab;
X-DocPath=konsole/index.html
X-DBUS-StartupType=Unique
StartupNotify=true
X-KDE-AuthorizeAction=shell_access
Name=Konsole ServiceRunnerTest
GenericName=Terminal ServiceRunnerTest
Comment=Command line access ServiceRunnerTest
[Desktop Action NewWindow]
Name=Open a New Window
Exec=konsole
[Desktop Action NewTab]
Name=Open a New Tab
Exec=konsole --new-tab
[Desktop Entry]
Name=Yakuake ServiceRunnerTest
GenericName=Drop-down Terminal ServiceRunnerTest
Exec=yakuake
Icon=yakuake
Type=Application
Terminal=false
Categories=Qt;KDE;System;TerminalEmulator;
Comment=A drop-down terminal emulator based on KDE Konsole technology.
X-DBUS-StartupType=Unique
X-KDE-StartupNotify=false
X-DBUS-ServiceName=org.kde.yakuake
/*
* Copyright (C) 2016 Harald Sitter <sitter@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QObject>
#include <QStandardPaths>
#include <QTest>
#include <KSycoca>
#include "../servicerunner.h"
class ServiceRunnerTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void testChromeAppsRelevance();
void testKonsoleVsYakuakeComment();
};
void ServiceRunnerTest::initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
auto appsPath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
QDir(appsPath).removeRecursively();
QVERIFY(QDir().mkpath(appsPath));
auto fixtureDir = QDir(QFINDTESTDATA("fixtures"));
for(auto fileInfo : fixtureDir.entryInfoList(QDir::Files)) {
auto source = fileInfo.absoluteFilePath();
auto target = appsPath + QDir::separator() + fileInfo.fileName();
QVERIFY2(QFile::copy(fileInfo.absoluteFilePath(), target),
qPrintable(QString("can't copy %1 => %2").arg(source, target)));
}
setlocale(LC_ALL, "C.utf8");
KSycoca::self()->ensureCacheValid();
}
void ServiceRunnerTest::cleanupTestCase()
{
}
void ServiceRunnerTest::testChromeAppsRelevance()
{
ServiceRunner runner(this, QVariantList());
Plasma::RunnerContext context;
context.setQuery("chrome");
runner.match(context);
bool chromeFound = false;
bool signalFound = false;
for (auto match : context.matches()) {
qDebug() << "matched" << match.text();
if (!match.text().contains("ServiceRunnerTest")) {
continue;
}
if (match.text() == "Google Chrome ServiceRunnerTest") {
QCOMPARE(match.relevance(), 0.8);
chromeFound = true;
} else if (match.text() == "Signal ServiceRunnerTest") {
// Rates lower because it doesn't have it in the name.
QCOMPARE(match.relevance(), 0.7);
signalFound = true;
}
}
QVERIFY(chromeFound);
QVERIFY(signalFound);
}
void ServiceRunnerTest::testKonsoleVsYakuakeComment()
{
// Yakuake has konsole mentioned in comment, should be rated lower.
ServiceRunner runner(this, QVariantList());
Plasma::RunnerContext context;
context.setQuery("kons");
runner.match(context);
bool konsoleFound = false;
bool yakuakeFound = false;
for (auto match : context.matches()) {
qDebug() << "matched" << match.text();
if (!match.text().contains("ServiceRunnerTest")) {
continue;
}
if (match.text() == "Konsole ServiceRunnerTest") {
QCOMPARE(match.relevance(), 0.99);
konsoleFound = true;
} else if (match.text() == "Yakuake ServiceRunnerTest") {
// Rates lower because it doesn't have it in the name.
QCOMPARE(match.relevance(), 0.59);
yakuakeFound = true;
}
}
QVERIFY(konsoleFound);
QVERIFY(yakuakeFound);
}
QTEST_MAIN(ServiceRunnerTest)
#include "servicerunnertest.moc"
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