on master help sign in
unity8/tests/plugins/Unity/Indicators/IndicatorsManagerTest.cpp
183 lines 5.6 kB history raw
1/*
2 * Copyright 2012 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 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 */
20#include "indicatorsmanager.h"
22#include <paths.h>
24#include <QtTest>
25#include <QDebug>
27class IndicatorsManagerTest : public QObject
29 Q_OBJECT
30private Q_SLOTS:
32 void initTestCase()
33 {
34 setenv("XDG_DATA_DIRS", (testDataDir() + "/data").toLatin1().data(), 1);
35 }
37 void cleanupTestCase()
38 {
39 }
41 /*
42 * Test if all plugins is loaded correct
43 */
44 void testLoad()
45 {
46 IndicatorsManager manager;
48 QVERIFY(!manager.isLoaded());
49 QCOMPARE(manager.indicators().count(), 0);
51 manager.setProfile("test1");
52 manager.load();
54 QVERIFY(manager.isLoaded());
55 QCOMPARE(manager.indicators().count(), 4);
57 manager.unload();
59 QVERIFY(!manager.isLoaded());
60 QCOMPARE(manager.indicators().count(), 0);
61 }
63 /*
64 * Test the creation & initialising of the indicator data
65 */
66 void testPluginInterfaceProfile1()
67 {
68 IndicatorsManager manager;
69 manager.setProfile("test1");
70 manager.load();
72 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
73 QVERIFY(indicator ? true : false);
75 QCOMPARE(indicator->identifier(), QString("indicator-fake1"));
76 QCOMPARE(indicator->position(), 1);
78 // Check that the initial properties have been set.
79 QVariantMap props = indicator->indicatorProperties().toMap();
80 QCOMPARE(props.count(), 4);
81 QCOMPARE(props["busName"].toString(), QString("com.canonical.indicator.fake1"));
82 QCOMPARE(props["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
84 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test1"));
85 }
87 /*
88 * Test the creation & initialising of the indicator data
89 */
90 void testPluginInterfaceProfile2()
91 {
92 IndicatorsManager manager;
93 manager.setProfile("test2");
94 manager.load();
96 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
97 QVERIFY(indicator ? true : false);
99 QCOMPARE(indicator->identifier(), QString("indicator-fake1"));
100 QCOMPARE(indicator->position(), 1);
102 // Check that the initial properties have been set.
103 QVariantMap props = indicator->indicatorProperties().toMap();
104 QCOMPARE(props.count(), 4);
105 QCOMPARE(props["busName"].toString(), QString("com.canonical.indicator.fake1"));
106 QCOMPARE(props["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
108 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test2"));
109 }
111 /*
112 * Test switching the indicator profile data
113 */
114 void testPluginInterfaceProfileSwitch()
115 {
116 IndicatorsManager manager;
117 manager.setProfile("test1");
118 manager.load();
120 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
121 QVERIFY(indicator ? true : false);
123 QVariantMap props = indicator->indicatorProperties().toMap();
124 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test1"));
126 manager.setProfile("test2");
127 props = indicator->indicatorProperties().toMap();
128 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test2"));
129 }
131 /*
132 * Test if a new plugin object is create for each different plugin
133 */
134 void testPluginInstance()
135 {
136 IndicatorsManager manager;
137 manager.setProfile("test2");
138 manager.load();
140 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
141 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
142 QVERIFY(i0?true:false);
143 QVERIFY(i1?true:false);
144 QCOMPARE(i0, i1);
146 Indicator::Ptr i2 = manager.indicator("indicator-fake2");
147 QVERIFY(i2?true:false);
148 QVERIFY(i2 != i1);
149 QVERIFY(i2 != i1);
150 }
152 /*
153 * Test if a new plugin init function is called only once
154 */
155 void testPluginInitAndShutdown()
156 {
157 IndicatorsManager manager;
158 manager.setProfile("test1");
159 manager.load();
161 QWeakPointer<Indicator> wp0;
162 QWeakPointer<Indicator> wp1;
163 {
164 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
165 wp0 = i0.toWeakRef();
167 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
168 wp1 = i1.toWeakRef();
170 manager.unload();
171 // still alive while we have the shared pointers.
172 QVERIFY(!wp0.isNull());
173 QVERIFY(!wp1.isNull());
174 }
176 // no more smart pointers. should have been released.
177 QVERIFY(wp0.isNull());
178 QVERIFY(wp1.isNull());
179 }
180};
182QTEST_GUILESS_MAIN(IndicatorsManagerTest)
183#include "IndicatorsManagerTest.moc"