on 1663e5c help sign in
unity8/tests/plugins/Unity/Indicators/indicatorsmanagertest.cpp
137 lines 3.9 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();
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 testPluginInterface()
68 {
69 IndicatorsManager manager;
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/phone"));
85 }
87 /*
88 * Test if a new plugin object is create for each different plugin
89 */
90 void testPluginInstance()
91 {
92 IndicatorsManager manager;
93 manager.load();
95 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
96 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
97 QVERIFY(i0?true:false);
98 QVERIFY(i1?true:false);
99 QCOMPARE(i0, i1);
101 Indicator::Ptr i2 = manager.indicator("indicator-fake2");
102 QVERIFY(i2?true:false);
103 QVERIFY(i2 != i1);
104 QVERIFY(i2 != i1);
105 }
107 /*
108 * Test if a new plugin init function is called only once
109 */
110 void testPluginInitAndShutdown()
111 {
112 IndicatorsManager manager;
113 manager.load();
115 QWeakPointer<Indicator> wp0;
116 QWeakPointer<Indicator> wp1;
117 {
118 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
119 wp0 = i0.toWeakRef();
121 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
122 wp1 = i1.toWeakRef();
124 manager.unload();
125 // still alive while we have the shared pointers.
126 QVERIFY(!wp0.isNull());
127 QVERIFY(!wp1.isNull());
128 }
130 // no more smart pointers. should have been released.
131 QVERIFY(wp0.isNull());
132 QVERIFY(wp1.isNull());
133 }
134};
136QTEST_GUILESS_MAIN(IndicatorsManagerTest)
137#include "indicatorsmanagertest.moc"