@@ -20,6 +20,10 @@
20#include "launcherbackend.h"
20#include "launcherbackend.h"
22#include <QtTest>
22#include <QtTest>
23+#include <QDBusConnection>
24+#include <QDBusMessage>
25+#include <QDBusVariant>
24class LauncherBackendTest : public QObject
28class LauncherBackendTest : public QObject
@@ -133,6 +137,80 @@ private Q_SLOTS:
133 QString decodeOut = LauncherBackend::decodeAppId(encoded);
137 QString decodeOut = LauncherBackend::decodeAppId(encoded);
134 QCOMPARE(decoded, decodeOut);
138 QCOMPARE(decoded, decodeOut);
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");
148+ /* Get baseline data on things working */
149+ QTest::newRow("Baseline") << "rel-icon" << false << 0 << false << -1;
152+ QTest::newRow("Visible Count") << "rel-icon" << true << 42 << true << 42;
154+ /* Invalide app to load */
155+ QTest::newRow("Invalid App ID") << "this-app-doesnt-exist" << true << 42 << true << -1;
158+ void testDbusIface() {
159+ QFETCH(QString, appId);
160+ QFETCH(bool, setCount);
161+ QFETCH(int, inCount);
162+ QFETCH(bool, countVisible);
163+ QFETCH(int, expectedCount);
165+ QDBusConnection con = QDBusConnection::sessionBus();
166+ QDBusMessage message;
169+ LauncherBackend backend;
172+ message = QDBusMessage::createMethodCall("com.canonical.unity.launcher",
173+ "/com/canonical/unity/launcher/" + LauncherBackend::encodeAppId(appId),
174+ "org.freedesktop.DBus.Properties",
177+ cargs.append(QString("com.canonical.unity.Launcher.Item"));
178+ cargs.append(QString("count"));
179+ cargs.append(QVariant::fromValue(QDBusVariant(inCount)));
181+ message.setArguments(cargs);
182+ reply = con.call(message);
183+ QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
186+ /* Set countVisible */
187+ message = QDBusMessage::createMethodCall("com.canonical.unity.launcher",
188+ "/com/canonical/unity/launcher/" + LauncherBackend::encodeAppId(appId),
189+ "org.freedesktop.DBus.Properties",
191+ QVariantList cvargs;
192+ cvargs.append(QString("com.canonical.unity.Launcher.Item"));
193+ cvargs.append(QString("countVisible"));
194+ cvargs.append(QVariant::fromValue(QDBusVariant(countVisible)));
196+ message.setArguments(cvargs);
197+ reply = con.call(message);
198+ QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
201+ message = QDBusMessage::createMethodCall("com.canonical.unity.launcher",
202+ "/com/canonical/unity/launcher/" + LauncherBackend::encodeAppId(appId),
203+ "org.freedesktop.DBus.Properties",
205+ QVariantList getargs;
206+ getargs.append(QString("com.canonical.unity.Launcher.Item"));
207+ getargs.append(QString("count"));
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);
138QTEST_GUILESS_MAIN(LauncherBackendTest)
216QTEST_GUILESS_MAIN(LauncherBackendTest)