14 * Description: unit tests for the CpThemeControl class from themeplugin |
14 * Description: unit tests for the CpThemeControl class from themeplugin |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <QtTest/QtTest> |
18 #include <QtTest/QtTest> |
19 #include <QModelIndex> |
|
20 #include <QSignalSpy> |
19 #include <QSignalSpy> |
|
20 |
|
21 #include <hbinstance.h> |
|
22 #include <hbtheme.h> |
21 |
23 |
22 #include "cpthemechanger.h" |
24 #include "cpthemechanger.h" |
23 #include "cpthemecontrol.h" |
25 #include "cpthemecontrol.h" |
24 #include "cpthemechanger.h" |
26 #include "cpthemeinfo.h" |
|
27 #include "cpthemeutil.h" |
25 |
28 |
26 class TestCpThemeControl : public QObject |
29 class TestCpThemeControl : public QObject |
27 { |
30 { |
28 Q_OBJECT |
31 Q_OBJECT |
29 |
32 |
30 private slots: |
33 private slots: |
31 void init(); |
|
32 |
34 |
33 void testConstructor(); |
35 void testConstructor(); |
34 void testThemeListView(); |
36 void testThemeListView(); |
35 void testCurrentThemeName(); |
37 void testCurrentThemeName(); |
36 void testCurrentThemeIcon(); |
38 void testCurrentThemeIcon(); |
37 void testNewThemeSelected(); |
39 |
38 void testPreviewClosed(); |
|
39 void testThemeApplied(); |
|
40 void testUpdateThemeList(); |
|
41 |
|
42 void cleanup(); |
|
43 |
|
44 private: |
40 private: |
45 CpThemeChanger* mThemeChanger; |
41 CpThemeChanger* mThemeChanger; |
46 }; |
42 }; |
47 |
43 |
48 // setup and cleanup |
|
49 void TestCpThemeControl::init() |
|
50 { |
|
51 mThemeChanger = new CpThemeChanger(); |
|
52 } |
|
53 |
44 |
54 void TestCpThemeControl::cleanup() |
|
55 { |
|
56 delete mThemeChanger; |
|
57 } |
|
58 |
45 |
59 // verify that the constructor works and that the |
46 // verify that the constructor works and that the |
60 // defaults are sane. |
47 // defaults are sane. |
61 void TestCpThemeControl::testConstructor() |
48 void TestCpThemeControl::testConstructor() |
62 { |
49 { |
63 CpThemeControl * control = new CpThemeControl(); |
50 CpThemeControl * control = new CpThemeControl(); |
64 |
51 |
65 QVERIFY(control !=0 ); |
52 QVERIFY(control !=0 ); |
66 QVERIFY(!control->currentThemeName().isEmpty()); |
53 QVERIFY(!control->currentThemeName().isEmpty()); |
67 QVERIFY(!control->currentThemeIcon().isEmpty()); |
54 QVERIFY(!control->currentThemeIcon().iconName().isEmpty()); |
68 |
55 |
69 delete control; |
56 delete control; |
70 } |
57 } |
71 |
58 |
72 // verify that the themeListView doesn't return NULL (or crash) |
59 // verify that the themeListView doesn't return NULL (or crash) |
80 // test that we get back a non-empty QString |
67 // test that we get back a non-empty QString |
81 void TestCpThemeControl::testCurrentThemeName() |
68 void TestCpThemeControl::testCurrentThemeName() |
82 { |
69 { |
83 CpThemeControl control; |
70 CpThemeControl control; |
84 |
71 |
85 QVERIFY((control.currentThemeName() == mThemeChanger->currentTheme()) |
72 QVERIFY( (control.currentThemeName() == hbInstance->theme()->name()) |
86 || (control.currentThemeName() == QString("hbdefault"))); |
73 || (control.currentThemeName() == QString("hbdefault"))); |
87 } |
74 } |
88 |
75 |
89 // test that we get a non-empty string for current theme icon |
76 // test that we get a non-empty string for current theme icon |
90 void TestCpThemeControl::testCurrentThemeIcon() |
77 void TestCpThemeControl::testCurrentThemeIcon() |
91 { |
78 { |
92 CpThemeControl control; |
79 CpThemeControl control; |
93 |
80 |
94 QVERIFY(!control.currentThemeIcon().isEmpty()); |
81 QVERIFY(!control.currentThemeIcon().isNull() && !control.currentThemeIcon().iconName().isEmpty()); |
95 } |
82 } |
96 |
83 |
97 // NULL test there's no way to externally get the model the QModelIndex is based on |
|
98 void TestCpThemeControl::testNewThemeSelected() |
|
99 { |
|
100 CpThemeControl control; |
|
101 |
|
102 control.newThemeSelected(QModelIndex()); |
|
103 |
|
104 } |
|
105 |
|
106 // NULL test - basically verifies that it doesn't burst into flames. |
|
107 void TestCpThemeControl::testPreviewClosed() |
|
108 { |
|
109 CpThemeControl control; |
|
110 |
|
111 control.previewClosed(); |
|
112 |
|
113 } |
|
114 |
84 |
115 void TestCpThemeControl::testThemeApplied() |
|
116 { |
|
117 CpThemeControl control; |
|
118 QList<CpThemeChanger::ThemeInfo> themeList = mThemeChanger->themes(); |
|
119 QSignalSpy spy(&control, SIGNAL(themeUpdated(const QString&, const QString&))); |
|
120 int expectedSignalCount = 0; |
|
121 |
|
122 for (int i = 0; i < themeList.size(); ++i) { |
|
123 CpThemeChanger::ThemeInfo info = themeList.at(i); |
|
124 QString name = info.themeName; |
|
125 |
|
126 if (control.currentThemeName() == mThemeChanger->currentTheme()) { |
|
127 ++expectedSignalCount; |
|
128 } |
|
129 |
|
130 control.themeApplied(name); |
|
131 QCOMPARE(control.currentThemeName(), mThemeChanger->currentTheme()); |
|
132 |
|
133 QCOMPARE(spy.count(),expectedSignalCount); |
|
134 } |
|
135 } |
|
136 |
|
137 // NULL test - basically verifies that it doesn't burst into flames. |
|
138 void TestCpThemeControl::testUpdateThemeList() |
|
139 { |
|
140 CpThemeControl control; |
|
141 |
|
142 control.updateThemeList(); |
|
143 } |
|
144 |
85 |
145 |
86 |
146 |
87 |
147 QTEST_MAIN(TestCpThemeControl) |
88 QTEST_MAIN(TestCpThemeControl) |
148 #include "unittest_cpthemecontrol.moc" |
89 #include "unittest_cpthemecontrol.moc" |