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 * This is the source file for testing Wlan Qt Utilities library. |
|
16 */ |
|
17 |
|
18 #include <QtCore> |
|
19 #include <QTest> |
|
20 #include <QSignalSpy> |
|
21 #include <rconnmon.h> |
|
22 #include <nifvar.h> |
|
23 #include "wlanqtutilscommon.h" |
|
24 #include "wlanqtutilswlanap.h" |
|
25 #include "wlanqtutilsiap.h" |
|
26 #include "wlanqtutilswlaniap.h" |
|
27 #include "wlanqtutils.h" |
|
28 #include "wlanqtutils_p.h" |
|
29 #include "wlanqtutilsconmonwrapper.h" |
|
30 #include "wlanqtutilsconmonwrapper_s60_p.h" |
|
31 #include "wlanqtutilsconntestwrapper.h" |
|
32 #include "wlanqtutilsconntestwrapper_s60_p.h" |
|
33 #include "testwlanqtutils.h" |
|
34 #include "wlanqtutilstestcontext.h" |
|
35 |
|
36 WlanQtUtilsTestContext testContext; |
|
37 |
|
38 const QString TestWlanQtUtils::commsDatDefault_ = "default.cre"; |
|
39 |
|
40 // --------------------------------------------------------- |
|
41 // FRAMEWORK FUNCTIONS |
|
42 // --------------------------------------------------------- |
|
43 |
|
44 /** |
|
45 * This function will be called before the first test function is executed. |
|
46 */ |
|
47 void TestWlanQtUtils::initTestCase() |
|
48 { |
|
49 wlanQtUtils_ = NULL; |
|
50 signalScanReady_ = NULL; |
|
51 signalWlanNetworkOpened_ = NULL; |
|
52 signalWlanNetworkClosed_ = NULL; |
|
53 |
|
54 //If Active scheduler exists then don't install a new one as it will cause panic |
|
55 if (CActiveScheduler::Current() == NULL) { |
|
56 CActiveScheduler *scheduler = new CActiveScheduler(); |
|
57 CActiveScheduler::Install(scheduler); |
|
58 } |
|
59 } |
|
60 |
|
61 /** |
|
62 * This function will be called after the last test function was executed. |
|
63 */ |
|
64 void TestWlanQtUtils::cleanupTestCase() |
|
65 { |
|
66 // CommsDat file is initialized. |
|
67 subTestLoadCommsDatFile(commsDatDefault_); |
|
68 |
|
69 // TODO: Can we get rid of this delay? |
|
70 QWARN(": \n *********** \n * PASSED! * \n *********** \n\n\n"); |
|
71 QWARN(": \n *** Window will be closed in 5s... \n\n\n"); |
|
72 QTest::qSleep(5000); |
|
73 } |
|
74 |
|
75 /** |
|
76 * This function will be called before each test function is executed. |
|
77 */ |
|
78 void TestWlanQtUtils::init() |
|
79 { |
|
80 // CommsDat file is initialized. |
|
81 subTestLoadCommsDatFile(commsDatDefault_); |
|
82 |
|
83 testContext.initialize(); |
|
84 |
|
85 QVERIFY(wlanQtUtils_ == NULL); |
|
86 QVERIFY(signalScanReady_ == NULL); |
|
87 QVERIFY(signalWlanNetworkOpened_ == NULL); |
|
88 QVERIFY(signalWlanNetworkClosed_ == NULL); |
|
89 subTestNewWlanQtUtils(); |
|
90 } |
|
91 |
|
92 /** |
|
93 * This function will be called after each test function is executed. |
|
94 */ |
|
95 void TestWlanQtUtils::cleanup() |
|
96 { |
|
97 delete wlanQtUtils_; |
|
98 wlanQtUtils_ = NULL; |
|
99 |
|
100 QCOMPARE(signalScanReady_->count(), 0); |
|
101 delete signalScanReady_; |
|
102 signalScanReady_ = NULL; |
|
103 |
|
104 QCOMPARE(signalWlanNetworkOpened_->count(), 0); |
|
105 delete signalWlanNetworkOpened_; |
|
106 signalWlanNetworkOpened_ = NULL; |
|
107 |
|
108 QCOMPARE(signalWlanNetworkClosed_->count(), 0); |
|
109 delete signalWlanNetworkClosed_; |
|
110 signalWlanNetworkClosed_ = NULL; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------- |
|
114 // TEST CASES |
|
115 // --------------------------------------------------------- |
|
116 |
|
117 /** |
|
118 * Test available WLAN APs when scan is triggered by client. |
|
119 * Two scan results have the same SSID and the latter one of those will be removed. |
|
120 * Two scan results have the same SSID but different security mode |
|
121 * and both are included in the results. |
|
122 */ |
|
123 void TestWlanQtUtils::testAvailableWlanAps() |
|
124 { |
|
125 testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(10); |
|
126 testContext.connMon_.wlanScanResult_.wlanScanResultList_[0]->setSsid("Same SSID"); |
|
127 testContext.connMon_.wlanScanResult_.wlanScanResultList_[2]->setSsid("Same SSID"); |
|
128 testContext.connMon_.wlanScanResult_.wlanScanResultList_[5]->setSsid("Same SSID, different SecMode"); |
|
129 testContext.connMon_.wlanScanResult_.wlanScanResultList_[5]->setSecurityMode(WlanQtUtilsWlanSecModeWpa); |
|
130 testContext.connMon_.wlanScanResult_.wlanScanResultList_[8]->setSsid("Same SSID, different SecMode"); |
|
131 testContext.connMon_.wlanScanResult_.wlanScanResultList_[8]->setSecurityMode(WlanQtUtilsWlanSecModeOpen); |
|
132 |
|
133 // Request a scan to get result signal |
|
134 wlanQtUtils_->scanWlans(); |
|
135 |
|
136 // Let active object run and verify signal. |
|
137 subTestSignalWaitAndTake(signalScanReady_, NULL); |
|
138 |
|
139 // Get and verify the list of available WLAN APs. |
|
140 QList<WlanQtUtilsWlanIap *> iaps; |
|
141 QList<WlanQtUtilsWlanAp *> aps; |
|
142 wlanQtUtils_->availableWlanAps(iaps, aps); |
|
143 |
|
144 // First remove AP that has duplicate SSID. |
|
145 // Then order APs alphabetically. |
|
146 testContext.connMon_.wlanScanResult_.wlanScanResultList_.removeAt(2); |
|
147 testContext.connMon_.wlanScanResult_.wlanScanResultList_.move(4, 1); |
|
148 testContext.connMon_.wlanScanResult_.wlanScanResultList_.move(7, 1); |
|
149 testContext.connMon_.wlanScanResult_.wlanScanResultList_.move(8, 3); |
|
150 testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps); |
|
151 QCOMPARE(iaps.count(), 0); |
|
152 aps.clear(); // TODO: Free AP pointers too. |
|
153 } |
|
154 |
|
155 /** |
|
156 * Test available WLAN APs when there are also WLAN IAPs available. |
|
157 */ |
|
158 void TestWlanQtUtils::testAvailableWlanApsWithIaps() |
|
159 { |
|
160 testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(7); |
|
161 testContext.connMon_.wlanScanResult_.wlanScanResultList_[1]->setSsid("WLAN IAP 3"); |
|
162 testContext.connMon_.wlanScanResult_.wlanScanResultList_[1]->setSecurityMode(WlanQtUtilsWlanSecModeWpa); |
|
163 testContext.connMon_.wlanScanResult_.wlanScanResultList_[3]->setSsid(""); |
|
164 testContext.connMon_.wlanScanResult_.wlanScanResultList_[5]->setSsid("WLAN IAP 1"); |
|
165 // Todo: security mode not compared yet due to an issue with CMM vs ConnMon WLAN security |
|
166 // modes under investigation |
|
167 // SSID is found in Internet Snap, but security mode does not match: |
|
168 // testContext.connMon_.wlanScanResult_.wlanScanResultList_[6]->setSsid("WLAN IAP 2"); |
|
169 // testContext.connMon_.wlanScanResult_.wlanScanResultList_[6]->setSecurityMode(WlanQtUtilsWlanSecModeWpa); |
|
170 |
|
171 // Request a scan to get result signal |
|
172 wlanQtUtils_->scanWlans(); |
|
173 |
|
174 // Let active object run and verify signal. |
|
175 subTestSignalWaitAndTake(signalScanReady_, NULL); |
|
176 |
|
177 // Get and verify the list of available WLAN APs. |
|
178 QList<WlanQtUtilsWlanIap *> iaps; |
|
179 QList<WlanQtUtilsWlanAp *> aps; |
|
180 wlanQtUtils_->availableWlanAps(iaps, aps); |
|
181 |
|
182 // Verify WLAN AP list. First, remove scan results that will not appear |
|
183 // because they are hidden WLANs or WLAN IAPs. |
|
184 testContext.connMon_.wlanScanResult_.wlanScanResultList_.removeAt(5); |
|
185 testContext.connMon_.wlanScanResult_.wlanScanResultList_.removeAt(3); |
|
186 testContext.connMon_.wlanScanResult_.wlanScanResultList_.removeAt(1); |
|
187 testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps); |
|
188 |
|
189 // Verify WLAN IAP list |
|
190 QCOMPARE(iaps.count(), 2); |
|
191 QCOMPARE(iaps[0]->id(), 5); |
|
192 QCOMPARE(iaps[0]->name(), QString("WLAN IAP 1")); |
|
193 QCOMPARE(iaps[0]->bearerType(), WlanQtUtilsBearerTypeWlan); |
|
194 QCOMPARE(iaps[0]->ssid(), QString("WLAN IAP 1")); |
|
195 QCOMPARE(iaps[1]->id(), 7); |
|
196 QCOMPARE(iaps[1]->name(), QString("WLAN IAP 3")); |
|
197 QCOMPARE(iaps[1]->bearerType(), WlanQtUtilsBearerTypeWlan); |
|
198 QCOMPARE(iaps[1]->ssid(), QString("WLAN IAP 3")); |
|
199 iaps.clear(); // TODO: Free IAP pointers too. |
|
200 aps.clear(); // TODO: Free AP pointers too. |
|
201 } |
|
202 |
|
203 /** |
|
204 * Test refereshing of WLAN APs when client requests sequential scans. |
|
205 */ |
|
206 void TestWlanQtUtils::testAvailableWlanApsSequence() |
|
207 { |
|
208 // **************** Before 1st scan ******************** |
|
209 QList<WlanQtUtilsWlanIap *> iaps; |
|
210 QList<WlanQtUtilsWlanAp *> aps; |
|
211 wlanQtUtils_->availableWlanAps(iaps, aps); |
|
212 // Verify we have no results |
|
213 QCOMPARE(aps.count(), 0); |
|
214 QCOMPARE(iaps.count(), 0); |
|
215 |
|
216 // **************** 1st scan ******************** |
|
217 // 6 APs are required for this scan |
|
218 testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(6); |
|
219 |
|
220 wlanQtUtils_->scanWlans(); |
|
221 subTestSignalWaitAndTake(signalScanReady_, NULL); |
|
222 |
|
223 // Get the results for the 1st scan |
|
224 wlanQtUtils_->availableWlanAps(iaps, aps); |
|
225 // Verify the results for the scan |
|
226 testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps); |
|
227 QCOMPARE(iaps.count(), 0); |
|
228 aps.clear(); // TODO: free memory of pointers too. |
|
229 |
|
230 // **************** 2nd scan ******************** |
|
231 // 2 APs are required for this scan |
|
232 testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(2); |
|
233 |
|
234 wlanQtUtils_->scanWlans(); |
|
235 subTestSignalWaitAndTake(signalScanReady_, NULL); |
|
236 |
|
237 // Get the results for the 2nd scan |
|
238 wlanQtUtils_->availableWlanAps(iaps, aps); |
|
239 // Verify the results for the scan |
|
240 testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps); |
|
241 QCOMPARE(iaps.count(), 0); |
|
242 aps.clear(); // TODO: Free memory |
|
243 |
|
244 // **************** 3rd scan ******************** |
|
245 // 4 APs are required for the 3rd scan |
|
246 testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(4); |
|
247 |
|
248 wlanQtUtils_->scanWlans(); |
|
249 subTestSignalWaitAndTake(signalScanReady_, NULL); |
|
250 |
|
251 // Get the results for the 3rd scan |
|
252 wlanQtUtils_->availableWlanAps(iaps, aps); |
|
253 // Verify the results for the scan |
|
254 testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps); |
|
255 QCOMPARE(iaps.count(), 0); |
|
256 aps.clear(); // TODO: Free memory |
|
257 } |
|
258 |
|
259 /** |
|
260 * This function tests creation of WLAN IAP in a succesful manner. |
|
261 * - WLAN scan is made because otherwise we cannot verify that IAP creation is successful. |
|
262 * - Check that there are no available WLAN IAPs. |
|
263 * - Fetch SNAP list. |
|
264 * - Create WLAN IAP. |
|
265 * - Check that WLAN IAP has been created and that this IAP is not in WLAN AP scan results. |
|
266 */ |
|
267 void TestWlanQtUtils::testCreateWlanIapOk() |
|
268 { |
|
269 testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(1); |
|
270 testContext.connMon_.wlanScanResult_.wlanScanResultList_[0]->setSsid("New WLAN IAP"); |
|
271 testContext.connMon_.wlanScanResult_.wlanScanResultList_[0]->setSecurityMode(WlanQtUtilsWlanSecModeWpa2); |
|
272 |
|
273 // Create a new instance in order to test functionality triggered in constructor. |
|
274 WlanQtUtils *utils = new WlanQtUtils(); |
|
275 QSignalSpy spy(utils, SIGNAL(wlanScanReady())); |
|
276 QVERIFY(spy.isValid() == true); |
|
277 subTestSignalWaitAndTake(&spy, NULL); |
|
278 |
|
279 // Ensure there are no WLAN IAPs but there is one scan result. |
|
280 QList<WlanQtUtilsWlanIap *> iaps; |
|
281 QList<WlanQtUtilsWlanAp *> aps; |
|
282 utils->availableWlanAps(iaps, aps); |
|
283 |
|
284 QCOMPARE(iaps.count(), 0); |
|
285 testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps); |
|
286 |
|
287 // Execute createWlanIap() function |
|
288 WlanQtUtilsWlanAp wlanAp("New WLAN IAP", "abcdef", 90, EConnMonInfraStructure, WlanQtUtilsWlanSecModeWpa2); |
|
289 int iapId = utils->createWlanIap(&wlanAp); |
|
290 |
|
291 // Verify that created IAP is in the IAP list and AP list is empty. |
|
292 utils->availableWlanAps(iaps, aps); |
|
293 QCOMPARE(iaps.count(), 1); |
|
294 QCOMPARE(iaps[0]->id(), iapId); |
|
295 QCOMPARE(iaps[0]->name(), QString("New WLAN IAP")); |
|
296 QCOMPARE(iaps[0]->bearerType(), WlanQtUtilsBearerTypeWlan); |
|
297 QCOMPARE(iaps[0]->ssid(), QString("New WLAN IAP")); |
|
298 // Todo: should be Wpa2, CMM vs ConnMon WLAN security modes under investigation |
|
299 QCOMPARE(iaps[0]->securityMode(), WlanQtUtilsWlanSecModeWpa); |
|
300 QCOMPARE(aps.count(), 0); |
|
301 iaps.clear(); // TODO: memory leak. |
|
302 delete utils; |
|
303 } |
|
304 |
|
305 /** |
|
306 * This function tests connecting to IAP in a succesful manner. |
|
307 */ |
|
308 void TestWlanQtUtils::testConnectIapOk() |
|
309 { |
|
310 testContext.esock_.startRetValue_ = KErrNone; |
|
311 |
|
312 // Esock stub completes connection creation immediately |
|
313 wlanQtUtils_->connectIap(5); |
|
314 |
|
315 // Connection creation in ConnMon interface |
|
316 testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5); |
|
317 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonEventBase( |
|
318 EConnMonCreateConnection, |
|
319 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId())); |
|
320 |
|
321 // Connection status change in ConnMon interface |
|
322 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonConnectionStatusChange( |
|
323 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(), |
|
324 0, |
|
325 KConnectionOpen)); |
|
326 |
|
327 // Receive signal for connection opening (caused by connectIap, which completed immediately) |
|
328 QList<QVariant> arguments; |
|
329 subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); |
|
330 QCOMPARE(arguments.at(0).toInt(), 5); |
|
331 |
|
332 // Connection status change to opened in ConnMon interface. Sub test cases between test |
|
333 // cases check that no extra signals are sent |
|
334 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonConnectionStatusChange( |
|
335 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(), |
|
336 0, |
|
337 KLinkLayerOpen)); |
|
338 } |
|
339 |
|
340 /** |
|
341 * This function tests connecting to IAP in unsuccesful manner. |
|
342 */ |
|
343 void TestWlanQtUtils::testConnectIapErr() |
|
344 { |
|
345 testContext.esock_.startRetValue_ = KErrGeneral; |
|
346 |
|
347 wlanQtUtils_->connectIap(7); |
|
348 |
|
349 testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 7); |
|
350 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonEventBase( |
|
351 EConnMonCreateConnection, |
|
352 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId())); |
|
353 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonConnectionStatusChange( |
|
354 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(), |
|
355 0, |
|
356 KConnectionOpen)); |
|
357 |
|
358 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonEventBase( |
|
359 EConnMonDeleteConnection, |
|
360 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId())); |
|
361 |
|
362 QList<QVariant> arguments; |
|
363 subTestSignalWaitAndTake(signalWlanNetworkClosed_, &arguments); |
|
364 QCOMPARE(arguments.at(0).toInt(), 7); |
|
365 } |
|
366 |
|
367 // TODO: testDisconnectFail cases are needed when fail branches are |
|
368 // implemented into the connmon wrapper |
|
369 /** |
|
370 * This function tests IAP disconnecting functionality. |
|
371 */ |
|
372 void TestWlanQtUtils::testDisconnectIapOk() |
|
373 { |
|
374 // Create and connect an IAP we can then disconnect |
|
375 WlanQtUtilsWlanAp wlanAp("Disconnect IAP", "abcdef", 90, EConnMonInfraStructure, WlanQtUtilsWlanSecModeWpa2); |
|
376 int iapId = wlanQtUtils_->createWlanIap(&wlanAp); |
|
377 testContext.esock_.startRetValue_ = KErrNone; |
|
378 wlanQtUtils_->connectIap(iapId); |
|
379 QList<QVariant> arguments; |
|
380 subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); |
|
381 QCOMPARE(arguments.at(0).toInt(), iapId); |
|
382 |
|
383 // The disconnect function does not have any return values or |
|
384 // signals related to the disconnection, thus plain |
|
385 // function call is done for the test. |
|
386 wlanQtUtils_->disconnectIap(iapId); |
|
387 } |
|
388 |
|
389 /** |
|
390 * This function tests IAP getter with existing IAP ID. |
|
391 */ |
|
392 void TestWlanQtUtils::testIapFound() |
|
393 { |
|
394 // Create the IAP we want to find with the getter |
|
395 WlanQtUtilsWlanAp wlanAp("testIapFound", "abcdef", 90, EConnMonInfraStructure, WlanQtUtilsWlanSecModeWpa2); |
|
396 int iapId = wlanQtUtils_->createWlanIap(&wlanAp); |
|
397 |
|
398 // Execute the function under test and check that we got the correct IAP |
|
399 WlanQtUtilsIap *iap = wlanQtUtils_->iap(iapId); |
|
400 QVERIFY(iap != NULL); |
|
401 QCOMPARE(iap->id(), iapId); |
|
402 QCOMPARE(iap->name(), QString("testIapFound")); |
|
403 QCOMPARE(iap->bearerType(), WlanQtUtilsBearerTypeWlan); |
|
404 } |
|
405 |
|
406 /** |
|
407 * This function tests IAP getter with non-existing IAP ID. |
|
408 */ |
|
409 void TestWlanQtUtils::testIapNotFound() |
|
410 { |
|
411 // Execute the function under test and check that we get no IAP as result |
|
412 WlanQtUtilsIap *iap = wlanQtUtils_->iap(1000); |
|
413 QVERIFY(iap == NULL); |
|
414 } |
|
415 |
|
416 /** |
|
417 * This function tests connected WLAN IAP getter with existing connection. |
|
418 */ |
|
419 void TestWlanQtUtils::testConnectedWlanIdFound() |
|
420 { |
|
421 // Create the IAP we want to find with the getter |
|
422 WlanQtUtilsWlanAp wlanAp("testConnectedWlanIdFound", "abcdef", 90, EConnMonInfraStructure, WlanQtUtilsWlanSecModeWpa2); |
|
423 int iapId = wlanQtUtils_->createWlanIap(&wlanAp); |
|
424 |
|
425 testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, iapId); |
|
426 |
|
427 // Send event for connection creation. |
|
428 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonEventBase( |
|
429 EConnMonCreateConnection, |
|
430 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId())); |
|
431 |
|
432 // Send events for connection status change -> opened. |
|
433 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonConnectionStatusChange( |
|
434 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(), |
|
435 0, |
|
436 KStartingConnection)); |
|
437 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonConnectionStatusChange( |
|
438 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(), |
|
439 0, |
|
440 KLinkLayerOpen)); |
|
441 |
|
442 QList<QVariant> arguments; |
|
443 subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); |
|
444 QCOMPARE(arguments.at(0).toInt(), iapId); |
|
445 |
|
446 // Execute the function under test and check that we get valid ID as result |
|
447 int id = wlanQtUtils_->connectedWlanId(); |
|
448 QCOMPARE(id, iapId); |
|
449 } |
|
450 |
|
451 /** |
|
452 * This function tests connected WLAN IAP getter with connection existing already during dll construction. |
|
453 */ |
|
454 void TestWlanQtUtils::testConnectedWlanIdFoundConstructor() |
|
455 { |
|
456 // IAP ID 5 exists in default commsdat file |
|
457 testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5); |
|
458 |
|
459 // Create a new instance in order to test functionality triggered in constructor. |
|
460 WlanQtUtils *utils = new WlanQtUtils(); |
|
461 |
|
462 // Execute the function under test and check that we get valid ID as result |
|
463 int id = utils->connectedWlanId(); |
|
464 QCOMPARE(id, 5); |
|
465 |
|
466 delete utils; |
|
467 } |
|
468 |
|
469 /** |
|
470 * This function tests connected WLAN IAP getter without existing connection. |
|
471 */ |
|
472 void TestWlanQtUtils::testConnectedWlanIdNotFound() |
|
473 { |
|
474 // Execute the function under test and check that we get invalid ID as result |
|
475 int id = wlanQtUtils_->connectedWlanId(); |
|
476 QCOMPARE(id, WlanQtUtilsInvalidIapId); |
|
477 } |
|
478 |
|
479 /** |
|
480 * Test WLAN scan triggering interface. |
|
481 */ |
|
482 void TestWlanQtUtils::testScanWlans() |
|
483 { |
|
484 // Execute function under test |
|
485 wlanQtUtils_->scanWlans(); |
|
486 |
|
487 // No need to verify scan results here, testAvailableWlanAps* test cases |
|
488 // are for that. Just make sure the result signal is received. |
|
489 subTestSignalWaitAndTake(signalScanReady_, NULL); |
|
490 } |
|
491 |
|
492 /** |
|
493 * This function tests Wlan network opening signal when network is not opened by the dll. |
|
494 */ |
|
495 void TestWlanQtUtils::testWlanNetworkOpened() |
|
496 { |
|
497 testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5); |
|
498 |
|
499 // Send event for connection creation. |
|
500 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonEventBase( |
|
501 EConnMonCreateConnection, |
|
502 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId())); |
|
503 |
|
504 // Send events for connection status change -> opened. |
|
505 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonConnectionStatusChange( |
|
506 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(), |
|
507 0, |
|
508 KConnectionOpen)); |
|
509 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonConnectionStatusChange( |
|
510 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(), |
|
511 0, |
|
512 KLinkLayerOpen)); |
|
513 |
|
514 QList<QVariant> arguments; |
|
515 subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); |
|
516 QCOMPARE(arguments.at(0).toInt(), 5); |
|
517 } |
|
518 |
|
519 /** |
|
520 * This function tests Wlan network closing signal when network is not closed by the dll. |
|
521 */ |
|
522 void TestWlanQtUtils::testWlanNetworkClosed() |
|
523 { |
|
524 // First create a connection |
|
525 testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5); |
|
526 |
|
527 // Send event for connection creation. |
|
528 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonEventBase( |
|
529 EConnMonCreateConnection, |
|
530 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId())); |
|
531 |
|
532 // Send events for connection status change -> opened. |
|
533 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonConnectionStatusChange( |
|
534 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(), |
|
535 0, |
|
536 KConnectionOpen)); |
|
537 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonConnectionStatusChange( |
|
538 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(), |
|
539 0, |
|
540 KLinkLayerOpen)); |
|
541 |
|
542 QList<QVariant> arguments; |
|
543 subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); |
|
544 QCOMPARE(arguments.at(0).toInt(), 5); |
|
545 |
|
546 // Send event for connection status change -> closed. |
|
547 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonConnectionStatusChange( |
|
548 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(), |
|
549 0, |
|
550 KLinkLayerClosed)); |
|
551 |
|
552 // Send event for connection deletion. |
|
553 wlanQtUtils_->d_ptr->conMonWrapper_->d_ptrConnInfo->EventL(CConnMonEventBase( |
|
554 EConnMonDeleteConnection, |
|
555 testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId())); |
|
556 |
|
557 subTestSignalWaitAndTake(signalWlanNetworkClosed_, &arguments); |
|
558 QCOMPARE(arguments.at(0).toInt(), 5); |
|
559 } |
|
560 |
|
561 /** |
|
562 * This function tests ICT when connection test passes. |
|
563 */ |
|
564 void TestWlanQtUtils::testConnectionTestPass() |
|
565 { |
|
566 // Create and connect an IAP we can then test |
|
567 WlanQtUtilsWlanAp wlanAp("Connection test IAP", "abcdef", 90, EConnMonInfraStructure, WlanQtUtilsWlanSecModeWpa2); |
|
568 int iapId = wlanQtUtils_->createWlanIap(&wlanAp); |
|
569 testContext.esock_.startRetValue_ = KErrNone; |
|
570 wlanQtUtils_->connectIap(iapId); |
|
571 QList<QVariant> arguments; |
|
572 subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); |
|
573 QCOMPARE(arguments.at(0).toInt(), iapId); |
|
574 |
|
575 // Connection test automatically started at this point. Call result function explicitly |
|
576 // No interface exists that we could check that the IAP is moved to Internet SNAP correctly |
|
577 TBuf<5> string; |
|
578 wlanQtUtils_->d_ptr->connTestWrapper_->d_ptr_->ConnectivityObserver(EConnectionOk, string); |
|
579 } |
|
580 |
|
581 /** |
|
582 * This function tests ICT when connection test fails. |
|
583 */ |
|
584 void TestWlanQtUtils::testConnectionTestFail() |
|
585 { |
|
586 // Create and connect an IAP we can then test |
|
587 WlanQtUtilsWlanAp wlanAp("Connection test IAP", "abcdef", 90, EConnMonInfraStructure, WlanQtUtilsWlanSecModeWpa2); |
|
588 int iapId = wlanQtUtils_->createWlanIap(&wlanAp); |
|
589 testContext.esock_.startRetValue_ = KErrNone; |
|
590 wlanQtUtils_->connectIap(iapId); |
|
591 QList<QVariant> arguments; |
|
592 subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); |
|
593 QCOMPARE(arguments.at(0).toInt(), iapId); |
|
594 |
|
595 // Connection test automatically started at this point. Call result function explicitly |
|
596 // No interface exists that we could check that IAP is not moved to another SNAP |
|
597 // Todo: Repeat for all possible error codes to gain coverage |
|
598 TBuf<5> string; |
|
599 wlanQtUtils_->d_ptr->connTestWrapper_->d_ptr_->ConnectivityObserver(EHttpAuthenticationNeeded, string); |
|
600 } |
|
601 |
|
602 // --------------------------------------------------------- |
|
603 // SUB TEST CASES |
|
604 // --------------------------------------------------------- |
|
605 |
|
606 /** |
|
607 * This function waits for active objects to get time to run, takes the arguments of the |
|
608 * first signal and returns them from the given signal spy. |
|
609 * This function also verifies that the number of signals is 1. |
|
610 * |
|
611 * @param[in] spy Signal spy. |
|
612 * @param[out] arguments Arguments of the first signal in the given signal spy. NULL if arguments not needed. |
|
613 */ |
|
614 void TestWlanQtUtils::subTestSignalWaitAndTake(QSignalSpy* spy, QList<QVariant>* arguments) |
|
615 { |
|
616 QTest::qWait(1); |
|
617 QCOMPARE(spy->count(), 1); |
|
618 QList<QVariant> arguments_tmp = spy->takeFirst(); |
|
619 if (arguments != NULL) { |
|
620 *arguments = arguments_tmp; |
|
621 } |
|
622 } |
|
623 |
|
624 /** |
|
625 * This function loads given CommsDat file, replacing current one. |
|
626 * If CommsDat file doesn't exist, it can be re-created by commanding WST script. |
|
627 * Using help switch is a quick way: |
|
628 * run_wst HELP |
|
629 * |
|
630 * @param newCommsdatFilename Filename of the new CommsDat to be loaded. |
|
631 */ |
|
632 void TestWlanQtUtils::subTestLoadCommsDatFile(QString newCommsdatFilename) |
|
633 { |
|
634 // EPOC's CommsDat filename |
|
635 const QString epocCommsdatFilename("cccccc00.cre"); |
|
636 // EPOC's directory for CommsDat file |
|
637 const QString commsdatDir("c:\\private\\10202be9\\persists\\"); |
|
638 // Created backup directory under EPOC for CommsDat files |
|
639 const QString storeDir("c:\\private\\10202be9\\persists\\backup\\"); |
|
640 QString nameOld = commsdatDir + epocCommsdatFilename; |
|
641 QString nameDefault = storeDir + newCommsdatFilename; |
|
642 |
|
643 // First remove the old CommsDat file. |
|
644 Q_ASSERT(QFile::remove(nameOld) == TRUE); |
|
645 |
|
646 // Copy the stored default CommsDat file. |
|
647 Q_ASSERT(QFile::copy(nameDefault, nameOld) == TRUE); |
|
648 } |
|
649 |
|
650 /** |
|
651 * |
|
652 */ |
|
653 void TestWlanQtUtils::subTestNewWlanQtUtils() |
|
654 { |
|
655 if (wlanQtUtils_ != NULL) { |
|
656 delete wlanQtUtils_; |
|
657 } |
|
658 wlanQtUtils_ = new WlanQtUtils(); |
|
659 |
|
660 if (signalScanReady_ != NULL) { |
|
661 delete signalScanReady_; |
|
662 } |
|
663 signalScanReady_ = new QSignalSpy(wlanQtUtils_, SIGNAL(wlanScanReady())); |
|
664 QVERIFY(signalScanReady_->isValid() == true); |
|
665 |
|
666 if (signalWlanNetworkOpened_ != NULL) { |
|
667 delete signalWlanNetworkOpened_; |
|
668 } |
|
669 signalWlanNetworkOpened_ = new QSignalSpy(wlanQtUtils_, SIGNAL(wlanNetworkOpened(int))); |
|
670 QVERIFY(signalWlanNetworkOpened_->isValid() == true); |
|
671 |
|
672 if (signalWlanNetworkClosed_ != NULL) { |
|
673 delete signalWlanNetworkClosed_; |
|
674 } |
|
675 signalWlanNetworkClosed_ = new QSignalSpy(wlanQtUtils_, SIGNAL(wlanNetworkClosed(int))); |
|
676 QVERIFY(signalWlanNetworkClosed_->isValid() == true); |
|
677 |
|
678 // Let first active objects to run. First WLAN scan is done in engine contructor. |
|
679 subTestSignalWaitAndTake(signalScanReady_, NULL); |
|
680 } |
|
681 |
|
682 // Create main function using QTest marco. |
|
683 QTEST_MAIN(TestWlanQtUtils) |
|