on e82caeb help sign in
unity8/tests/plugins/Unity/Indicators/indicatorsmodeltest.cpp
109 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["title"] = "fake1";
70 QVariantMap map2; map2["title"] = "fake2";
71 QVariantMap map3; map3["title"] = "fake3";
72 QVariantMap map4; map4["title"] = "fake4";
73 map["indicator-fake1"] = map1;
74 map["indicator-fake2"] = map2;
75 map["indicator-fake3"] = map3;
76 map["indicator-fake4"] = map4;
78 IndicatorsModel model;
79 model.setIndicatorData(map);
80 model.load();
82 // should be in order:
83 // fake3, fake4, fake1, fake2
85 QCOMPARE(model.data(0, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake3"));
86 QCOMPARE(model.data(0, IndicatorsModelRole::Title).toString(), QString("fake3"));
87 QCOMPARE(model.data(0, IndicatorsModelRole::Position).toInt(), 3);
88 QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
90 QCOMPARE(model.data(1, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake4"));
91 QCOMPARE(model.data(1, IndicatorsModelRole::Title).toString(), QString("fake4"));
92 QCOMPARE(model.data(1, IndicatorsModelRole::Position).toInt(), 2);
93 QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
95 QCOMPARE(model.data(2, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake1"));
96 QCOMPARE(model.data(2, IndicatorsModelRole::Title).toString(), QString("fake1"));
97 QCOMPARE(model.data(2, IndicatorsModelRole::Position).toInt(), 1);
98 QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
100 QCOMPARE(model.data(3, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake2"));
101 QCOMPARE(model.data(3, IndicatorsModelRole::Title).toString(), QString("fake2"));
102 QCOMPARE(model.data(3, IndicatorsModelRole::Position).toInt(), 0);
103 QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
104 }
105};
107QTEST_GUILESS_MAIN(IndicatorsModelTest)
109#include "indicatorsmodeltest.moc"