~mterry/+junk/u8.2

« back to all changes in this revision

Viewing changes to tests/plugins/Unity/Indicators/sharedunitymenumodeltest.cpp

  • Committer: Michael Terry
  • Date: 2014-11-17 14:56:04 UTC
  • mfrom: (1317.1.118 unity8)
  • Revision ID: michael.terry@canonical.com-20141117145604-96dn9p5nwkifq2f4
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
17
 
 
18
#include "sharedunitymenumodel.h"
 
19
#include "unitymenumodelcache.h"
 
20
 
 
21
#include <QtTest>
 
22
#include <unitymenumodel.h>
 
23
 
 
24
class SharedUnityMenuModelTest : public QObject
 
25
{
 
26
    Q_OBJECT
 
27
 
 
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);
 
36
 
 
37
        return model;
 
38
    }
 
39
 
 
40
private Q_SLOTS:
 
41
 
 
42
    void testCreateModel()
 
43
    {
 
44
        QSharedPointer<SharedUnityMenuModel> model(createFullModel("test1"));
 
45
        QVERIFY(model->model() != nullptr);
 
46
    }
 
47
 
 
48
    void testDifferentDataCreatesDifferentModels()
 
49
    {
 
50
        QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
 
51
        QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test2"));
 
52
 
 
53
        QVERIFY(model1->model() != model2->model());
 
54
    }
 
55
 
 
56
    void testSameDataCreatesSameModels()
 
57
    {
 
58
        QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
 
59
        QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
 
60
 
 
61
        QCOMPARE(model1->model(), model2->model());
 
62
    }
 
63
 
 
64
    void testSavedData()
 
65
    {
 
66
        QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
 
67
        QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
 
68
 
 
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
    }
 
75
 
 
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"));
 
81
 
 
82
        model2->setMenuObjectPath("/com/canonical/LP1328646");
 
83
 
 
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
    }
 
88
 
 
89
    // Tests that the cache is recreated if deleted.
 
90
    void testDeletedCache()
 
91
    {
 
92
        QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
 
93
 
 
94
        QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
 
95
        delete UnityMenuModelCache::singleton();
 
96
        QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), false);
 
97
    }
 
98
 
 
99
};
 
100
 
 
101
QTEST_GUILESS_MAIN(SharedUnityMenuModelTest)
 
102
#include "sharedunitymenumodeltest.moc"