Changeset View
Standalone View
autotests/dbusrunnertest.cpp
| Show All 18 Lines | |||||
| 19 | #include <QObject> | 19 | #include <QObject> | ||
| 20 | #include <QAction> | 20 | #include <QAction> | ||
| 21 | #include <QTest> | 21 | #include <QTest> | ||
| 22 | #include <QStandardPaths> | 22 | #include <QStandardPaths> | ||
| 23 | 23 | | |||
| 24 | #include "runnermanager.h" | 24 | #include "runnermanager.h" | ||
| 25 | #include <QSignalSpy> | 25 | #include <QSignalSpy> | ||
| 26 | #include <QProcess> | 26 | #include <QProcess> | ||
| 27 | #include <QTime> | ||||
| 28 | #include <QTimer> | ||||
| 27 | 29 | | |||
| 28 | #include <KSycoca> | 30 | #include <KSycoca> | ||
| 29 | 31 | | |||
| 30 | using namespace Plasma; | 32 | using namespace Plasma; | ||
| 31 | 33 | | |||
| 32 | Q_DECLARE_METATYPE(Plasma::QueryMatch) | 34 | Q_DECLARE_METATYPE(Plasma::QueryMatch) | ||
| 33 | Q_DECLARE_METATYPE(QList<Plasma::QueryMatch>) | 35 | Q_DECLARE_METATYPE(QList<Plasma::QueryMatch>) | ||
| 34 | 36 | | |||
| 35 | class DBusRunnerTest : public QObject | 37 | class DBusRunnerTest : public QObject | ||
| 36 | { | 38 | { | ||
| 37 | Q_OBJECT | 39 | Q_OBJECT | ||
| 38 | public: | 40 | public: | ||
| 39 | DBusRunnerTest(); | 41 | DBusRunnerTest(); | ||
| 40 | ~DBusRunnerTest(); | 42 | ~DBusRunnerTest(); | ||
| 41 | 43 | | |||
| 42 | private Q_SLOTS: | 44 | private Q_SLOTS: | ||
| 43 | void initTestCase(); | 45 | void initTestCase(); | ||
| 44 | void cleanupTestCase(); | 46 | void cleanupTestCase(); | ||
| 45 | void testMatch(); | 47 | void testMatch(); | ||
| 46 | void testMulti(); | 48 | void testMulti(); | ||
| 49 | void testRequestActionsOnce(); | ||||
| 47 | private: | 50 | private: | ||
| 48 | QStringList m_filesForCleanup; | 51 | QStringList m_filesForCleanup; | ||
| 49 | }; | 52 | }; | ||
| 50 | 53 | | |||
| 51 | DBusRunnerTest::DBusRunnerTest() | 54 | DBusRunnerTest::DBusRunnerTest() | ||
| 52 | : QObject() | 55 | : QObject() | ||
| 53 | { | 56 | { | ||
| 54 | qRegisterMetaType<QList<Plasma::QueryMatch> >(); | 57 | qRegisterMetaType<QList<Plasma::QueryMatch> >(); | ||
| Show All 23 Lines | 79 | { | |||
| 78 | QFile::copy(QFINDTESTDATA("dbusrunnertestmulti.desktop"), fakeServicePath); | 81 | QFile::copy(QFINDTESTDATA("dbusrunnertestmulti.desktop"), fakeServicePath); | ||
| 79 | m_filesForCleanup << fakeServicePath; | 82 | m_filesForCleanup << fakeServicePath; | ||
| 80 | } | 83 | } | ||
| 81 | KSycoca::self()->ensureCacheValid(); | 84 | KSycoca::self()->ensureCacheValid(); | ||
| 82 | } | 85 | } | ||
| 83 | 86 | | |||
| 84 | void DBusRunnerTest::cleanupTestCase() | 87 | void DBusRunnerTest::cleanupTestCase() | ||
| 85 | { | 88 | { | ||
| 86 | for(const QString path: m_filesForCleanup) { | 89 | for(const QString &path: qAsConst(m_filesForCleanup)) { | ||
| 87 | QFile::remove(path); | 90 | QFile::remove(path); | ||
| 88 | } | 91 | } | ||
| 89 | } | 92 | } | ||
| 90 | 93 | | |||
| 91 | void DBusRunnerTest::testMatch() | 94 | void DBusRunnerTest::testMatch() | ||
| 92 | { | 95 | { | ||
| 93 | QProcess process; | 96 | QProcess process; | ||
| 94 | process.start(QFINDTESTDATA("testremoterunner"), QStringList({QStringLiteral("net.krunnertests.dave")})); | 97 | process.start(QFINDTESTDATA("testremoterunner"), QStringList({QStringLiteral("net.krunnertests.dave")})); | ||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 144 | { | |||
| 168 | QVERIFY(second == QLatin1String("net.krunnertests.multi.a1") || second == QStringLiteral("net.krunnertests.multi.a2")); | 171 | QVERIFY(second == QLatin1String("net.krunnertests.multi.a1") || second == QStringLiteral("net.krunnertests.multi.a2")); | ||
| 169 | 172 | | |||
| 170 | process1.kill(); | 173 | process1.kill(); | ||
| 171 | process2.kill(); | 174 | process2.kill(); | ||
| 172 | process1.waitForFinished(); | 175 | process1.waitForFinished(); | ||
| 173 | process2.waitForFinished(); | 176 | process2.waitForFinished(); | ||
| 174 | } | 177 | } | ||
| 175 | 178 | | |||
| 179 | void DBusRunnerTest::testRequestActionsOnce() | ||||
| 180 | { | ||||
| 181 | QProcess process; | ||||
| 182 | process.start(QFINDTESTDATA("testremoterunner"), QStringList({QStringLiteral("net.krunnertests.dave")})); | ||||
| 183 | QVERIFY(process.waitForStarted()); | ||||
| 184 | QTest::qSleep(500); | ||||
| 176 | 185 | | |||
| 186 | RunnerManager m; | ||||
| 187 | auto s = KService::serviceByDesktopPath(QStringLiteral("dbusrunnertest.desktop")); | ||||
| 188 | QVERIFY(s); | ||||
| 189 | m.loadRunner(s); | ||||
| 190 | | ||||
| 191 | // Wait because dbus signal is async | ||||
| 192 | QEventLoop loop; | ||||
| 193 | QTimer t; | ||||
| 194 | QTimer::connect(&t, &QTimer::timeout, &loop, &QEventLoop::quit); | ||||
| 195 | t.start(500); | ||||
| 196 | loop.exec(); | ||||
| 197 | | ||||
| 198 | // Construct a fake match with necesarry data | ||||
| 199 | QueryMatch fakeMatch(m.runner(QStringLiteral("dbusrunnertest"))); | ||||
| 200 | fakeMatch.setId(QStringLiteral("dbusrunnertest_id1")); | ||||
| 201 | fakeMatch.setData(QStringLiteral("net.krunnertests.dave")); | ||||
| 202 | | ||||
| 203 | // We haven't called the prepare slot, if the implementation works | ||||
| 204 | // the actions should alredy be available | ||||
meven: typo: already | |||||
| 205 | auto actions = m.actionsForMatch(fakeMatch); | ||||
| 206 | QCOMPARE(actions.count(), 1); | ||||
You should have added a QSignalSpy to check prepare was called, and another for requestAction to check it has been called only once. meven: You should have added a QSignalSpy to check prepare was called, and another for requestAction… | |||||
The concept behind this test is, that the runner is just loaded. If the Request-Actions-Once property is correctly implemented the actions are requested when the plugin is initialized. That means that they should be available and prepare doesn't need to be called. So it would make sense to add a signal spy to check if prepare was not called at all, or am I missing something? alex: The concept behind this test is, that the runner is just loaded. If the Request-Actions-Once… | |||||
I am not sure the test illustrates the change. Only by adding signals spies can you test the actual behavior here. I would trigger a second match and check requestActions was only called once, but prepare called each time as usual. meven: I am not sure the test illustrates the change.
1 action available means it did not regress but… | |||||
| 207 | | ||||
| 208 | process.kill(); | ||||
| 209 | process.waitForFinished(); | ||||
| 210 | } | ||||
| 177 | 211 | | |||
| 178 | QTEST_MAIN(DBusRunnerTest) | 212 | QTEST_MAIN(DBusRunnerTest) | ||
| 179 | 213 | | |||
| 180 | 214 | | |||
| 181 | #include "dbusrunnertest.moc" | 215 | #include "dbusrunnertest.moc" | ||
typo: already