on 574bbde help sign in
unity8/tests/modules/Unity/Indicators/indicatorsmodeltest.cpp
101 lines 3.4 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 "paths.h"
23#include <QtTest>
24#include <QDebug>
26class IndicatorsModelTest : public QObject
28 Q_OBJECT
29private Q_SLOTS:
31 void initTestCase()
32 {
33 setenv("UNITY_TEST_ENV", "1", 1);
34 setenv("XDG_DATA_DIRS", (sourceDirectory() + "/tests/data").toLatin1().data(), 1);
35 }
37 void cleanupTestCase()
38 {
39 unsetenv("UNITY_TEST_ENV");
40 }
42 /*
43 * Testa that all the plugins are loaded / unloaded correctly
44 */
45 void testLoad()
46 {
47 IndicatorsModel model;
49 QCOMPARE(model.property("count").toInt(), 0);
51 model.load();
53 QCOMPARE(model.property("count").toInt(), 4);
55 model.unload();
57 QCOMPARE(model.property("count").toInt(), 0);
59 }
61 /*
62 * Testa that the plugin data was loaded correctly
63 */
64 void testDataAndOrder()
65 {
66 // Priority order. (2, 1, 4, 3)
67 QVariantMap map;
68 QVariantMap map1; map1["priority"] = 1; map1["title"] = "fake1";
69 QVariantMap map2; map2["priority"] = 0; map2["title"] = "fake2";
70 QVariantMap map3; map3["priority"] = 3; map3["title"] = "fake3";
71 QVariantMap map4; map4["priority"] = 2; map4["title"] = "fake4";
72 map["indicator-fake1"] = map1;
73 map["indicator-fake2"] = map2;
74 map["indicator-fake3"] = map3;
75 map["indicator-fake4"] = map4;
77 IndicatorsModel model;
78 model.setIndicatorData(map);
79 model.load();
81 QCOMPARE(model.get(0)["identifier"].toString(), QString("indicator-fake2"));
82 QCOMPARE(model.get(0)["title"].toString(), QString("fake2"));
83 QCOMPARE(model.get(0)["indicatorProperties"].toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
85 QCOMPARE(model.get(1)["identifier"].toString(), QString("indicator-fake1"));
86 QCOMPARE(model.get(1)["title"].toString(), QString("fake1"));
87 QCOMPARE(model.get(1)["indicatorProperties"].toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
89 QCOMPARE(model.get(2)["identifier"].toString(), QString("indicator-fake4"));
90 QCOMPARE(model.get(2)["title"].toString(), QString("fake4"));
91 QCOMPARE(model.get(2)["indicatorProperties"].toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
93 QCOMPARE(model.get(3)["identifier"].toString(), QString("indicator-fake3"));
94 QCOMPARE(model.get(3)["title"].toString(), QString("fake3"));
95 QCOMPARE(model.get(3)["indicatorProperties"].toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
96 }
97};
99QTEST_MAIN(IndicatorsModelTest)
101#include "indicatorsmodeltest.moc"