on e220ccd help sign in
unity8/tests/plugins/Unity/Indicators/indicatorsmodeltest.cpp
94 lines 3.2 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 IndicatorsModel model;
69 model.load();
71 // should be in order:
72 // fake3, fake4, fake1, fake2
74 QCOMPARE(model.data(0, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake3"));
75 QCOMPARE(model.data(0, IndicatorsModelRole::Position).toInt(), 3);
76 QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
78 QCOMPARE(model.data(1, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake4"));
79 QCOMPARE(model.data(1, IndicatorsModelRole::Position).toInt(), 2);
80 QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
82 QCOMPARE(model.data(2, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake1"));
83 QCOMPARE(model.data(2, IndicatorsModelRole::Position).toInt(), 1);
84 QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
86 QCOMPARE(model.data(3, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake2"));
87 QCOMPARE(model.data(3, IndicatorsModelRole::Position).toInt(), 0);
88 QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
89 }
90};
92QTEST_GUILESS_MAIN(IndicatorsModelTest)
94#include "indicatorsmodeltest.moc"