diff --git a/autotests/dbusrunnertest.cpp b/autotests/dbusrunnertest.cpp index fb261f8..dbc51e3 100644 --- a/autotests/dbusrunnertest.cpp +++ b/autotests/dbusrunnertest.cpp @@ -1,176 +1,181 @@ /* * Copyright (C) 2017 David Edmundson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * 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 Library 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. */ #include #include #include #include "runnermanager.h" #include #include #include #include using namespace Plasma; Q_DECLARE_METATYPE(Plasma::QueryMatch); Q_DECLARE_METATYPE(QList); class DBusRunnerTest : public QObject { Q_OBJECT public: DBusRunnerTest(); ~DBusRunnerTest(); private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void testMatch(); void testMulti(); private: QStringList m_filesForCleanup; }; DBusRunnerTest::DBusRunnerTest() : QObject() { qRegisterMetaType >(); } DBusRunnerTest::~DBusRunnerTest() { } void DBusRunnerTest::initTestCase() { + // Set up a layer in the bin dir so ksycoca finds the Plasma/Runner service type + const QByteArray defaultDataDirs = qEnvironmentVariableIsSet("XDG_DATA_DIRS") ? qgetenv("XDG_DATA_DIRS") : QByteArray("/usr/local:/usr"); + const QByteArray modifiedDataDirs = QFile::encodeName(QCoreApplication::applicationDirPath()) + "/data:" + defaultDataDirs; + qputenv("XDG_DATA_DIRS", modifiedDataDirs); + QStandardPaths::setTestModeEnabled(true); QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).mkpath(QStringLiteral("kservices5")); { const QString fakeServicePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kservices5/dbusrunnertest.desktop"); QFile::copy(QFINDTESTDATA("dbusrunnertest.desktop"), fakeServicePath); m_filesForCleanup << fakeServicePath; } { const QString fakeServicePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kservices5/dbusrunnertestmulti.desktop"); QFile::copy(QFINDTESTDATA("dbusrunnertestmulti.desktop"), fakeServicePath); m_filesForCleanup << fakeServicePath; } KSycoca::self()->ensureCacheValid(); } void DBusRunnerTest::cleanupTestCase() { for(const QString path: m_filesForCleanup) { QFile::remove(path); } } void DBusRunnerTest::testMatch() { QProcess process; process.start(QFINDTESTDATA("testremoterunner"), QStringList({"net.krunnertests.dave"})); QVERIFY(process.waitForStarted()); QTest::qSleep(500); RunnerManager m; auto s = KService::serviceByDesktopPath(QStringLiteral("dbusrunnertest.desktop")); QVERIFY(s); m.loadRunner(s); m.launchQuery(QStringLiteral("foo")); QSignalSpy spy(&m, &RunnerManager::matchesChanged); QVERIFY(spy.wait()); //verify matches QCOMPARE(m.matches().count(), 1); auto result = m.matches().first(); //see testremoterunner.cpp QCOMPARE(result.id(), QStringLiteral("dbusrunnertest_id1")); //note the runner name is prepended QCOMPARE(result.text(), QStringLiteral("Match 1")); QCOMPARE(result.iconName(), QStringLiteral("icon1")); QCOMPARE(result.type(), Plasma::QueryMatch::ExactMatch); //relevance can't be compared easily becuase RunnerContext meddles with it //verify actions auto actions = m.actionsForMatch(result); QCOMPARE(actions.count(), 1); auto action = actions.first(); QCOMPARE(action->text(), QStringLiteral("Action 1")); QSignalSpy processSpy(&process, &QProcess::readyRead); m.run(result); processSpy.wait(); QCOMPARE(process.readAllStandardOutput().trimmed(), QByteArray("Running:id1:")); result.setSelectedAction(action); m.run(result); processSpy.wait(); QCOMPARE(process.readAllStandardOutput().trimmed(), QByteArray("Running:id1:action1")); process.kill(); process.waitForFinished(); } void DBusRunnerTest::testMulti() { QProcess process1; process1.start(QFINDTESTDATA("testremoterunner"), QStringList({"net.krunnertests.multi.a1"})); QVERIFY(process1.waitForStarted()); QProcess process2; process2.start(QFINDTESTDATA("testremoterunner"), QStringList({"net.krunnertests.multi.a2"})); QVERIFY(process2.waitForStarted()); QTest::qSleep(500); RunnerManager m; auto s = KService::serviceByDesktopPath(QStringLiteral("dbusrunnertestmulti.desktop")); QVERIFY(s); m.loadRunner(s); m.launchQuery(QStringLiteral("foo")); QSignalSpy spy(&m, &RunnerManager::matchesChanged); QVERIFY(spy.wait()); //verify matches, must be one from each QCOMPARE(m.matches().count(), 2); QString first = m.matches().at(0).data().toString(); QString second = m.matches().at(1).data().toString(); QVERIFY(first != second); QVERIFY(first == "net.krunnertests.multi.a1" || first == "net.krunnertests.multi.a2"); QVERIFY(second == "net.krunnertests.multi.a1" || second == "net.krunnertests.multi.a2"); process1.kill(); process2.kill(); process1.waitForFinished(); process2.waitForFinished(); } QTEST_MAIN(DBusRunnerTest) #include "dbusrunnertest.moc" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2bbf544..a9ecb0f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,108 +1,116 @@ add_subdirectory(declarative) set (KF5Runner_SRCS abstractrunner.cpp dbusrunner.cpp runnerjobs.cpp querymatch.cpp runnercontext.cpp runnermanager.cpp runnersyntax.cpp) ecm_qt_declare_logging_category(KF5Runner_SRCS HEADER krunner_debug.h IDENTIFIER KRUNNER CATEGORY_NAME org.kde.krunner) set_property(SOURCE "data/org.kde.krunner1.xml" PROPERTY INCLUDE dbusutils_p.h) add_library(KF5Runner ${KF5Runner_SRCS}) generate_export_header(KF5Runner BASE_NAME KRunner) add_library(KF5::Runner ALIAS KF5Runner) target_include_directories(KF5Runner INTERFACE "$") target_include_directories(KF5Runner PUBLIC "$") target_link_libraries(KF5Runner PUBLIC Qt5::Core KF5::Plasma # Must be public because abstractrunner.h needs plasma/version.h PRIVATE Qt5::DBus Qt5::Gui Qt5::Widgets KF5::ConfigCore KF5::Service KF5::I18n KF5::ThreadWeaver KF5::CoreAddons #KShell KF5::KIOCore #KProtocolInfo ) set_target_properties(KF5Runner PROPERTIES VERSION ${KRUNNER_VERSION_STRING} SOVERSION 5 EXPORT_NAME "Runner" ) ecm_generate_headers(KRunner_CamelCase_HEADERS HEADER_NAMES AbstractRunner RunnerContext RunnerManager RunnerSyntax QueryMatch PREFIX KRunner REQUIRED_HEADERS KRunner_HEADERS ) # Install files install(TARGETS KF5Runner EXPORT KF5RunnerTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${KRunner_CamelCase_HEADERS} DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/KRunner/KRunner COMPONENT Devel) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/krunner_export.h ${KRunner_HEADERS} DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/KRunner/krunner COMPONENT Devel) install(FILES data/servicetypes/plasma-runner.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR}) +add_custom_target(copy_servicetypes) +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin/data/kservicetypes5) +add_custom_command(TARGET copy_servicetypes PRE_BUILD COMMAND + ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/data/servicetypes/plasma-runner.desktop + ${CMAKE_BINARY_DIR}/bin/data/kservicetypes5) +add_dependencies(KF5Runner copy_servicetypes) + if(BUILD_QCH) ecm_add_qch( KF5Runner_QCH NAME KRunner BASE_NAME KF5Runner VERSION ${KF5_VERSION} ORG_DOMAIN org.kde SOURCES # using only public headers, to cover only public API ${KRunner_HEADERS} MD_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md" LINK_QCHS Qt5Core_QCH BLANK_MACROS KRUNNER_EXPORT KRUNNER_DEPRECATED KRUNNER_DEPRECATED_EXPORT TAGFILE_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} QCH_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} COMPONENT Devel ) endif() include(ECMGeneratePriFile) ecm_generate_pri_file(BASE_NAME KRunner LIB_NAME KF5Runner DEPS "core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KF5_INCLUDE_INSTALL_DIR}/KRunner) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) install(FILES "data/org.kde.krunner1.xml" DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR} RENAME kf5_org.kde.krunner1.xml)