2 * Copyright 2012 Canonical Ltd.
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.
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.
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/>.
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
20#include "fakeindicator.h"
21#include "indicatorsmanager.h"
22#include "indicatorsfactory.h"
28FAKE_INDICATOR(1, "Fake Title 1", "fake-indicator-1")
29FAKE_INDICATOR(2, "Fake Title 2", "fake-indicator-2")
31class IndicatorsManagerTest : public QObject
37 setenv("XDG_DATA_DIRS", (sourceDirectory() + "/tests/data").toLatin1().data(), 1);
39 IndicatorsFactory::instance().registerIndicator<FakeIndicatorClient1>("indicator-fake1");
40 IndicatorsFactory::instance().registerIndicator<FakeIndicatorClient2>("indicator-fake2");
44 * Test if all plugins is loaded correct
49 IndicatorsManager manager;
51 QVERIFY(!manager.isLoaded());
52 QCOMPARE(manager.indicators().count(), 0);
56 QVERIFY(manager.isLoaded());
57 QCOMPARE(manager.indicators().count(), 2);
61 QVERIFY(!manager.isLoaded());
62 QCOMPARE(manager.indicators().count(), 0);
66 * Test the creation & initialising of the indicator data
68 void testPluginInterface()
70 IndicatorsManager manager;
73 IndicatorClientInterface::Ptr indicator = manager.indicator("indicator-fake1");
74 QVERIFY(indicator.get());
76 QCOMPARE(indicator->identifier(), QString("indicator-fake1"));
77 QCOMPARE(indicator->icon(), QUrl("image://gicon/fake-indicator-1"));
78 QCOMPARE(indicator->title(), QString("Fake Title 1"));
79 QCOMPARE(indicator->label(), QString());
80 QCOMPARE(indicator->description(), QString());
81 QCOMPARE(indicator->priority(), 1);
83 IndicatorClientInterface::WidgetsMap widgets = indicator->widgets();
84 QCOMPARE(widgets.count(), 2);
85 QCOMPARE(widgets["com.canonical.button"], QUrl("Button.qml"));
86 QCOMPARE(widgets["com.canonical.label"], QUrl("Label.qml"));
88 // Check that the initial properties have been set.
89 IndicatorClientInterface::PropertiesMap props = indicator->initialProperties();
90 QCOMPARE(props.count(), 4);
91 QCOMPARE(props["title"].toString(), QString("Fake Title 1"));
92 QCOMPARE(props["busType"].toInt(), 1);
93 QCOMPARE(props["busName"].toString(), QString("com.canonical.indicator.fake1"));
94 QCOMPARE(props["objectPath"].toString(), QString("/com/canonical/indicator/fake1"));
98 * Test if a new plugin object is create for each different plugin
100 void testPluginInstance()
102 IndicatorsManager manager;
105 IndicatorClientInterface::Ptr i0 = manager.indicator("indicator-fake1");
106 IndicatorClientInterface::Ptr i1 = manager.indicator("indicator-fake1");
107 QVERIFY(i0?true:false);
108 QVERIFY(i1?true:false);
111 IndicatorClientInterface::Ptr i2 = manager.indicator("indicator-fake2");
112 QVERIFY(i2?true:false);
118 * Test if a new plugin init function is called only once
120 void testPluginInitAndShutdown()
122 IndicatorsManager manager;
125 QPointer<QObject> pi0;
126 QPointer<QObject> pi1;
128 IndicatorClientInterface::Ptr i0 = manager.indicator("indicator-fake1");
129 pi0 = dynamic_cast<QObject*>(i0.get());
130 QCOMPARE(pi0->property("initializedCount").toInt(), 1);
132 IndicatorClientInterface::Ptr i1 = manager.indicator("indicator-fake1");
133 pi1 = dynamic_cast<QObject*>(i1.get());
134 QCOMPARE(pi0->property("initializedCount").toInt(), 1);
135 QCOMPARE(pi1->property("initializedCount").toInt(), 1);
138 // still alive while we have the shared pointers.
139 QVERIFY(!pi0.isNull());
140 QVERIFY(!pi1.isNull());
144 // no more smart pointers. should have been released.
145 QVERIFY(pi0.isNull());
146 QVERIFY(pi1.isNull());
150QTEST_MAIN(IndicatorsManagerTest)
151#include "indicatorsmanagertest.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list