|
1 /* |
|
2 * Copyright (c) 2010 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 * Control Panel WLAN AP plugin unit testing. |
|
16 */ |
|
17 |
|
18 #include <HbApplication> |
|
19 #include <HbMainWindow> |
|
20 #include <HbView> |
|
21 #include <HbDialog> |
|
22 #include <HbRadioButtonList> |
|
23 #include <HbAction> |
|
24 #include <HbDataForm> |
|
25 #include <HbDataFormModel> |
|
26 #include <HbDataFormModelItem> |
|
27 #include <QtTest/QtTest> |
|
28 #include <cpbearerapplugininterface.h> |
|
29 #include <cmmanager_shim.h> |
|
30 #include <cmconnectionmethod_shim.h> |
|
31 |
|
32 #include "cpwlanapview.h" |
|
33 |
|
34 #include "hbautotest.h" |
|
35 #include "testcpwlanapplugin.h" |
|
36 |
|
37 // Following flag must be defined if WLAN security settings plugins |
|
38 // (WEP, WPA/WPA2 and WPA2) are available. Flag can be removed when the |
|
39 // plugins are released. |
|
40 #define WLAN_SECURITY_PLUGINS_AVAILABLE |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // STATIC TEST DATA |
|
44 // ----------------------------------------------------------------------------- |
|
45 |
|
46 // Connection method (AP) ID used for testing |
|
47 static const uint testApId = 5; |
|
48 |
|
49 static const QString pluginDir = |
|
50 "\\resource\\qt\\plugins\\controlpanel\\bearerap"; |
|
51 |
|
52 static const QString pluginName = "cpwlanapplugin.dll"; |
|
53 |
|
54 // Time to wait before continuing after an UI step |
|
55 static const int waitTime = 10; |
|
56 |
|
57 // UI coordinates |
|
58 static const QPoint connectionNameLabel(175, 70); |
|
59 |
|
60 static const QPoint connectionNameLineEdit(330, 110); |
|
61 |
|
62 static const QPoint wlanNetworkNameLineEdit(330, 190); |
|
63 |
|
64 static const QPoint networkStatusComboBox(175, 270); |
|
65 static const QPoint networkStatusPublic(175, 325); |
|
66 static const QPoint networkStatusHidden(175, 375); |
|
67 |
|
68 static const QPoint networkModeComboBox(175, 365); |
|
69 static const QPoint networkModeIntrastructure(175, 415); |
|
70 static const QPoint networkModeAdHoc(175, 465); |
|
71 |
|
72 static const QPoint securityModeComboBox(175, 460); |
|
73 #ifndef WLAN_SECURITY_PLUGINS_AVAILABLE |
|
74 static const QPoint securityModeOpen(175, 510); |
|
75 #else |
|
76 static const QPoint securityModeOpen(175, 260); |
|
77 static const QPoint securityModeWep(175, 305); |
|
78 static const QPoint securityModeWpaWpa2(175, 355); |
|
79 static const QPoint securityModeWpa2(175, 405); |
|
80 #endif |
|
81 |
|
82 static const QPoint homepageLineEdit(330, 545); |
|
83 |
|
84 static const QPoint messageBoxOkButton(170, 320); |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // FRAMEWORK FUNCTIONS |
|
88 // ----------------------------------------------------------------------------- |
|
89 |
|
90 /** |
|
91 * Test main function. Runs all test cases. |
|
92 */ |
|
93 #ifndef TESTCMAPPLSETTINGSUI_NO_OUTPUT_REDIRECT |
|
94 int main(int argc, char *argv[]) |
|
95 { |
|
96 HbApplication app(argc, argv); |
|
97 app.setApplicationName("TestCpWlanApPlugin"); |
|
98 |
|
99 char *pass[3]; |
|
100 pass[0] = argv[0]; |
|
101 pass[1] = "-o"; |
|
102 pass[2] = "c:\\data\\TestCpWlanApPlugin.txt"; |
|
103 |
|
104 TestCpWlanApPlugin tc; |
|
105 int res = QTest::qExec(&tc, 3, pass); |
|
106 |
|
107 return res; |
|
108 } |
|
109 #else |
|
110 QTEST_MAIN(TestCpWlanApPlugin) |
|
111 #endif |
|
112 |
|
113 /** |
|
114 * This function is be called before the first test case is executed. |
|
115 */ |
|
116 void TestCpWlanApPlugin::initTestCase() |
|
117 { |
|
118 mMainWindow = new HbAutoTestMainWindow; |
|
119 //mMainWindow = new HbMainWindow; |
|
120 mMainWindow->show(); |
|
121 |
|
122 // Load plugin |
|
123 QDir dir(pluginDir); |
|
124 QPluginLoader loader(dir.absoluteFilePath(pluginName)); |
|
125 mPlugin = qobject_cast<CpBearerApPluginInterface *>(loader.instance()); |
|
126 QVERIFY(mPlugin != NULL); |
|
127 |
|
128 // Verify plugin bearer type |
|
129 QVERIFY(mPlugin->bearerType() == CMManagerShim::BearerTypeWlan); |
|
130 |
|
131 // Create WLAN settings view (connection method ID given) |
|
132 subCreateSettingsView(testApId); |
|
133 } |
|
134 |
|
135 /** |
|
136 * This function is be called after the last test case was executed. |
|
137 */ |
|
138 void TestCpWlanApPlugin::cleanupTestCase() |
|
139 { |
|
140 delete mMainWindow; |
|
141 mMainWindow = 0; |
|
142 } |
|
143 |
|
144 /** |
|
145 * This function is be called before each test case is executed. |
|
146 */ |
|
147 void TestCpWlanApPlugin::init() |
|
148 { |
|
149 QTest::qWait(1000); |
|
150 } |
|
151 |
|
152 /** |
|
153 * This function is be called after each test case is executed. |
|
154 */ |
|
155 void TestCpWlanApPlugin::cleanup() |
|
156 { |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // TEST CASES |
|
161 // ----------------------------------------------------------------------------- |
|
162 |
|
163 /** |
|
164 * Tests changing of connection name. |
|
165 */ |
|
166 void TestCpWlanApPlugin::tcChangeConnectionName() |
|
167 { |
|
168 QFETCH(QString, string); |
|
169 QFETCH(QString, result); |
|
170 |
|
171 HbAutoTest::mouseClick(mMainWindow, mTestView, connectionNameLineEdit); |
|
172 |
|
173 // Erase old string |
|
174 subClearLineEdit(CMManagerShim::CmNameLength); |
|
175 |
|
176 // Enter new string |
|
177 HbAutoTest::keyClicks(mMainWindow, string, 0, waitTime); |
|
178 |
|
179 HbAutoTest::mouseClick(mMainWindow, mTestView, connectionNameLabel); |
|
180 |
|
181 // Verify both commsdat and UI widget |
|
182 subVerifyString( |
|
183 CMManagerShim::CmName, |
|
184 mTestView->mConnectionNameItem, |
|
185 result); |
|
186 } |
|
187 |
|
188 /** |
|
189 * Test data for connection name change test case. |
|
190 */ |
|
191 void TestCpWlanApPlugin::tcChangeConnectionName_data() |
|
192 { |
|
193 QTest::addColumn<QString>("string"); |
|
194 QTest::addColumn<QString>("result"); |
|
195 |
|
196 QTest::newRow("maximum length") |
|
197 << "really long name 1234567890123" |
|
198 << "really long name 1234567890123"; |
|
199 QTest::newRow("too long") |
|
200 << "too long name 123456789012345678901234567890" |
|
201 << "too long name 1234567890123456"; |
|
202 QTest::newRow("basic") // last one must always fit on one line in UI |
|
203 << "test WLAN AP" |
|
204 << "test WLAN AP"; |
|
205 } |
|
206 |
|
207 /** |
|
208 * Tests that empty connection name is not accepted. |
|
209 */ |
|
210 void TestCpWlanApPlugin::tcConnectionNameEmpty() |
|
211 { |
|
212 QString previous = |
|
213 mTestView->mConnectionNameItem->contentWidgetData("text").toString(); |
|
214 |
|
215 HbAutoTest::mouseClick(mMainWindow, mTestView, connectionNameLineEdit); |
|
216 // Erase old string |
|
217 subClearLineEdit(CMManagerShim::CmNameLength); |
|
218 |
|
219 HbAutoTest::mouseClick(mMainWindow, mTestView, connectionNameLabel); |
|
220 |
|
221 QTest::qWait(100); |
|
222 // Dismiss messagebox |
|
223 HbAutoTest::mouseClick(mMainWindow, mTestView, messageBoxOkButton); |
|
224 |
|
225 // Verify both commsdat and UI widget |
|
226 subVerifyString( |
|
227 CMManagerShim::CmName, |
|
228 mTestView->mConnectionNameItem, |
|
229 previous); |
|
230 } |
|
231 |
|
232 /** |
|
233 * Tests changing of WLAN network name. |
|
234 */ |
|
235 void TestCpWlanApPlugin::tcChangeWlanNetworkName() |
|
236 { |
|
237 QFETCH(QString, string); |
|
238 QFETCH(QString, result); |
|
239 |
|
240 HbAutoTest::mouseClick(mMainWindow, mTestView, wlanNetworkNameLineEdit); |
|
241 |
|
242 // Erase old string |
|
243 subClearLineEdit(CMManagerShim::WlanSSIDLength); |
|
244 |
|
245 // Enter new string |
|
246 HbAutoTest::keyClicks(mMainWindow, string, 0, waitTime); |
|
247 |
|
248 HbAutoTest::mouseClick(mMainWindow, mTestView, connectionNameLabel); |
|
249 |
|
250 // Verify both commsdat and UI widget |
|
251 subVerifyString( |
|
252 CMManagerShim::WlanSSID, |
|
253 mTestView->mWlanNetworkNameItem, |
|
254 result); |
|
255 } |
|
256 |
|
257 /** |
|
258 * Test data for WLAN network name change test case. |
|
259 */ |
|
260 void TestCpWlanApPlugin::tcChangeWlanNetworkName_data() |
|
261 { |
|
262 QTest::addColumn<QString>("string"); |
|
263 QTest::addColumn<QString>("result"); |
|
264 |
|
265 QTest::newRow("maximum length") |
|
266 << "really long name 123456789012345" |
|
267 << "really long name 123456789012345"; |
|
268 QTest::newRow("too long") |
|
269 << "too long name 123456789012345678901234567890" |
|
270 << "too long name 123456789012345678"; |
|
271 QTest::newRow("basic") // last one must always fit on one line in UI |
|
272 << "test SSID" |
|
273 << "test SSID"; |
|
274 } |
|
275 |
|
276 /** |
|
277 * Tests that empty WLAN network name is not accepted. |
|
278 */ |
|
279 void TestCpWlanApPlugin::tcWlanNetworkNameEmpty() |
|
280 { |
|
281 QString previous = |
|
282 mTestView->mWlanNetworkNameItem->contentWidgetData("text").toString(); |
|
283 |
|
284 HbAutoTest::mouseClick(mMainWindow, mTestView, wlanNetworkNameLineEdit); |
|
285 |
|
286 // Erase old string |
|
287 subClearLineEdit(CMManagerShim::WlanSSIDLength); |
|
288 |
|
289 HbAutoTest::mouseClick(mMainWindow, mTestView, connectionNameLabel); |
|
290 |
|
291 QTest::qWait(100); |
|
292 // Dismiss messagebox |
|
293 HbAutoTest::mouseClick(mMainWindow, mTestView, messageBoxOkButton); |
|
294 |
|
295 // Verify both commsdat and UI widget |
|
296 subVerifyString( |
|
297 CMManagerShim::WlanSSID, |
|
298 mTestView->mWlanNetworkNameItem, |
|
299 previous); |
|
300 } |
|
301 |
|
302 /** |
|
303 * Tests changing of WLAN network status. |
|
304 */ |
|
305 void TestCpWlanApPlugin::tcChangeNetworkStatus() |
|
306 { |
|
307 // Set network status to hidden |
|
308 HbAutoTest::mouseClick(mMainWindow, mTestView, networkStatusComboBox, 100); |
|
309 HbAutoTest::mouseClick(mMainWindow, mTestView, networkStatusHidden, 100); |
|
310 subVerifyNetworkStatus(HiddenStatus); |
|
311 |
|
312 // Set network status to public |
|
313 HbAutoTest::mouseClick(mMainWindow, mTestView, networkStatusComboBox, 100); |
|
314 HbAutoTest::mouseClick(mMainWindow, mTestView, networkStatusPublic, 100); |
|
315 subVerifyNetworkStatus(PublicStatus); |
|
316 } |
|
317 |
|
318 /** |
|
319 * Tests changing of WLAN network mode. |
|
320 */ |
|
321 void TestCpWlanApPlugin::tcChangeNetworkMode() |
|
322 { |
|
323 // Set network mode to ad-hoc |
|
324 HbAutoTest::mouseClick(mMainWindow, mTestView, networkModeComboBox, 100); |
|
325 HbAutoTest::mouseClick(mMainWindow, mTestView, networkModeAdHoc, 100); |
|
326 subVerifyUint(CMManagerShim::WlanConnectionMode, CMManagerShim::Adhoc); |
|
327 |
|
328 // Set network mode to infrastructure |
|
329 HbAutoTest::mouseClick(mMainWindow, mTestView, networkModeComboBox, 100); |
|
330 HbAutoTest::mouseClick(mMainWindow, mTestView, networkModeIntrastructure, 100); |
|
331 subVerifyUint(CMManagerShim::WlanConnectionMode, CMManagerShim::Infra); |
|
332 } |
|
333 |
|
334 /** |
|
335 * Tests changing of WLAN security mode. |
|
336 */ |
|
337 void TestCpWlanApPlugin::tcChangeSecurityMode() |
|
338 { |
|
339 #ifdef WLAN_SECURITY_PLUGINS_AVAILABLE |
|
340 // Ensure security mode is open |
|
341 HbAutoTest::mouseClick(mMainWindow, mTestView, securityModeComboBox, 100); |
|
342 QTest::qWait(100); |
|
343 HbAutoTest::mouseClick(mMainWindow, mTestView, securityModeOpen, 100); |
|
344 subVerifyUint( |
|
345 CMManagerShim::WlanSecurityMode, |
|
346 CMManagerShim::WlanSecModeOpen); |
|
347 |
|
348 QTest::qWait(1000); |
|
349 |
|
350 // Set security mode to WEP |
|
351 HbAutoTest::mouseClick(mMainWindow, mTestView, securityModeComboBox, 100); |
|
352 QTest::qWait(100); |
|
353 HbAutoTest::mouseClick(mMainWindow, mTestView, securityModeWep, 100); |
|
354 subVerifyUint( |
|
355 CMManagerShim::WlanSecurityMode, |
|
356 CMManagerShim::WlanSecModeWep); |
|
357 |
|
358 QTest::qWait(1000); |
|
359 #endif |
|
360 |
|
361 // Set security mode to open |
|
362 HbAutoTest::mouseClick(mMainWindow, mTestView, securityModeComboBox, 100); |
|
363 QTest::qWait(100); |
|
364 HbAutoTest::mouseClick(mMainWindow, mTestView, securityModeOpen, 100); |
|
365 subVerifyUint( |
|
366 CMManagerShim::WlanSecurityMode, |
|
367 CMManagerShim::WlanSecModeOpen); |
|
368 } |
|
369 |
|
370 /** |
|
371 * Tests changing of homepage. |
|
372 */ |
|
373 void TestCpWlanApPlugin::tcChangeHomepage() |
|
374 { |
|
375 QFETCH(QString, string); |
|
376 QFETCH(QString, result); |
|
377 |
|
378 HbAutoTest::mouseClick(mMainWindow, mTestView, homepageLineEdit); |
|
379 |
|
380 // Erase old string |
|
381 QString text = mTestView->mHomepageItem->contentWidgetData("text").toString(); |
|
382 subClearLineEdit(text.size()); |
|
383 |
|
384 // Enter new string |
|
385 HbAutoTest::keyClicks(mMainWindow, string, 0, waitTime); |
|
386 |
|
387 HbAutoTest::mouseClick(mMainWindow, mTestView, connectionNameLabel); |
|
388 |
|
389 // Verify both commsdat and UI widget |
|
390 subVerifyString( |
|
391 CMManagerShim::CmStartPage, |
|
392 mTestView->mHomepageItem, |
|
393 result); |
|
394 } |
|
395 |
|
396 /** |
|
397 * Test data for homepage change test case. |
|
398 */ |
|
399 void TestCpWlanApPlugin::tcChangeHomepage_data() |
|
400 { |
|
401 QTest::addColumn<QString>("string"); |
|
402 QTest::addColumn<QString>("result"); |
|
403 |
|
404 // Doesn't work always, view goes blank sometimes, Orbit bug? |
|
405 // QTest::newRow("long") |
|
406 // << "http://developer.symbian.org/main/documentation/reference/s^3/doc_source/AboutSymbianOSLibrary9.6/index.html" |
|
407 // << "http://developer.symbian.org/main/documentation/reference/s^3/doc_source/AboutSymbianOSLibrary9.6/index.html"; |
|
408 QTest::newRow("basic") // last one should always fit on one line in UI |
|
409 << "http://www.symbian.org/" |
|
410 << "http://www.symbian.org/"; |
|
411 QTest::newRow("empty") |
|
412 << "" |
|
413 << ""; |
|
414 } |
|
415 |
|
416 /** |
|
417 * Tests advanced settings view (which is currently empty). |
|
418 */ |
|
419 void TestCpWlanApPlugin::tcAdvancedSettings() |
|
420 { |
|
421 // Launch advanced settings view |
|
422 bool status = connect( |
|
423 this, |
|
424 SIGNAL(menuActionTriggered(HbAction *)), |
|
425 mTestView, |
|
426 SLOT(menuActionTriggered(HbAction *))); |
|
427 Q_ASSERT(status); |
|
428 emit menuActionTriggered(mTestView->mAdvancedSettingsAction); |
|
429 |
|
430 QTest::qWait(2000); |
|
431 |
|
432 // Return from advanced settings view |
|
433 subClickWidget("HbNavigationButton"); |
|
434 } |
|
435 |
|
436 // ----------------------------------------------------------------------------- |
|
437 // SUB TEST CASES |
|
438 // ----------------------------------------------------------------------------- |
|
439 |
|
440 /** |
|
441 * Verifies that given string is correctly stored in CommsDat and shown on UI. |
|
442 */ |
|
443 void TestCpWlanApPlugin::subVerifyString( |
|
444 CMManagerShim::ConnectionMethodAttribute attribute, |
|
445 HbDataFormModelItem *item, |
|
446 QString expected) |
|
447 { |
|
448 // Read attribute value from CommsDat |
|
449 QScopedPointer<CmManagerShim> cmManager(new CmManagerShim); |
|
450 QScopedPointer<CmConnectionMethodShim> connectionMethod( |
|
451 cmManager->connectionMethod(testApId)); |
|
452 QString commsdat = connectionMethod->getStringAttribute(attribute); |
|
453 |
|
454 QCOMPARE(commsdat, expected); |
|
455 |
|
456 // Get value from UI widget |
|
457 QString widget = item->contentWidgetData("text").toString(); |
|
458 |
|
459 QCOMPARE(widget, expected); |
|
460 } |
|
461 |
|
462 /** |
|
463 * Verifies that given attribute contains expected integer value in CommsDat. |
|
464 */ |
|
465 void TestCpWlanApPlugin::subVerifyUint( |
|
466 CMManagerShim::ConnectionMethodAttribute attribute, |
|
467 uint expected) |
|
468 { |
|
469 // Read attribute value from CommsDat |
|
470 QScopedPointer<CmManagerShim> cmManager(new CmManagerShim); |
|
471 QScopedPointer<CmConnectionMethodShim> connectionMethod( |
|
472 cmManager->connectionMethod(testApId)); |
|
473 uint commsdat = connectionMethod->getIntAttribute(attribute); |
|
474 |
|
475 QCOMPARE(commsdat, expected); |
|
476 } |
|
477 |
|
478 /** |
|
479 * Verifies that WLAN network status in CommsDat is correct. |
|
480 */ |
|
481 void TestCpWlanApPlugin::subVerifyNetworkStatus( |
|
482 NetworkStatus expected) |
|
483 { |
|
484 // Read attribute value from CommsDat |
|
485 QScopedPointer<CmManagerShim> cmManager(new CmManagerShim); |
|
486 QScopedPointer<CmConnectionMethodShim> connectionMethod( |
|
487 cmManager->connectionMethod(testApId)); |
|
488 bool commsdatScanSsid = connectionMethod->getBoolAttribute( |
|
489 CMManagerShim::WlanScanSSID); |
|
490 |
|
491 if (expected == HiddenStatus) { |
|
492 QVERIFY(commsdatScanSsid == true); |
|
493 } else if (expected == PublicStatus) { |
|
494 QVERIFY(commsdatScanSsid == false); |
|
495 } else { |
|
496 Q_ASSERT(false); |
|
497 } |
|
498 } |
|
499 |
|
500 /** |
|
501 * Clears a HbLineEdit. |
|
502 */ |
|
503 void TestCpWlanApPlugin::subClearLineEdit( |
|
504 uint length) |
|
505 { |
|
506 // Erase old string |
|
507 QTest::qWait(5000); // TODO: Remove this when item specific menu doesn't pop up anymore |
|
508 |
|
509 // Move cursor to end of string |
|
510 //HbAutoTest::keyClick(mMainWindow, Qt::Key_End, 0, waitTime); // doesn't seem to do anything? |
|
511 HbAutoTest::keyClick(mMainWindow, Qt::Key_Down, 0, waitTime); |
|
512 HbAutoTest::keyClick(mMainWindow, Qt::Key_Down, 0, waitTime); |
|
513 HbAutoTest::keyClick(mMainWindow, Qt::Key_Down, 0, waitTime); |
|
514 for (int i=0; i<25; i++) { |
|
515 HbAutoTest::keyClick(mMainWindow, Qt::Key_Right, 0, waitTime); |
|
516 } |
|
517 for (int i=0; i<length; i++) { |
|
518 HbAutoTest::keyClick(mMainWindow, Qt::Key_Backspace, 0, waitTime); |
|
519 } |
|
520 } |
|
521 |
|
522 /** |
|
523 * Creates the settings view and shows it. |
|
524 */ |
|
525 void TestCpWlanApPlugin::subCreateSettingsView(uint connectionMethodId) |
|
526 { |
|
527 // Create settings view |
|
528 HbView *view = mPlugin->createSettingView(connectionMethodId); |
|
529 QVERIFY(view != NULL); |
|
530 |
|
531 // Display the view |
|
532 mMainWindow->addView(view); |
|
533 mMainWindow->setCurrentView(view); |
|
534 // Store pointer to settings view class |
|
535 mTestView = static_cast<CpWlanApView *>(view); |
|
536 } |
|
537 |
|
538 /** |
|
539 * Clicks a widget currently on UI by class name. |
|
540 */ |
|
541 void TestCpWlanApPlugin::subClickWidget(const QString &name) |
|
542 { |
|
543 QList<QGraphicsItem *> itemList = mMainWindow->scene()->items(); |
|
544 |
|
545 QGraphicsItem *target = 0; |
|
546 foreach (QGraphicsItem* item, itemList) { |
|
547 if (item->isWidget()) { |
|
548 QString widgetClassName(static_cast<QGraphicsWidget*>(item)->metaObject()->className()); |
|
549 //qDebug() << widgetClassName; |
|
550 |
|
551 if (widgetClassName == name) { |
|
552 target = item; |
|
553 break; |
|
554 } |
|
555 } |
|
556 } |
|
557 |
|
558 Q_ASSERT(target); |
|
559 HbAutoTest::mouseClick(mMainWindow, static_cast<HbWidget *>(target)); |
|
560 } |