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 Zanetti <michael.zanetti@canonical.com>
21#include <unity/shell/launcher/LauncherModelInterface.h>
22#include <unity/shell/application/ApplicationInfoInterface.h>
24#include "launcheritem.h"
25#include "launchermodelas.h"
26#include "AccountsServiceDBusAdaptor.h"
30QHash<QString, QList<QVariantMap>> mockProperties;
32class LauncherModelASTest : public QObject
37 LauncherModel *launcherModel;
42 // Prepare some fake list
43 QList<QVariantMap> list;
45 item.insert("id", "appId1");
46 item.insert("name", "Item 1");
47 item.insert("icon", "fake.svg");
48 item.insert("count", 0);
49 item.insert("countVisible", false);
50 item.insert("pinned", true);
52 item["id"] = "appId2";
53 item["name"] = "Item 2";
55 mockProperties["user1"] = list;
58 bool isInSync(LauncherModel *model, const QList<QVariantMap> &properties) {
59 QList<QVariantMap> list;
60 // Strip unpinned if onlyPinned is set
61 Q_FOREACH (const QVariantMap &map, properties) {
62 if (!model->onlyPinned() || map.value("pinned").toBool()) {
67 bool inSync = model->rowCount() == list.count();
68 for (int i = 0; inSync && i < model->rowCount(); i++) {
69 inSync &= model->get(i)->appId() == list.at(i).value("id").toString();
70 inSync &= model->get(i)->name() == list.at(i).value("name").toString();
71 inSync &= model->get(i)->icon() == list.at(i).value("icon").toString();
72 inSync &= model->get(i)->count() == list.at(i).value("count").toInt();
73 inSync &= model->get(i)->countVisible() == list.at(i).value("countVisible").toBool();
78 void testLoadASOnStartup() {
80 LauncherModel* model = new LauncherModel(this);
82 // We didn't set a user yet. model should be empty
83 QCOMPARE(model->rowCount(), 0);
85 model->setUser("user1");
87 QCOMPARE(isInSync(model, mockProperties["user1"]), true);
91 void testASChangedUpdatesModel_data() {
92 QTest::addColumn<QString>("modelUser");
93 QTest::addColumn<QString>("changedUser");
94 QTest::addColumn<bool>("inSync");
96 QTest::newRow("this user changed") << "user1" << "user1" << true;
97 QTest::newRow("other user changed") << "user1" << "user2" << false;
100 void testASChangedUpdatesModel() {
101 QFETCH(QString, modelUser);
102 QFETCH(QString, changedUser);
103 QFETCH(bool, inSync);
105 LauncherModel* model = new LauncherModel(this);
106 model->setUser(modelUser);
108 int oldCount = mockProperties[modelUser].count();
109 QCOMPARE(model->rowCount(), oldCount);
111 QList<QVariantMap> newList;
112 QVariantMap newEntry;
113 newEntry.insert("id", "newappId");
114 newEntry.insert("name", "New app");
115 newEntry.insert("icon", "some-icon.svg");
116 newEntry.insert("count", 0);
117 newEntry.insert("countVisible", false);
118 newEntry.insert("pinned", true);
119 newList.append(newEntry);
120 model->m_accounts->simulatePropertyChange(changedUser, "LauncherItems", QVariant::fromValue(newList));
122 QCOMPARE(isInSync(model, mockProperties[modelUser]), true);
123 QCOMPARE(isInSync(model, mockProperties[changedUser]), inSync);
125 model->deleteLater();
128 void testUpdateCount() {
129 LauncherModel* model = new LauncherModel(this);
130 model->setUser("user1");
132 QCOMPARE(model->get(0)->countVisible(), false);
133 QCOMPARE(model->get(0)->count(), 0);
135 QList<QVariantMap> newList = mockProperties["user1"];
136 QVariantMap entry = newList.at(0);
137 entry["countVisible"] = true;
140 model->m_accounts->simulatePropertyChange("user1", "LauncherItems", QVariant::fromValue(newList));
142 QCOMPARE(isInSync(model, mockProperties["user1"]), true);
144 model->deleteLater();
147 void testOnlyPinned() {
148 LauncherModel *model = new LauncherModel(this);
149 model->setUser("user1");
150 model->setOnlyPinned(true);
152 QCOMPARE(isInSync(model, mockProperties["user1"]), true);
154 // Let's unpin one item
155 QList<QVariantMap> newList = mockProperties["user1"];
156 QVariantMap entry = newList.at(0);
157 entry["pinned"] = false;
159 model->m_accounts->simulatePropertyChange("user1", "LauncherItems", QVariant::fromValue(newList));
160 QCOMPARE(isInSync(model, mockProperties["user1"]), true);
162 // Now toggle onlyPinned and make sure the model keeps up
163 model->setOnlyPinned(false);
164 QCOMPARE(isInSync(model, mockProperties["user1"]), true);
166 model->setOnlyPinned(true);
167 QCOMPARE(isInSync(model, mockProperties["user1"]), true);
171QTEST_GUILESS_MAIN(LauncherModelASTest)
172#include "launchermodelastest.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