2 * Copyright 2013 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Michael Terry <michael.terry@canonical.com>
20#include "launcherbackend.h"
23#include <QDBusConnection>
24#include <QDBusMessage>
25#include <QDBusVariant>
28class LauncherBackendTest : public QObject
36 // As we want to test absolute file paths in the .desktop file, we need to modify the
37 // sample file and replace the path in there with the current build dir.
38 QSettings settings(QDir::currentPath() + "/click-icon.desktop", QSettings::IniFormat);
39 settings.setValue("Desktop Entry/Path", QDir::currentPath());
44 LauncherBackend backend;
46 backend.setStoredApplications(QStringList() << "rel-icon" << "abs-icon" << "invalid");
47 QCOMPARE(backend.storedApplications(), QStringList() << "rel-icon" << "abs-icon");
50 void testIcon_data() {
51 QTest::addColumn<QString>("appId");
52 QTest::addColumn<QString>("expectedIcon");
54 // Needs to expand a relative icon to the absolute path
55 QTest::newRow("relative icon path") << "rel-icon" << QDir::currentPath() + "/rel-icon.svg";
57 // In case an icon is not found on disk, it needs to fallback on image://theme/ for it
58 QTest::newRow("fallback on theme") << "abs-icon" << "image://theme//path/to/icon.png";
60 // Click packages have a relative icon path but an absolute path as a separate entry
61 QTest::newRow("click package icon") << "click-icon" << QDir::currentPath() + "/click-icon.svg";
65 QFETCH(QString, appId);
66 QFETCH(QString, expectedIcon);
68 LauncherBackend backend;
69 backend.setStoredApplications(QStringList() << appId);
71 QCOMPARE(backend.icon(appId), expectedIcon);
74 void testGetItem_data() {
75 QTest::addColumn<QString>("appId");
76 QTest::addColumn<bool>("exists");
78 QTest::newRow("Exists") << "rel-icon" << true;
79 QTest::newRow("Doesn't Exist") << "does-not-exist" << false;
83 QFETCH(QString, appId);
86 LauncherBackend backend;
87 auto item = backend.getItem(appId);
90 QVERIFY(item != nullptr);
92 QVERIFY(item == nullptr);
96 void testCount_data() {
97 QTest::addColumn<QString>("appId");
98 QTest::addColumn<bool>("setCount");
99 QTest::addColumn<int>("inCount");
100 QTest::addColumn<bool>("countVisible");
101 QTest::addColumn<int>("expectedCount");
103 /* Get baseline data on things working */
104 QTest::newRow("Baseline") << "rel-icon" << false << 0 << false << -1;
106 /* Valid count, but not visible */
107 QTest::newRow("Not visible") << "rel-icon" << true << 42 << false << -1;
110 QTest::newRow("Visible Count") << "rel-icon" << true << 42 << true << 42;
112 /* Invalide app to load */
113 QTest::newRow("Invalid App ID") << "this-app-doesnt-exist" << true << 42 << true << -1;
117 QFETCH(QString, appId);
118 QFETCH(bool, setCount);
119 QFETCH(int, inCount);
120 QFETCH(bool, countVisible);
121 QFETCH(int, expectedCount);
123 LauncherBackend backend;
126 backend.setCount(appId, inCount);
127 backend.setCountVisible(appId, countVisible);
129 QCOMPARE(backend.count(appId), expectedCount);
132 void testDbusName_data() {
133 QTest::addColumn<QString>("decoded");
134 QTest::addColumn<QString>("encoded");
136 /* Passthrough test */
137 QTest::newRow("Passthrough") << "fine" << "fine";
139 /* Number as first characeter */
140 QTest::newRow("Number first") << "31337" << "_331337";
142 /* Underscore test */
143 QTest::newRow("Underscore test") << "this_is_c_style_namespacing" << "this_5Fis_5Fc_5Fstyle_5Fnamespacing";
146 QTest::newRow("Hyphen test") << "typical-application" << "typical_2Dapplication";
149 QTest::newRow("日本語 test") << "日本語" << "_E6_97_A5_E6_9C_AC_E8_AA_9E";
152 void testDbusName() {
153 QFETCH(QString, decoded);
154 QFETCH(QString, encoded);
156 QString encodeOut = LauncherBackend::encodeAppId(decoded);
157 QCOMPARE(encoded, encodeOut);
159 QString decodeOut = LauncherBackend::decodeAppId(encoded);
160 QCOMPARE(decoded, decodeOut);
163 void testDbusIface_data() {
164 QTest::addColumn<QString>("appId");
165 QTest::addColumn<bool>("setCount");
166 QTest::addColumn<int>("inCount");
167 QTest::addColumn<bool>("countVisible");
168 QTest::addColumn<int>("expectedCount");
170 /* Get baseline data on things working */
171 QTest::newRow("Baseline") << "rel-icon" << false << 0 << false << -1;
174 QTest::newRow("Visible Count") << "rel-icon" << true << 42 << true << 42;
176 /* Invalide app to load */
177 QTest::newRow("Invalid App ID") << "this-app-doesnt-exist" << true << 42 << true << -1;
180 void testDbusIface() {
181 QFETCH(QString, appId);
182 QFETCH(bool, setCount);
183 QFETCH(int, inCount);
184 QFETCH(bool, countVisible);
185 QFETCH(int, expectedCount);
187 QDBusConnection con = QDBusConnection::sessionBus();
188 QDBusMessage message;
191 LauncherBackend backend;
194 message = QDBusMessage::createMethodCall("com.canonical.Unity.Launcher",
195 "/com/canonical/Unity/Launcher/" + LauncherBackend::encodeAppId(appId),
196 "org.freedesktop.DBus.Properties",
199 cargs.append(QString("com.canonical.Unity.Launcher.Item"));
200 cargs.append(QString("count"));
201 cargs.append(QVariant::fromValue(QDBusVariant(inCount)));
203 message.setArguments(cargs);
204 reply = con.call(message);
205 QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
208 /* Set countVisible */
209 message = QDBusMessage::createMethodCall("com.canonical.Unity.Launcher",
210 "/com/canonical/Unity/Launcher/" + LauncherBackend::encodeAppId(appId),
211 "org.freedesktop.DBus.Properties",
214 cvargs.append(QString("com.canonical.Unity.Launcher.Item"));
215 cvargs.append(QString("countVisible"));
216 cvargs.append(QVariant::fromValue(QDBusVariant(countVisible)));
218 message.setArguments(cvargs);
219 reply = con.call(message);
220 QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
223 message = QDBusMessage::createMethodCall("com.canonical.Unity.Launcher",
224 "/com/canonical/Unity/Launcher/" + LauncherBackend::encodeAppId(appId),
225 "org.freedesktop.DBus.Properties",
227 QVariantList getargs;
228 getargs.append(QString("com.canonical.Unity.Launcher.Item"));
229 getargs.append(QString("count"));
231 message.setArguments(getargs);
232 reply = con.call(message);
233 QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
234 QCOMPARE(reply.arguments()[0].value<QDBusVariant>().variant().toInt(), expectedCount);
238QTEST_GUILESS_MAIN(LauncherBackendTest)
239#include "launcherbackendtest.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list