2
* Copyright 2014 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/>.
18
#include "sharedunitymenumodel.h"
19
#include "unitymenumodelcache.h"
22
#include <unitymenumodel.h>
24
class SharedUnityMenuModelTest : public QObject
28
SharedUnityMenuModel* createFullModel(const QByteArray& testId)
30
SharedUnityMenuModel* model = new SharedUnityMenuModel;
31
model->setBusName("com.canonical." + testId);
32
model->setMenuObjectPath("/com/canonical/" + testId);
34
actions["test"] = QString("/com/canonical/%1/actions").arg(QString(testId));
35
model->setActions(actions);
42
void testCreateModel()
44
QSharedPointer<SharedUnityMenuModel> model(createFullModel("test1"));
45
QVERIFY(model->model() != nullptr);
48
void testDifferentDataCreatesDifferentModels()
50
QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
51
QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test2"));
53
QVERIFY(model1->model() != model2->model());
56
void testSameDataCreatesSameModels()
58
QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
59
QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
61
QCOMPARE(model1->model(), model2->model());
66
QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
67
QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
69
QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
71
QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
73
QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
76
// Tests that changing cached model data does not change the model path of others
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"));
89
// Tests that the cache is recreated if deleted.
90
void testDeletedCache()
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);
101
QTEST_GUILESS_MAIN(SharedUnityMenuModelTest)
102
#include "sharedunitymenumodeltest.moc"