on 09cdf79 help sign in
unity8/tests/plugins/Unity/Indicators/indicatorsmodeltest.cpp
107 lines 4.0 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 "indicatorsmodel.h"
21#include "indicators.h"
22#include "paths.h"
24#include <QtTest>
25#include <QDebug>
27class IndicatorsModelTest : 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 * Testa that all the plugins are loaded / unloaded correctly
45 */
46 void testLoad()
47 {
48 IndicatorsModel model;
50 QCOMPARE(model.property("count").toInt(), 0);
52 model.load();
54 QCOMPARE(model.property("count").toInt(), 4);
56 model.unload();
58 QCOMPARE(model.property("count").toInt(), 0);
60 }
62 /*
63 * Testa that the plugin data was loaded correctly
64 */
65 void testDataAndOrder()
66 {
67 // Priority order. (2, 1, 4, 3)
68 QVariantMap map;
69 QVariantMap map1; map1["widgetSource"] = "fake1.qml";
70 QVariantMap map2; map2["widgetSource"] = "fake2.qml";
71 QVariantMap map3; map3["widgetSource"] = "fake3.qml";
72 map["indicator-fake1"] = map1;
73 map["indicator-fake2"] = map2;
74 map["indicator-fake3"] = map3;
76 IndicatorsModel model;
77 model.setIndicatorData(map);
78 model.load();
80 // should be in order:
81 // fake3, fake4, fake1, fake2
83 QCOMPARE(model.data(0, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake3"));
84 QCOMPARE(model.data(0, IndicatorsModelRole::Position).toInt(), 3);
85 QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
86 QCOMPARE(model.data(0, IndicatorsModelRole::WidgetSource).toString(), QString("fake3.qml"));
88 QCOMPARE(model.data(1, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake4"));
89 QCOMPARE(model.data(1, IndicatorsModelRole::Position).toInt(), 2);
90 QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
91 QCOMPARE(model.data(1, IndicatorsModelRole::WidgetSource).toString(), shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorWidget2.qml");
93 QCOMPARE(model.data(2, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake1"));
94 QCOMPARE(model.data(2, IndicatorsModelRole::Position).toInt(), 1);
95 QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
96 QCOMPARE(model.data(2, IndicatorsModelRole::WidgetSource).toString(), QString("fake1.qml"));
98 QCOMPARE(model.data(3, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake2"));
99 QCOMPARE(model.data(3, IndicatorsModelRole::Position).toInt(), 0);
100 QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
101 QCOMPARE(model.data(3, IndicatorsModelRole::WidgetSource).toString(), QString("fake2.qml"));
102 }
103};
105QTEST_GUILESS_MAIN(IndicatorsModelTest)
107#include "indicatorsmodeltest.moc"