on f4e1764 help sign in
unity8/tests/plugins/Unity/Indicators/indicatorsmanagertest.cpp
136 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"
21#include "paths.h"
23#include <QtTest>
24#include <QDebug>
26class IndicatorsManagerTest : public QObject
28 Q_OBJECT
29private Q_SLOTS:
31 void initTestCase()
32 {
33 setenv("UNITY_TEST_ENV", "1", 1);
34 setenv("XDG_DATA_DIRS", (sourceDirectory() + "/tests/data").toLatin1().data(), 1);
35 }
37 void cleanupTestCase()
38 {
39 unsetenv("UNITY_TEST_ENV");
40 }
42 /*
43 * Test if all plugins is loaded correct
44 */
45 void testLoad()
46 {
47 IndicatorsManager manager;
49 QVERIFY(!manager.isLoaded());
50 QCOMPARE(manager.indicators().count(), 0);
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 testPluginInterface()
67 {
68 IndicatorsManager manager;
69 manager.load();
71 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
72 QVERIFY(indicator ? true : false);
74 QCOMPARE(indicator->identifier(), QString("indicator-fake1"));
75 QCOMPARE(indicator->position(), 1);
77 // Check that the initial properties have been set.
78 QVariantMap props = indicator->indicatorProperties().toMap();
79 QCOMPARE(props.count(), 4);
80 QCOMPARE(props["busName"].toString(), QString("com.canonical.indicator.fake1"));
81 QCOMPARE(props["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
83 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/phone"));
84 }
86 /*
87 * Test if a new plugin object is create for each different plugin
88 */
89 void testPluginInstance()
90 {
91 IndicatorsManager manager;
92 manager.load();
94 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
95 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
96 QVERIFY(i0?true:false);
97 QVERIFY(i1?true:false);
98 QCOMPARE(i0, i1);
100 Indicator::Ptr i2 = manager.indicator("indicator-fake2");
101 QVERIFY(i2?true:false);
102 QVERIFY(i2 != i1);
103 QVERIFY(i2 != i1);
104 }
106 /*
107 * Test if a new plugin init function is called only once
108 */
109 void testPluginInitAndShutdown()
110 {
111 IndicatorsManager manager;
112 manager.load();
114 QWeakPointer<Indicator> wp0;
115 QWeakPointer<Indicator> wp1;
116 {
117 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
118 wp0 = i0.toWeakRef();
120 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
121 wp1 = i1.toWeakRef();
123 manager.unload();
124 // still alive while we have the shared pointers.
125 QVERIFY(!wp0.isNull());
126 QVERIFY(!wp1.isNull());
127 }
129 // no more smart pointers. should have been released.
130 QVERIFY(wp0.isNull());
131 QVERIFY(wp1.isNull());
132 }
133};
135QTEST_GUILESS_MAIN(IndicatorsManagerTest)
136#include "indicatorsmanagertest.moc"