|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: XENT-MV |
|
13 * |
|
14 * Description: unit tests for the CpThemeControl class from themeplugin |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 #include <QModelIndex> |
|
20 #include <QSignalSpy> |
|
21 |
|
22 #include "cpthemechanger.h" |
|
23 #include "cpthemecontrol.h" |
|
24 #include "cpthemechanger.h" |
|
25 |
|
26 class TestCpThemeControl : public QObject |
|
27 { |
|
28 Q_OBJECT |
|
29 |
|
30 private slots: |
|
31 void init(); |
|
32 |
|
33 void testConstructor(); |
|
34 void testThemeListView(); |
|
35 void testCurrentThemeName(); |
|
36 void testCurrentThemeIcon(); |
|
37 void testNewThemeSelected(); |
|
38 void testPreviewClosed(); |
|
39 void testThemeApplied(); |
|
40 void testUpdateThemeList(); |
|
41 |
|
42 void cleanup(); |
|
43 |
|
44 private: |
|
45 CpThemeChanger* mThemeChanger; |
|
46 }; |
|
47 |
|
48 // setup and cleanup |
|
49 void TestCpThemeControl::init() |
|
50 { |
|
51 mThemeChanger = new CpThemeChanger(); |
|
52 } |
|
53 |
|
54 void TestCpThemeControl::cleanup() |
|
55 { |
|
56 delete mThemeChanger; |
|
57 } |
|
58 |
|
59 // verify that the constructor works and that the |
|
60 // defaults are sane. |
|
61 void TestCpThemeControl::testConstructor() |
|
62 { |
|
63 CpThemeControl * control = new CpThemeControl(); |
|
64 |
|
65 QVERIFY(control !=0 ); |
|
66 QVERIFY(!control->currentThemeName().isEmpty()); |
|
67 QVERIFY(!control->currentThemeIcon().isEmpty()); |
|
68 |
|
69 delete control; |
|
70 } |
|
71 |
|
72 // verify that the themeListView doesn't return NULL (or crash) |
|
73 void TestCpThemeControl::testThemeListView() |
|
74 { |
|
75 CpThemeControl control; |
|
76 |
|
77 QVERIFY(control.themeListView() != 0); |
|
78 } |
|
79 |
|
80 // test that we get back a non-empty QString |
|
81 void TestCpThemeControl::testCurrentThemeName() |
|
82 { |
|
83 CpThemeControl control; |
|
84 |
|
85 QVERIFY((control.currentThemeName() == mThemeChanger->currentTheme()) |
|
86 || (control.currentThemeName() == QString("hbdefault"))); |
|
87 } |
|
88 |
|
89 // test that we get a non-empty string for current theme icon |
|
90 void TestCpThemeControl::testCurrentThemeIcon() |
|
91 { |
|
92 CpThemeControl control; |
|
93 |
|
94 QVERIFY(!control.currentThemeIcon().isEmpty()); |
|
95 } |
|
96 |
|
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 |
|
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 |
|
145 |
|
146 |
|
147 QTEST_MAIN(TestCpThemeControl) |
|
148 #include "unittest_cpthemecontrol.moc" |