on daa5708 help sign in
unity8/tests/plugins/Unity/Indicators/indicatorsmanagertest.cpp
185 lines 5.7 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("UNITY_TEST_ENV", "1", 1);
35 setenv("XDG_DATA_DIRS", (sourceDirectory() + "/tests/data").toLatin1().data(), 1);
36 }
38 void cleanupTestCase()
39 {
40 unsetenv("UNITY_TEST_ENV");
41 }
43 /*
44 * Test if all plugins is loaded correct
45 */
46 void testLoad()
47 {
48 IndicatorsManager manager;
50 QVERIFY(!manager.isLoaded());
51 QCOMPARE(manager.indicators().count(), 0);
53 manager.setProfile("test1");
54 manager.load();
56 QVERIFY(manager.isLoaded());
57 QCOMPARE(manager.indicators().count(), 4);
59 manager.unload();
61 QVERIFY(!manager.isLoaded());
62 QCOMPARE(manager.indicators().count(), 0);
63 }
65 /*
66 * Test the creation & initialising of the indicator data
67 */
68 void testPluginInterfaceProfile1()
69 {
70 IndicatorsManager manager;
71 manager.setProfile("test1");
72 manager.load();
74 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
75 QVERIFY(indicator ? true : false);
77 QCOMPARE(indicator->identifier(), QString("indicator-fake1"));
78 QCOMPARE(indicator->position(), 1);
80 // Check that the initial properties have been set.
81 QVariantMap props = indicator->indicatorProperties().toMap();
82 QCOMPARE(props.count(), 4);
83 QCOMPARE(props["busName"].toString(), QString("com.canonical.indicator.fake1"));
84 QCOMPARE(props["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
86 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test1"));
87 }
89 /*
90 * Test the creation & initialising of the indicator data
91 */
92 void testPluginInterfaceProfile2()
93 {
94 IndicatorsManager manager;
95 manager.setProfile("test2");
96 manager.load();
98 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
99 QVERIFY(indicator ? true : false);
101 QCOMPARE(indicator->identifier(), QString("indicator-fake1"));
102 QCOMPARE(indicator->position(), 1);
104 // Check that the initial properties have been set.
105 QVariantMap props = indicator->indicatorProperties().toMap();
106 QCOMPARE(props.count(), 4);
107 QCOMPARE(props["busName"].toString(), QString("com.canonical.indicator.fake1"));
108 QCOMPARE(props["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
110 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test2"));
111 }
113 /*
114 * Test switching the indicator profile data
115 */
116 void testPluginInterfaceProfileSwitch()
117 {
118 IndicatorsManager manager;
119 manager.setProfile("test1");
120 manager.load();
122 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
123 QVERIFY(indicator ? true : false);
125 QVariantMap props = indicator->indicatorProperties().toMap();
126 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test1"));
128 manager.setProfile("test2");
129 props = indicator->indicatorProperties().toMap();
130 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test2"));
131 }
133 /*
134 * Test if a new plugin object is create for each different plugin
135 */
136 void testPluginInstance()
137 {
138 IndicatorsManager manager;
139 manager.setProfile("test2");
140 manager.load();
142 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
143 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
144 QVERIFY(i0?true:false);
145 QVERIFY(i1?true:false);
146 QCOMPARE(i0, i1);
148 Indicator::Ptr i2 = manager.indicator("indicator-fake2");
149 QVERIFY(i2?true:false);
150 QVERIFY(i2 != i1);
151 QVERIFY(i2 != i1);
152 }
154 /*
155 * Test if a new plugin init function is called only once
156 */
157 void testPluginInitAndShutdown()
158 {
159 IndicatorsManager manager;
160 manager.setProfile("test1");
161 manager.load();
163 QWeakPointer<Indicator> wp0;
164 QWeakPointer<Indicator> wp1;
165 {
166 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
167 wp0 = i0.toWeakRef();
169 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
170 wp1 = i1.toWeakRef();
172 manager.unload();
173 // still alive while we have the shared pointers.
174 QVERIFY(!wp0.isNull());
175 QVERIFY(!wp1.isNull());
176 }
178 // no more smart pointers. should have been released.
179 QVERIFY(wp0.isNull());
180 QVERIFY(wp1.isNull());
181 }
182};
184QTEST_GUILESS_MAIN(IndicatorsManagerTest)
185#include "indicatorsmanagertest.moc"