@@ -0,0 +1,100 @@
1+/*
2+ * Copyright 2013 Canonical Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ *
16+ * Authors:
17+ * Nick Dedekind <nick.dedekind@canonical.com>
18+ */
19+
20+#include "launcherbackend.h"
21+
22+#include <QtTest>
23+#include <QDebug>
24+
25+class LauncherBackendTest : public QObject
26+{
27+ Q_OBJECT
28+
29+private Q_SLOTS:
30+ void testFileNames()
31+ {
32+ LauncherBackend backend(false);
33+
34+ auto apps = QStringList() << "one.desktop" << "two" << "/full";
35+ backend.setStoredApplications(apps);
36+
37+ QCOMPARE(backend.desktopFile("one.desktop"), QString("/usr/share/applications/one.desktop"));
38+ QCOMPARE(backend.desktopFile("two"), QString("/usr/share/applications/two"));
39+ QCOMPARE(backend.desktopFile("/full"), QString("/full"));
40+ QCOMPARE(backend.storedApplications(), QStringList() << "/usr/share/applications/one.desktop" << "/usr/share/applications/two" << "/full");
41+
42+ QCOMPARE(backend.desktopFile("full"), QString(""));
43+
44+ QCOMPARE(backend.desktopFile("/usr/share/applications/one.desktop"), QString("/usr/share/applications/one.desktop"));
45+ }
46+
47+ void testDesktopReading()
48+ {
49+ LauncherBackend backend(false);
50+
51+ auto apps = QStringList() << SRCDIR "/rel-icon.desktop" << SRCDIR "/abs-icon.desktop" << SRCDIR "/no-icon.desktop" << SRCDIR "/no-name.desktop" << SRCDIR "/no-exist.desktop";
52+ backend.setStoredApplications(apps);
53+
54+ QCOMPARE(backend.displayName(SRCDIR "/rel-icon.desktop"), QString("Relative Icon"));
55+ QCOMPARE(backend.icon(SRCDIR "/rel-icon.desktop"), QString("image://gicon/rel-icon"));
56+
57+ QCOMPARE(backend.displayName(SRCDIR "/abs-icon.desktop"), QString("Absolute Icon"));
58+ QCOMPARE(backend.icon(SRCDIR "/abs-icon.desktop"), QString("/path/to/icon.png"));
59+
60+ QCOMPARE(backend.displayName(SRCDIR "/no-icon.desktop"), QString("No Icon"));
61+ QCOMPARE(backend.icon(SRCDIR "/no-icon.desktop"), QString(""));
62+
63+ QCOMPARE(backend.displayName(SRCDIR "/no-name.desktop"), QString(""));
64+ QCOMPARE(backend.icon(SRCDIR "/no-name.desktop"), QString("image://gicon/no-name"));
65+
66+ QCOMPARE(backend.displayName(SRCDIR "/no-exist.desktop"), QString(""));
67+ QCOMPARE(backend.icon(SRCDIR "/no-exist.desktop"), QString(""));
68+ }
69+
70+ void testPinning()
71+ {
72+ LauncherBackend backend(false);
73+
74+ // Confirm that default entries are all pinned
75+ auto defaultApps = backend.storedApplications();
76+ QVERIFY(defaultApps.size() > 0);
77+ for (auto app: defaultApps) {
78+ QCOMPARE(backend.isPinned(app), true);
79+ }
80+
81+ backend.setStoredApplications(QStringList() << "one" << "two");
82+ QCOMPARE(backend.isPinned("one"), false);
83+ QCOMPARE(backend.isPinned("two"), false);
84+
85+ backend.setPinned("two", true);
86+ QCOMPARE(backend.isPinned("two"), true);
87+
88+ backend.setStoredApplications(QStringList() << "one" << "two" << "three");
89+ QCOMPARE(backend.isPinned("two"), true);
90+ QCOMPARE(backend.isPinned("three"), false);
91+
92+ backend.setPinned("three", true);
93+ backend.setStoredApplications(QStringList() << "one" << "two");
94+ QCOMPARE(backend.isPinned("two"), true);
95+ QCOMPARE(backend.isPinned("three"), false); // doesn't exist anymore!
96+ }
97+};
98+
99+QTEST_GUILESS_MAIN(LauncherBackendTest)
100+#include "launcherbackendtest.moc"