on a4713ff help sign in
unity8/tests/plugins/IndicatorsClient/indicatorsmodeltest.cpp
96 lines 2.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 "fakeindicator.h"
21#include "indicatorsmodel.h"
22#include "indicatorsfactory.h"
23#include "paths.h"
25#include <QtTest>
26#include <QDebug>
28FAKE_INDICATOR(1, "Fake Title 1", "fake-indicator-1")
29FAKE_INDICATOR(2, "Fake Title 2", "fake-indicator-2")
31class IndicatorsModelTest : public QObject
33 Q_OBJECT
34private Q_SLOTS:
36 void initTestCase() {
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");
41 }
43 /*
44 * Test if all plugins is loaded correct
45 */
46 void testLoad()
47 {
48 IndicatorsModel model;
50 QCOMPARE(model.property("count").toInt(), 0);
52 model.load();
54 QCOMPARE(model.property("count").toInt(), 2);
56 model.unload();
58 QCOMPARE(model.property("count").toInt(), 0);
60 }
62 /*
63 * Test if the plugin data was loaded correct
64 */
65 void testDataOrder()
66 {
67 IndicatorsModel model;
68 model.load();
70 QVariantMap data = model.get(0);
71 QCOMPARE(data["title"].toString(), QString("Fake Title 1"));
72 QCOMPARE(data["label"].toString(), QString());
73 QCOMPARE(data["iconSource"].value<QUrl>(), QUrl("image://gicon/fake-indicator-1"));
74 QCOMPARE(data["description"].toString(), QString());
75 // There is no QML context
76 QVERIFY(!data["component"].value<QObject*>());
77 QCOMPARE(data["isValid"].toBool(), true);
79 data = model.get(1);
80 QCOMPARE(data["title"].toString(), QString("Fake Title 2"));
81 QCOMPARE(data["label"].toString(), QString());
82 QCOMPARE(data["iconSource"].value<QUrl>(), QUrl("image://gicon/fake-indicator-2"));
83 QCOMPARE(data["description"].toString(), QString());
84 // There is no QML context
85 QVERIFY(!data["component"].value<QObject*>());
86 QCOMPARE(data["isValid"].toBool(), true);
88 data = model.get(3);
89 QVERIFY(data.isEmpty());
90 }
91};
93QTEST_MAIN(IndicatorsModelTest)
95#include "indicatorsmodeltest.moc"