on cd24bfb help sign in
unity8/tests/plugins/Unity/Indicators/indicatorsmodeltest.cpp
143 lines 7.5 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"
23#include <paths.h>
25#include <QtTest>
26#include <QDebug>
28class IndicatorsModelTest : public QObject
30 Q_OBJECT
31private Q_SLOTS:
33 void initTestCase()
34 {
35 setenv("UNITY_TEST_ENV", "1", 1);
36 setenv("XDG_DATA_DIRS", (sourceDirectory() + "/tests/data").toLatin1().data(), 1);
37 }
39 void cleanupTestCase()
40 {
41 unsetenv("UNITY_TEST_ENV");
42 }
44 /*
45 * Testa that all the plugins are loaded / unloaded correctly
46 */
47 void testLoad()
48 {
49 IndicatorsModel model;
50 model.setProfile("test1");
52 QCOMPARE(model.property("count").toInt(), 0);
54 model.load();
56 QCOMPARE(model.property("count").toInt(), 4);
58 model.unload();
60 QCOMPARE(model.property("count").toInt(), 0);
62 }
64 /*
65 * Testa that the plugin data was loaded correctly ( "test1" )
66 */
67 void testDataAndOrderProfile1()
68 {
69 // Priority order. (2, 1, 4, 3)
70 IndicatorsModel model;
71 model.setProfile("test1");
72 model.load();
74 // should be in order:
75 // fake3, fake4, fake1, fake2
77 QCOMPARE(model.data(0, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake3"));
78 QCOMPARE(model.data(0, IndicatorsModelRole::Position).toInt(), 3);
79 QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
80 QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake3"));
81 QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake3/test1"));
83 QCOMPARE(model.data(1, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake4"));
84 QCOMPARE(model.data(1, IndicatorsModelRole::Position).toInt(), 2);
85 QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
86 QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake4"));
87 QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake4/test1"));
89 QCOMPARE(model.data(2, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake1"));
90 QCOMPARE(model.data(2, IndicatorsModelRole::Position).toInt(), 1);
91 QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
92 QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
93 QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test1"));
95 QCOMPARE(model.data(3, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake2"));
96 QCOMPARE(model.data(3, IndicatorsModelRole::Position).toInt(), 0);
97 QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
98 QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake2"));
99 QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake2/test1"));
100 }
102 /*
103 * Testa that the plugin data was loaded correctly ( "test2" )
104 */
105 void testDataAndOrderProfile2()
106 {
107 // Priority order. (2, 1, 4, 3)
108 IndicatorsModel model;
109 model.setProfile("test2");
110 model.load();
112 // should be in order:
113 // fake3, fake4, fake1, fake2
115 QCOMPARE(model.data(0, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake3"));
116 QCOMPARE(model.data(0, IndicatorsModelRole::Position).toInt(), 3);
117 QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
118 QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake3"));
119 QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake3/test2"));
121 QCOMPARE(model.data(1, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake4"));
122 QCOMPARE(model.data(1, IndicatorsModelRole::Position).toInt(), 2);
123 QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
124 QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake4"));
125 QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake4/test2"));
127 QCOMPARE(model.data(2, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake1"));
128 QCOMPARE(model.data(2, IndicatorsModelRole::Position).toInt(), 1);
129 QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
130 QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
131 QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test2"));
133 QCOMPARE(model.data(3, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake2"));
134 QCOMPARE(model.data(3, IndicatorsModelRole::Position).toInt(), 0);
135 QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
136 QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake2"));
137 QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake2/test2"));
138 }
139};
141QTEST_GUILESS_MAIN(IndicatorsModelTest)
143#include "indicatorsmodeltest.moc"