on xenial help sign in
Dbus interface testing
commit690519cbef0bbefc3253786f908487700848656e authorTed Gould <ted@gould.cx> dateMon 14 Apr 2014, 16:57 (13 years ago) parent4abf593
2 files changed+81−3
plugins/Unity/Launcher/backend/launcherbackend.cpp+3−3 tests/plugins/Unity/Launcher/launcherbackendtest.cpp+78
plugins/Unity/Launcher/backend/launcherbackend.cpp+3−3
@@ -444,9 +444,9 @@ bool LauncherBackend::handleMessage(const QDBusMessage& message, const QDBusConn
444444
445445 if (message.member() == "Get") {
446446 if (message.arguments()[1].toString() == "count")
447− retval.append(this->count(appid));
447+ retval.append(QVariant::fromValue(QDBusVariant(this->count(appid))));
448448 else if (message.arguments()[1].toString() == "countVisible")
449− retval.append(this->countVisible(appid));
449+ retval.append(QVariant::fromValue(QDBusVariant(this->countVisible(appid))));
450450 } else if (message.member() == "Set") {
451451 if (message.arguments()[1].toString() == "count")
452452 this->setCount(appid, message.arguments()[2].value<QDBusVariant>().variant().toInt());
@@ -548,7 +548,7 @@ void LauncherBackend::emitPropChangedDbus (const QString& appId, const QString&
548548
549549 QList<QVariant> arguments;
550550 QVariantHash changedprops;
551− changedprops[property] = value;
551+ changedprops[property] = QVariant::fromValue(QDBusVariant(value));
552552 QVariantList deletedprops;
553553
554554 arguments.append(changedprops);
tests/plugins/Unity/Launcher/launcherbackendtest.cpp+78
@@ -20,6 +20,10 @@
2020#include "launcherbackend.h"
2121
2222#include <QtTest>
23+#include <QDBusConnection>
24+#include <QDBusMessage>
25+#include <QDBusVariant>
26+
2327
2428class LauncherBackendTest : public QObject
2529{
@@ -133,6 +137,80 @@ private Q_SLOTS:
133137 QString decodeOut = LauncherBackend::decodeAppId(encoded);
134138 QCOMPARE(decoded, decodeOut);
135139 }
140+
141+ void testDbusIface_data() {
142+ QTest::addColumn<QString>("appId");
143+ QTest::addColumn<bool>("setCount");
144+ QTest::addColumn<int>("inCount");
145+ QTest::addColumn<bool>("countVisible");
146+ QTest::addColumn<int>("expectedCount");
147+
148+ /* Get baseline data on things working */
149+ QTest::newRow("Baseline") << "rel-icon" << false << 0 << false << -1;
150+
151+ /* Turn it on */
152+ QTest::newRow("Visible Count") << "rel-icon" << true << 42 << true << 42;
153+
154+ /* Invalide app to load */
155+ QTest::newRow("Invalid App ID") << "this-app-doesnt-exist" << true << 42 << true << -1;
156+ }
157+
158+ void testDbusIface() {
159+ QFETCH(QString, appId);
160+ QFETCH(bool, setCount);
161+ QFETCH(int, inCount);
162+ QFETCH(bool, countVisible);
163+ QFETCH(int, expectedCount);
164+
165+ QDBusConnection con = QDBusConnection::sessionBus();
166+ QDBusMessage message;
167+ QDBusMessage reply;
168+
169+ LauncherBackend backend;
170+
171+ if (setCount) {
172+ message = QDBusMessage::createMethodCall("com.canonical.unity.launcher",
173+ "/com/canonical/unity/launcher/" + LauncherBackend::encodeAppId(appId),
174+ "org.freedesktop.DBus.Properties",
175+ "Set");
176+ QVariantList cargs;
177+ cargs.append(QString("com.canonical.unity.Launcher.Item"));
178+ cargs.append(QString("count"));
179+ cargs.append(QVariant::fromValue(QDBusVariant(inCount)));
180+
181+ message.setArguments(cargs);
182+ reply = con.call(message);
183+ QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
184+ }
185+
186+ /* Set countVisible */
187+ message = QDBusMessage::createMethodCall("com.canonical.unity.launcher",
188+ "/com/canonical/unity/launcher/" + LauncherBackend::encodeAppId(appId),
189+ "org.freedesktop.DBus.Properties",
190+ "Set");
191+ QVariantList cvargs;
192+ cvargs.append(QString("com.canonical.unity.Launcher.Item"));
193+ cvargs.append(QString("countVisible"));
194+ cvargs.append(QVariant::fromValue(QDBusVariant(countVisible)));
195+
196+ message.setArguments(cvargs);
197+ reply = con.call(message);
198+ QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
199+
200+ /* Get value */
201+ message = QDBusMessage::createMethodCall("com.canonical.unity.launcher",
202+ "/com/canonical/unity/launcher/" + LauncherBackend::encodeAppId(appId),
203+ "org.freedesktop.DBus.Properties",
204+ "Get");
205+ QVariantList getargs;
206+ getargs.append(QString("com.canonical.unity.Launcher.Item"));
207+ getargs.append(QString("count"));
208+
209+ message.setArguments(getargs);
210+ reply = con.call(message);
211+ QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
212+ QCOMPARE(reply.arguments()[0].value<QDBusVariant>().variant().toInt(), expectedCount);
213+ }
136214};
137215
138216QTEST_GUILESS_MAIN(LauncherBackendTest)