on 14ca310 help sign in
unity8/tests/plugins/Unity/Indicators/indicatorsmanagertest.cpp
160 lines 4.8 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.load("test1");
55 QVERIFY(manager.isLoaded());
56 QCOMPARE(manager.indicators().count(), 4);
58 manager.unload();
60 QVERIFY(!manager.isLoaded());
61 QCOMPARE(manager.indicators().count(), 0);
62 }
64 /*
65 * Test the creation & initialising of the indicator data
66 */
67 void testPluginInterfaceProfile1()
68 {
69 IndicatorsManager manager;
70 manager.load("test1");
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.load("test2");
95 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
96 QVERIFY(indicator ? true : false);
98 QCOMPARE(indicator->identifier(), QString("indicator-fake1"));
99 QCOMPARE(indicator->position(), 1);
101 // Check that the initial properties have been set.
102 QVariantMap props = indicator->indicatorProperties().toMap();
103 QCOMPARE(props.count(), 4);
104 QCOMPARE(props["busName"].toString(), QString("com.canonical.indicator.fake1"));
105 QCOMPARE(props["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
107 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test2"));
108 }
110 /*
111 * Test if a new plugin object is create for each different plugin
112 */
113 void testPluginInstance()
114 {
115 IndicatorsManager manager;
116 manager.load("test2");
118 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
119 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
120 QVERIFY(i0?true:false);
121 QVERIFY(i1?true:false);
122 QCOMPARE(i0, i1);
124 Indicator::Ptr i2 = manager.indicator("indicator-fake2");
125 QVERIFY(i2?true:false);
126 QVERIFY(i2 != i1);
127 QVERIFY(i2 != i1);
128 }
130 /*
131 * Test if a new plugin init function is called only once
132 */
133 void testPluginInitAndShutdown()
134 {
135 IndicatorsManager manager;
136 manager.load("test1");
138 QWeakPointer<Indicator> wp0;
139 QWeakPointer<Indicator> wp1;
140 {
141 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
142 wp0 = i0.toWeakRef();
144 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
145 wp1 = i1.toWeakRef();
147 manager.unload();
148 // still alive while we have the shared pointers.
149 QVERIFY(!wp0.isNull());
150 QVERIFY(!wp1.isNull());
151 }
153 // no more smart pointers. should have been released.
154 QVERIFY(wp0.isNull());
155 QVERIFY(wp1.isNull());
156 }
157};
159QTEST_GUILESS_MAIN(IndicatorsManagerTest)
160#include "indicatorsmanagertest.moc"