on master help sign in
unity8/tests/plugins/Unity/Indicators/SharedUnityMenuModelTest.cpp
102 lines 3.6 kB history raw
1/*
2 * Copyright 2014 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 */
18#include "sharedunitymenumodel.h"
19#include "unitymenumodelcache.h"
21#include <QtTest>
22#include <unitymenumodel.h>
24class SharedUnityMenuModelTest : public QObject
26 Q_OBJECT
28 SharedUnityMenuModel* createFullModel(const QByteArray& testId)
29 {
30 SharedUnityMenuModel* model = new SharedUnityMenuModel;
31 model->setBusName("com.canonical." + testId);
32 model->setMenuObjectPath("/com/canonical/" + testId);
33 QVariantMap actions;
34 actions["test"] = QString("/com/canonical/%1/actions").arg(QString(testId));
35 model->setActions(actions);
37 return model;
38 }
40private Q_SLOTS:
42 void testCreateModel()
43 {
44 QSharedPointer<SharedUnityMenuModel> model(createFullModel("test1"));
45 QVERIFY(model->model() != nullptr);
46 }
48 void testDifferentDataCreatesDifferentModels()
49 {
50 QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
51 QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test2"));
53 QVERIFY(model1->model() != model2->model());
54 }
56 void testSameDataCreatesSameModels()
57 {
58 QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
59 QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
61 QCOMPARE(model1->model(), model2->model());
62 }
64 void testSavedData()
65 {
66 QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
67 QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
69 QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
70 model1.clear();
71 QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
72 model2.clear();
73 QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
74 }
76 // Tests that changing cached model data does not change the model path of others
77 void testLP1328646()
78 {
79 QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
80 QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
82 model2->setMenuObjectPath("/com/canonical/LP1328646");
84 QVERIFY(model1->model() != model2->model());
85 QCOMPARE(model1->model()->menuObjectPath(), QByteArray("/com/canonical/test1"));
86 QCOMPARE(model2->model()->menuObjectPath(), QByteArray("/com/canonical/LP1328646"));
87 }
89 // Tests that the cache is recreated if deleted.
90 void testDeletedCache()
91 {
92 QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
94 QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
95 delete UnityMenuModelCache::singleton();
96 QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), false);
97 }
99};
101QTEST_GUILESS_MAIN(SharedUnityMenuModelTest)
102#include "SharedUnityMenuModelTest.moc"