|
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: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 #include <QObject> |
|
20 #include <HbLabel> |
|
21 #include "wlanindicatorutcases.h" |
|
22 |
|
23 //static const char IndicatorType[] = |
|
24 // {"com.nokia.hb.indicator.connectivity.wlanindicatorplugin/1.0"}; |
|
25 |
|
26 QString WLAN_not_connected(hbTrId("txt_occ_dblist_wireless_lan_val_not_connected")); |
|
27 QString WLAN_connected(hbTrId("txt_occ_dblist_wireless_lan_val_1_connected")); |
|
28 QString WLAN_menu(hbTrId("txt_occ_dblist_indi_menu_wireless_lan")); |
|
29 QString Empty(""); |
|
30 QString Icon(""); |
|
31 |
|
32 enum WlanStates{ |
|
33 wlanIsNotConnected = 0, |
|
34 wlanIsConnected = 1 |
|
35 }; |
|
36 |
|
37 enum WlanIndicatorParameters{ |
|
38 wlanState = 0, |
|
39 wlanIapName = 1, |
|
40 }; |
|
41 |
|
42 WlanIndicatorUtCases::WlanIndicatorUtCases() |
|
43 { |
|
44 } |
|
45 |
|
46 WlanIndicatorUtCases::~WlanIndicatorUtCases() |
|
47 { |
|
48 } |
|
49 |
|
50 void WlanIndicatorUtCases::initTestCase() |
|
51 { |
|
52 } |
|
53 |
|
54 // Start of test cases |
|
55 void WlanIndicatorUtCases::wlanNotConnected() |
|
56 { |
|
57 qDebug("WLAN Not Connected"); |
|
58 bool result(true); |
|
59 QList<QVariant> params; |
|
60 |
|
61 params.insert(wlanState, wlanIsNotConnected ); |
|
62 |
|
63 result &= activateIndicator( &mWlanIndicatorPlugin ); |
|
64 result &= clientParameterHandler( &mWlanIndicatorPlugin, |
|
65 HbIndicatorInterface::RequestActivate, |
|
66 params, true ); |
|
67 result &= indicatorDataFeeder( &mWlanIndicatorPlugin, |
|
68 HbIndicatorInterface::SecondaryTextRole, |
|
69 WLAN_not_connected ); |
|
70 QVERIFY(result == true); |
|
71 } |
|
72 |
|
73 void WlanIndicatorUtCases::wlanConnected() |
|
74 { |
|
75 qDebug("WLAN Connected"); |
|
76 bool result(true); |
|
77 QList<QVariant> params; |
|
78 |
|
79 params.insert(wlanState, wlanIsConnected); |
|
80 params.insert(wlanIapName,"lahna"); |
|
81 |
|
82 result &= activateIndicator(&mWlanIndicatorPlugin); |
|
83 result &= clientParameterHandler(&mWlanIndicatorPlugin, |
|
84 HbIndicatorInterface::RequestActivate, |
|
85 params, true ); |
|
86 result &= indicatorDataFeeder( &mWlanIndicatorPlugin, |
|
87 HbIndicatorInterface::SecondaryTextRole, |
|
88 WLAN_connected); |
|
89 result &= indicatorIconFeeder( &mWlanIndicatorPlugin, |
|
90 HbIndicatorInterface::IconNameRole ); |
|
91 QVERIFY(result == true); |
|
92 } |
|
93 |
|
94 void WlanIndicatorUtCases::differentIndicatorData() |
|
95 { |
|
96 qDebug("Different indicator data handling"); |
|
97 bool result(true); |
|
98 |
|
99 result &= indicatorDataFeeder( &mWlanIndicatorPlugin, |
|
100 HbIndicatorInterface::PrimaryTextRole, WLAN_menu); |
|
101 |
|
102 result &= indicatorDataFeeder( &mWlanIndicatorPlugin, |
|
103 255, Empty); |
|
104 result &= indicatorIconFeeder( &mWlanIndicatorPlugin, |
|
105 HbIndicatorInterface::IconNameRole ); |
|
106 result &= indicatorIconFeeder( &mWlanIndicatorPlugin, |
|
107 HbIndicatorInterface::DecorationNameRole ); |
|
108 QVERIFY(result == true); |
|
109 } |
|
110 |
|
111 void WlanIndicatorUtCases::errorHandling() |
|
112 { |
|
113 qDebug("WLAN Indicator error handling"); |
|
114 bool result(true); |
|
115 |
|
116 result &= error( &mWlanIndicatorPlugin, 0 ); |
|
117 |
|
118 QVERIFY(result == true); |
|
119 } |
|
120 |
|
121 void WlanIndicatorUtCases::clientParamatersHandler() |
|
122 { |
|
123 qDebug("Parameter handling"); |
|
124 QList<QVariant> params; |
|
125 bool result(true); |
|
126 |
|
127 // Step 1: Deliver parameters for mParameter |
|
128 params.insert(wlanIapName, "lahna"); |
|
129 result &= clientParameterHandler( &mWlanIndicatorPlugin, |
|
130 HbIndicatorInterface::RequestActivate, |
|
131 params, |
|
132 true ); |
|
133 // Step 2: Clear parameters for mParameter |
|
134 result &= clientParameterHandler( &mWlanIndicatorPlugin, |
|
135 HbIndicatorInterface::RequestDeactivate, |
|
136 params, |
|
137 false ); |
|
138 // Step 3: Try to feed data with SecondaryTextRole. Data is not valid not because |
|
139 // mParameter has been cleared in Step 2 |
|
140 result &= indicatorDataFeeder( &mWlanIndicatorPlugin, |
|
141 HbIndicatorInterface::SecondaryTextRole, |
|
142 Empty ); |
|
143 QVERIFY(result == true); |
|
144 } |
|
145 |
|
146 void WlanIndicatorUtCases::handleInteractions() |
|
147 { |
|
148 qDebug("Interaction handling"); |
|
149 bool result(true); |
|
150 |
|
151 result &= handleInteraction( &mWlanIndicatorPlugin, |
|
152 HbIndicatorInterface::NoInteraction, |
|
153 false ); |
|
154 result &= handleInteraction( &mWlanIndicatorPlugin, |
|
155 HbIndicatorInterface::InteractionActivated, |
|
156 true ); |
|
157 |
|
158 QVERIFY(result == true); |
|
159 } |
|
160 |
|
161 void WlanIndicatorUtCases::processErrorHandling() |
|
162 { |
|
163 qDebug("WLAN Indicator error handling"); |
|
164 bool result(true); |
|
165 |
|
166 result &= processError( &mWlanIndicatorPlugin, QProcess::FailedToStart ); |
|
167 result &= processError( &mWlanIndicatorPlugin, QProcess::Crashed ); |
|
168 result &= processError( &mWlanIndicatorPlugin, QProcess::Timedout ); |
|
169 result &= processError( &mWlanIndicatorPlugin, QProcess::ReadError ); |
|
170 result &= processError( &mWlanIndicatorPlugin, QProcess::WriteError ); |
|
171 result &= processError( &mWlanIndicatorPlugin, QProcess::UnknownError ); |
|
172 |
|
173 QVERIFY(result == true); |
|
174 } |
|
175 // End of test cases |
|
176 |
|
177 // Sub-test cases |
|
178 bool WlanIndicatorUtCases::activateIndicator( WlanIndicatorPlugin* plugin ) |
|
179 { |
|
180 QStringList indTypes("com.nokia.hb.indicator.connectivity.wlanindicatorplugin/1.0"); |
|
181 QStringList resIndTypes(""); |
|
182 QString indTypeString(""); |
|
183 bool result(true); |
|
184 HbIndicatorInterface* resPtr(NULL); |
|
185 HbSecurityInfo* securityInfo = NULL; |
|
186 bool resAllowed(false); |
|
187 |
|
188 resIndTypes = plugin->indicatorTypes(); |
|
189 |
|
190 if (resIndTypes != indTypes) { |
|
191 qDebug("Indicator activation error: Erroneous IndicationType"); |
|
192 result = false; |
|
193 } |
|
194 |
|
195 resAllowed = plugin->accessAllowed( indTypeString, securityInfo ); |
|
196 |
|
197 if (resAllowed == false) { |
|
198 qDebug("Indicator activation error: Erroneous allowance"); |
|
199 result = false; |
|
200 } |
|
201 |
|
202 resPtr = plugin->createIndicator(indTypeString); |
|
203 |
|
204 if (resPtr == NULL) { |
|
205 qDebug("Indicator activation error: Indicator creation failed"); |
|
206 result = false; |
|
207 } |
|
208 return result; |
|
209 } |
|
210 |
|
211 bool WlanIndicatorUtCases::clientParameterHandler( WlanIndicatorPlugin* plugin, |
|
212 HbIndicatorInterface::RequestType ReqType, |
|
213 QVariant parameter, |
|
214 bool expectedResult ) |
|
215 { |
|
216 bool resHandled(false); |
|
217 bool result(true); |
|
218 |
|
219 resHandled = plugin->handleClientRequest( ReqType, parameter ); |
|
220 |
|
221 if (resHandled != expectedResult) { |
|
222 qDebug("Indicator error: Error in client request handling"); |
|
223 result = false; |
|
224 } |
|
225 return result; |
|
226 } |
|
227 |
|
228 bool WlanIndicatorUtCases::indicatorDataFeeder( WlanIndicatorPlugin* plugin, |
|
229 int role, |
|
230 QString expectedString ) |
|
231 { |
|
232 QString resString; |
|
233 bool result(true); |
|
234 |
|
235 resString = plugin->indicatorData(role).toString(); |
|
236 int x = QString::compare(resString, expectedString, Qt::CaseInsensitive); |
|
237 |
|
238 if (x != 0) { |
|
239 qDebug("Indicator error: Error in indicatorData"); |
|
240 result = false; |
|
241 } |
|
242 return result; |
|
243 } |
|
244 |
|
245 bool WlanIndicatorUtCases::indicatorIconFeeder( WlanIndicatorPlugin* plugin, |
|
246 int role ) |
|
247 { |
|
248 QVariant resIcon; |
|
249 bool result(true); |
|
250 |
|
251 resIcon = plugin->indicatorData(role); |
|
252 int x = 0; |
|
253 |
|
254 if (x != 0) { |
|
255 qDebug("Indicator error: Error in indicatorData"); |
|
256 result = false; |
|
257 } |
|
258 return result; |
|
259 } |
|
260 |
|
261 bool WlanIndicatorUtCases::error( WlanIndicatorPlugin* plugin, |
|
262 int expectedError ) |
|
263 { |
|
264 int error; |
|
265 bool result(true); |
|
266 |
|
267 error = plugin->error(); |
|
268 |
|
269 if (error != expectedError) { |
|
270 qDebug("Indicator error: Error in error value"); |
|
271 result = false; |
|
272 } |
|
273 return result; |
|
274 } |
|
275 |
|
276 bool WlanIndicatorUtCases::handleInteraction( WlanIndicatorPlugin* plugin, |
|
277 HbIndicatorInterface::InteractionType type, |
|
278 bool handleValue ) |
|
279 { |
|
280 bool resHandle(false); |
|
281 bool result(true); |
|
282 |
|
283 resHandle = plugin->handleInteraction( type ); |
|
284 |
|
285 if (resHandle != handleValue) { |
|
286 qDebug("Indicator error: Error in interaction handling"); |
|
287 result = false; |
|
288 } |
|
289 return result; |
|
290 } |
|
291 |
|
292 bool WlanIndicatorUtCases::processError( WlanIndicatorPlugin* plugin, |
|
293 QProcess::ProcessError err ) |
|
294 { |
|
295 bool result(true); |
|
296 plugin->processError( err ); |
|
297 return result; |
|
298 } |