|
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 * CM Application Settings UI unit testing. |
|
16 */ |
|
17 |
|
18 #include <QList> |
|
19 #include <QString> |
|
20 |
|
21 #include <HbApplication> |
|
22 #include <HbMainWindow> |
|
23 #include <HbView> |
|
24 #include <HbLabel> |
|
25 |
|
26 #include <QtTest/QtTest> |
|
27 |
|
28 #include "cmdestination_shim.h" |
|
29 #include "cmconnectionmethod_shim.h" |
|
30 |
|
31 #include "testcmmgrshim.h" |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // STATIC TEST DATA |
|
35 // ----------------------------------------------------------------------------- |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // TEST MACROES |
|
39 // ----------------------------------------------------------------------------- |
|
40 |
|
41 // Test macro for verifying an exception throwing code block |
|
42 #define TEST_CATCH_AND_VERIFY(code, error) \ |
|
43 { \ |
|
44 int error_code; \ |
|
45 QT_TRYCATCH_ERROR(error_code, code); \ |
|
46 QCOMPARE(error_code, error); \ |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // FRAMEWORK FUNCTIONS |
|
51 // ----------------------------------------------------------------------------- |
|
52 |
|
53 /** |
|
54 * Test main function. Runs all test cases. |
|
55 */ |
|
56 int main(int argc, char *argv[]) |
|
57 { |
|
58 Q_UNUSED(argc); |
|
59 |
|
60 char *pass[3]; |
|
61 pass[0] = argv[0]; |
|
62 pass[1] = "-o"; |
|
63 pass[2] = "c:\\data\\TestCmMgrShim.txt"; |
|
64 |
|
65 TestCmMgrShim tc; |
|
66 int res = QTest::qExec(&tc, 3, pass); |
|
67 |
|
68 return res; |
|
69 } |
|
70 |
|
71 /** |
|
72 * This function is be called before the first test case is executed. |
|
73 */ |
|
74 void TestCmMgrShim::initTestCase() |
|
75 { |
|
76 } |
|
77 |
|
78 /** |
|
79 * This function is be called after the last test case was executed. |
|
80 */ |
|
81 void TestCmMgrShim::cleanupTestCase() |
|
82 { |
|
83 } |
|
84 |
|
85 /** |
|
86 * This function is be called before each test case is executed. |
|
87 */ |
|
88 void TestCmMgrShim::init() |
|
89 { |
|
90 // Initialize the CmManagerShim object |
|
91 mCmManagerShim = new CmManagerShim; |
|
92 } |
|
93 |
|
94 /** |
|
95 * This function is be called after each test case is executed. |
|
96 */ |
|
97 void TestCmMgrShim::cleanup() |
|
98 { |
|
99 // There should be no destinations |
|
100 QList<uint> destinations; |
|
101 mCmManagerShim->allDestinations(destinations); |
|
102 int destinationCount = destinations.count(); |
|
103 |
|
104 // Delete the destinations if there were any |
|
105 deleteDestinations(); |
|
106 |
|
107 // There should be no connection methods |
|
108 QList<uint> connMethods; |
|
109 mCmManagerShim->connectionMethod(connMethods, false); |
|
110 int connMethodCount = connMethods.count(); |
|
111 |
|
112 // Delete the connection methods if there were any |
|
113 deleteConnectionMethods(); |
|
114 |
|
115 // Validate after the deletions are done |
|
116 QCOMPARE(destinationCount, 0); |
|
117 QCOMPARE(connMethodCount, 0); |
|
118 |
|
119 delete mCmManagerShim; |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // TEST CASES |
|
124 // ----------------------------------------------------------------------------- |
|
125 |
|
126 /** |
|
127 * Test case for testing initial state. |
|
128 * -Reads AND DELETES all destinations and connection methods. |
|
129 * -Verifies that there are no destinations and connection methods. |
|
130 */ |
|
131 void TestCmMgrShim::tcResetSettings() |
|
132 { |
|
133 // Read all destinations |
|
134 QList<uint> destinations; |
|
135 mCmManagerShim->allDestinations(destinations); |
|
136 |
|
137 // Delete the destinations |
|
138 for (int i=0; i < destinations.count(); i++) { |
|
139 CmDestinationShim *dest = mCmManagerShim->destination(destinations[i]); |
|
140 dest->deleteDestination(); |
|
141 |
|
142 // Update should leave |
|
143 TEST_CATCH_AND_VERIFY( |
|
144 dest->update(), |
|
145 KErrBadHandle); |
|
146 |
|
147 delete dest; |
|
148 } |
|
149 |
|
150 // Check that there no longer are any destinations |
|
151 mCmManagerShim->allDestinations(destinations); |
|
152 QCOMPARE(destinations.count(), 0); |
|
153 |
|
154 // Read all connection methods |
|
155 QList<uint> connMethods; |
|
156 mCmManagerShim->connectionMethod(connMethods, false); |
|
157 |
|
158 // Remove possible uncategorized connection methods |
|
159 for (int i=0; i < connMethods.count(); i++){ |
|
160 CmConnectionMethodShim *cm = |
|
161 mCmManagerShim->connectionMethod(connMethods[i]); |
|
162 QVERIFY(cm != NULL); |
|
163 bool ok = cm->deleteConnectionMethod(); |
|
164 QVERIFY(ok == true); |
|
165 delete cm; |
|
166 } |
|
167 |
|
168 // Check that tere is no longer any connection methods |
|
169 mCmManagerShim->connectionMethod(connMethods, false); |
|
170 QCOMPARE(connMethods.count(), 0); |
|
171 |
|
172 // Try reading a Connection Method with an erroneous ID |
|
173 TEST_CATCH_AND_VERIFY( |
|
174 mCmManagerShim->connectionMethod(0), |
|
175 KErrArgument); |
|
176 |
|
177 // Try reading a non-existent Connection Method |
|
178 TEST_CATCH_AND_VERIFY( |
|
179 mCmManagerShim->connectionMethod(1), |
|
180 KErrNotFound); |
|
181 } |
|
182 |
|
183 /** |
|
184 * Test case for testing basic legacy WLAN connection method handling. |
|
185 * -Creates a legacy WLAN connection method (i.e. does not belong to |
|
186 * any destination). |
|
187 * -Deletes the connection method. |
|
188 */ |
|
189 void TestCmMgrShim::tcLegacyConnMethodWlan() |
|
190 { |
|
191 // Create the connection method |
|
192 CmConnectionMethodShim *cm = mCmManagerShim->createConnectionMethod( |
|
193 CMManagerShim::BearerTypeWlan); |
|
194 QVERIFY(cm != NULL); |
|
195 |
|
196 // Update to CommsDat |
|
197 cm->update(); |
|
198 |
|
199 // Check bearer type |
|
200 int bearer = cm->getIntAttribute(CMManagerShim::CmBearerType); |
|
201 QCOMPARE(bearer, (int)CMManagerShim::BearerTypeWlan); |
|
202 |
|
203 // Check ID |
|
204 int id = cm->getIntAttribute(CMManagerShim::CmId); |
|
205 QCOMPARE(id, 1); |
|
206 |
|
207 // Delete the connection method reference |
|
208 delete cm; |
|
209 |
|
210 // Refetch the connection method |
|
211 cm = mCmManagerShim->connectionMethod(id); |
|
212 QVERIFY(cm != NULL); |
|
213 |
|
214 // Delete the connection method |
|
215 cm->deleteConnectionMethod(); |
|
216 |
|
217 // Check that double deletion throws an exception |
|
218 TEST_CATCH_AND_VERIFY( |
|
219 cm->deleteConnectionMethod(), |
|
220 KErrBadHandle); |
|
221 |
|
222 delete cm; |
|
223 } |
|
224 |
|
225 /** |
|
226 * Test case for testing basic legacy GPRS connection method handling. |
|
227 * -Creates a legacy GPRS connection method (i.e. does not belong to |
|
228 * any destination). |
|
229 * -Deletes the connection method. |
|
230 */ |
|
231 void TestCmMgrShim::tcLegacyConnMethodGprs() |
|
232 { |
|
233 // Create the connection method |
|
234 CmConnectionMethodShim *cm = mCmManagerShim->createConnectionMethod( |
|
235 CMManagerShim::BearerTypePacketData); |
|
236 QVERIFY(cm != NULL); |
|
237 |
|
238 // Update to CommsDat |
|
239 cm->update(); |
|
240 |
|
241 // Check ID |
|
242 int id = cm->getIntAttribute(CMManagerShim::CmId); |
|
243 QCOMPARE(id, 1); |
|
244 |
|
245 // Check bearer type |
|
246 int bearer = cm->getIntAttribute(CMManagerShim::CmBearerType); |
|
247 QCOMPARE(bearer, (int)CMManagerShim::BearerTypePacketData); |
|
248 |
|
249 // Delete the connection method reference |
|
250 delete cm; |
|
251 |
|
252 // Refetch the connection method |
|
253 cm = mCmManagerShim->connectionMethod(id); |
|
254 QVERIFY(cm != NULL); |
|
255 |
|
256 // Delete the connection method |
|
257 cm->deleteConnectionMethod(); |
|
258 delete cm; |
|
259 } |
|
260 |
|
261 /** |
|
262 * Basic error case testing for CmManagerShim. |
|
263 * All test call should throw an exception since they are invalid. |
|
264 */ |
|
265 void TestCmMgrShim::tcCmManagerBasicFails() |
|
266 { |
|
267 // Try creating a destination with an invalid name |
|
268 CmDestinationShim *dest = 0; |
|
269 TEST_CATCH_AND_VERIFY( |
|
270 dest = mCmManagerShim->createDestination(QString("")), |
|
271 KErrArgument); |
|
272 QVERIFY(dest == NULL); |
|
273 |
|
274 // Try creating a connection method with an invalid bearer type |
|
275 CmConnectionMethodShim *cm = 0; |
|
276 TEST_CATCH_AND_VERIFY( |
|
277 cm = mCmManagerShim->createConnectionMethod(0), |
|
278 KErrArgument); |
|
279 QVERIFY(cm == NULL); |
|
280 |
|
281 // Try fetching a connection method with an invalid ID |
|
282 cm = 0; |
|
283 TEST_CATCH_AND_VERIFY( |
|
284 cm = mCmManagerShim->connectionMethod(42), |
|
285 KErrNotFound); |
|
286 QVERIFY(cm == NULL); |
|
287 |
|
288 // Try fetching a destination with an invalid ID |
|
289 dest = 0; |
|
290 TEST_CATCH_AND_VERIFY( |
|
291 dest = mCmManagerShim->destination(42), |
|
292 KErrArgument); |
|
293 QVERIFY(dest == NULL); |
|
294 } |
|
295 |
|
296 /** |
|
297 * Test case for testing basic destination handling |
|
298 * -Create a destination |
|
299 * -Validate the default destination content |
|
300 * -Delete the destination |
|
301 */ |
|
302 void TestCmMgrShim::tcBasicDestination() |
|
303 { |
|
304 // Create a new destination |
|
305 CmDestinationShim *dest; |
|
306 dest = mCmManagerShim->createDestination("TestDestination"); |
|
307 QVERIFY(dest != NULL); |
|
308 |
|
309 // Update to CommsDat |
|
310 dest->update(); |
|
311 |
|
312 // Check the name |
|
313 QString name(dest->name()); |
|
314 QCOMPARE(name, QString("TestDestination")); |
|
315 |
|
316 // Check ID |
|
317 uint destinationId = dest->id(); |
|
318 QVERIFY(destinationId >= 4000); |
|
319 |
|
320 // Check protection level default value |
|
321 CMManagerShim::CmmProtectionLevel prot = dest->protectionLevel(); |
|
322 QCOMPARE(prot, CMManagerShim::ProtLevel0); |
|
323 |
|
324 // Check hidden flag default value |
|
325 bool isHidden = dest->isHidden(); |
|
326 QCOMPARE(isHidden, false); |
|
327 |
|
328 // Check destination content |
|
329 int connMethodCount = dest->connectionMethodCount(); |
|
330 QCOMPARE(connMethodCount, 0); |
|
331 |
|
332 // Delete the destination |
|
333 dest->deleteDestination(); |
|
334 |
|
335 // Check that double deletion throws an exception |
|
336 TEST_CATCH_AND_VERIFY( |
|
337 dest->deleteDestination(), |
|
338 KErrBadHandle); |
|
339 |
|
340 delete dest; |
|
341 } |
|
342 |
|
343 /** |
|
344 * Test case for testing basic modifications for a destination. |
|
345 * -Create a destination |
|
346 * -Add a GPRS connection method to it. |
|
347 * -Add a WLAN connection method to it. |
|
348 * -Delete the GPRS connection method. |
|
349 * -Delete the Destination (and thus also the WLAN connection method). |
|
350 */ |
|
351 void TestCmMgrShim::tcDestinationModify() |
|
352 { |
|
353 // Create a new destination |
|
354 CmDestinationShim *dest; |
|
355 dest = mCmManagerShim->createDestination("TestDestination"); |
|
356 QVERIFY(dest != NULL); |
|
357 uint destId = dest->id(); |
|
358 QVERIFY(destId >= 4000); |
|
359 |
|
360 // Check destination initial content |
|
361 int connMethodCount = dest->connectionMethodCount(); |
|
362 QCOMPARE(connMethodCount, 0); |
|
363 |
|
364 // Create a GPRS connection method |
|
365 CmConnectionMethodShim *cm = mCmManagerShim->createConnectionMethod( |
|
366 CMManagerShim::BearerTypePacketData); |
|
367 QVERIFY(cm != NULL); |
|
368 |
|
369 // Update to CommsDat |
|
370 cm->update(); |
|
371 |
|
372 // Add the connection method to the destination |
|
373 int index = dest->addConnectionMethod(cm); |
|
374 QCOMPARE(index, 0); |
|
375 |
|
376 // Update to CommsDat |
|
377 dest->update(); |
|
378 |
|
379 // Create a WLAN connection method |
|
380 CmConnectionMethodShim *cmWlan = mCmManagerShim->createConnectionMethod( |
|
381 CMManagerShim::BearerTypeWlan); |
|
382 QVERIFY(cmWlan != NULL); |
|
383 |
|
384 // Update to CommsDat |
|
385 cmWlan->update(); |
|
386 |
|
387 // Add the connection method to the destination |
|
388 index = dest->addConnectionMethod(cmWlan); |
|
389 QCOMPARE(index, 0); |
|
390 |
|
391 // Update to CommsDat |
|
392 dest->update(); |
|
393 |
|
394 // Delete the WLAN connection method reference |
|
395 delete cmWlan; |
|
396 cmWlan = 0; |
|
397 |
|
398 // Delete the GPRS connection method |
|
399 dest->deleteConnectionMethod(cm); |
|
400 delete cm; |
|
401 cm = 0; |
|
402 |
|
403 // Update to CommsDat |
|
404 dest->update(); |
|
405 |
|
406 // Verify the delete |
|
407 connMethodCount = dest->connectionMethodCount(); |
|
408 QCOMPARE(connMethodCount, 1); |
|
409 |
|
410 // Delete the whole destination including the remaining WLAN conn method. |
|
411 dest->deleteDestination(); |
|
412 delete dest; |
|
413 |
|
414 // Check that the destination is gone |
|
415 dest = NULL; |
|
416 TEST_CATCH_AND_VERIFY( |
|
417 dest = mCmManagerShim->destination(destId), |
|
418 KErrNotFound); |
|
419 QCOMPARE(dest, (CmDestinationShim *)0); |
|
420 } |
|
421 |
|
422 /** |
|
423 * Test case for adding and reading boolean attribute for a connection method. |
|
424 * -Creates a legacy WLAN connection method (i.e. does not belong to |
|
425 * any destination). |
|
426 * -Sets a boolean attribute. |
|
427 * -Gets the boolean attribute. |
|
428 * -Deletes the connection method. |
|
429 */ |
|
430 void TestCmMgrShim::tcConnMethodSetBoolAttribute() |
|
431 { |
|
432 // Create the connection method |
|
433 CmConnectionMethodShim *cm = mCmManagerShim->createConnectionMethod( |
|
434 CMManagerShim::BearerTypeWlan); |
|
435 QVERIFY(cm != NULL); |
|
436 |
|
437 // Update to CommsDat |
|
438 cm->update(); |
|
439 |
|
440 // Set bool attribute value |
|
441 cm->setBoolAttribute(CMManagerShim::CmProxyUsageEnabled, true); |
|
442 |
|
443 // Update to CommsDat |
|
444 cm->update(); |
|
445 |
|
446 // Get bool attribute value |
|
447 bool testBool = false; |
|
448 testBool = cm->getBoolAttribute(CMManagerShim::CmProxyUsageEnabled); |
|
449 QCOMPARE(testBool, true); |
|
450 |
|
451 // Delete the connection method |
|
452 cm->deleteConnectionMethod(); |
|
453 delete cm; |
|
454 } |
|
455 |
|
456 /** |
|
457 * Test case for adding and reading integer attribute for a connection method. |
|
458 * -Creates a legacy WLAN connection method (i.e. does not belong to |
|
459 * any destination). |
|
460 * -Sets an int attribute. |
|
461 * -Gets the int attribute. |
|
462 * -Deletes the connection method. |
|
463 */ |
|
464 void TestCmMgrShim::tcConnMethodSetIntAttribute() |
|
465 { |
|
466 // Create the connection method |
|
467 CmConnectionMethodShim *cm = mCmManagerShim->createConnectionMethod( |
|
468 CMManagerShim::BearerTypeWlan); |
|
469 QVERIFY(cm != NULL); |
|
470 |
|
471 // Update to CommsDat |
|
472 cm->update(); |
|
473 |
|
474 // Set int attribute value |
|
475 uint testInt = 99; |
|
476 cm->setIntAttribute(CMManagerShim::CmProxyPortNumber, testInt); |
|
477 |
|
478 // Update to CommsDat |
|
479 cm->update(); |
|
480 |
|
481 // Get int attribute value |
|
482 uint resultInt = cm->getIntAttribute(CMManagerShim::CmProxyPortNumber); |
|
483 QCOMPARE(resultInt, testInt); |
|
484 |
|
485 // Delete the connection method |
|
486 cm->deleteConnectionMethod(); |
|
487 delete cm; |
|
488 } |
|
489 |
|
490 /** |
|
491 * Test case for adding and reading string attributes for a connection method. |
|
492 * -Creates a legacy WLAN connection method (i.e. does not belong to |
|
493 * any destination). |
|
494 * -Sets a string attribute. |
|
495 * -Gets the string attribute. |
|
496 * -Deletes the connection method. |
|
497 */ |
|
498 void TestCmMgrShim::tcConnMethodSetStringAttribute() |
|
499 { |
|
500 // Create the connection method |
|
501 CmConnectionMethodShim *cm = mCmManagerShim->createConnectionMethod( |
|
502 CMManagerShim::BearerTypeWlan); |
|
503 QVERIFY(cm != NULL); |
|
504 |
|
505 // Update to CommsDat |
|
506 cm->update(); |
|
507 |
|
508 // Set string attribute value |
|
509 QString testString("TestProxyServerName"); |
|
510 cm->setStringAttribute(CMManagerShim::CmProxyServerName, testString); |
|
511 |
|
512 // Set string8 attribute value |
|
513 QString testString2("key12"); |
|
514 cm->setString8Attribute(CMManagerShim::WlanWepKey1InAscii, testString2); |
|
515 |
|
516 // Update to CommsDat |
|
517 cm->update(); |
|
518 |
|
519 // Check string attribute value |
|
520 QString resultString = cm->getStringAttribute(CMManagerShim::CmProxyServerName); |
|
521 QCOMPARE(resultString, testString); |
|
522 |
|
523 // Check string8 attribute value |
|
524 resultString = cm->getString8Attribute(CMManagerShim::WlanWepKey1InAscii); |
|
525 QCOMPARE(resultString, testString2); |
|
526 |
|
527 // Delete the connection method |
|
528 cm->deleteConnectionMethod(); |
|
529 delete cm; |
|
530 } |
|
531 |
|
532 /** |
|
533 * Test case for testing attribute reads using a wrong attribute type. |
|
534 * All test reads in this case should fail to an exception. |
|
535 */ |
|
536 void TestCmMgrShim::tcConnMethodWrongTypeAttributeRead() |
|
537 { |
|
538 // Create the connection method |
|
539 CmConnectionMethodShim *cm = mCmManagerShim->createConnectionMethod( |
|
540 CMManagerShim::BearerTypeWlan); |
|
541 QVERIFY(cm != NULL); |
|
542 |
|
543 // Update to CommsDat |
|
544 cm->update(); |
|
545 |
|
546 // Try reading name erroneously as an int attribute |
|
547 uint intResult = 0; |
|
548 TEST_CATCH_AND_VERIFY( |
|
549 intResult = cm->getIntAttribute(CMManagerShim::CmName), |
|
550 KErrNotSupported); |
|
551 QCOMPARE(intResult, (uint)0); |
|
552 |
|
553 // Try reading name erroneously as a bool attribute |
|
554 bool boolResult = false; |
|
555 TEST_CATCH_AND_VERIFY( |
|
556 boolResult = cm->getBoolAttribute(CMManagerShim::CmName), |
|
557 KErrNotSupported); |
|
558 QCOMPARE(boolResult, false); |
|
559 |
|
560 // Try reading ID erroneously as a string attribute |
|
561 QString stringResult; |
|
562 TEST_CATCH_AND_VERIFY( |
|
563 stringResult = cm->getStringAttribute(CMManagerShim::CmId), |
|
564 KErrNotSupported); |
|
565 QCOMPARE(stringResult, QString("")); |
|
566 |
|
567 // Try reading ID erroneously as a string 8 attribute |
|
568 stringResult = ""; |
|
569 TEST_CATCH_AND_VERIFY( |
|
570 stringResult = cm->getString8Attribute(CMManagerShim::CmId), |
|
571 KErrNotSupported); |
|
572 QCOMPARE(stringResult, QString("")); |
|
573 |
|
574 // Delete the connection method |
|
575 cm->deleteConnectionMethod(); |
|
576 delete cm; |
|
577 } |
|
578 |
|
579 /** |
|
580 * Test case for testing attribute reads using a wrong attribute type. |
|
581 * All test reads in this case should fail to an exception. |
|
582 */ |
|
583 void TestCmMgrShim::tcConnMethodWrongTypeAttributeWrite() |
|
584 { |
|
585 // Create the connection method |
|
586 CmConnectionMethodShim *cm = mCmManagerShim->createConnectionMethod( |
|
587 CMManagerShim::BearerTypeWlan); |
|
588 QVERIFY(cm != NULL); |
|
589 |
|
590 // Update to CommsDat |
|
591 cm->update(); |
|
592 |
|
593 // Try writing name erroneously as an int attribute |
|
594 TEST_CATCH_AND_VERIFY( |
|
595 cm->setIntAttribute(CMManagerShim::CmName, 0), |
|
596 KErrNotSupported); |
|
597 |
|
598 // Try writing name erroneously as a bool attribute |
|
599 TEST_CATCH_AND_VERIFY( |
|
600 cm->setBoolAttribute(CMManagerShim::CmName, false), |
|
601 KErrNotSupported); |
|
602 |
|
603 // Try writing ID erroneously as a string attribute |
|
604 TEST_CATCH_AND_VERIFY( |
|
605 cm->setStringAttribute(CMManagerShim::CmId, QString("dada")), |
|
606 KErrNotSupported); |
|
607 |
|
608 // Try reading ID erroneously as a string 8 attribute |
|
609 TEST_CATCH_AND_VERIFY( |
|
610 cm->setString8Attribute(CMManagerShim::CmId, QString("dada")), |
|
611 KErrNotSupported); |
|
612 |
|
613 // Delete the connection method |
|
614 cm->deleteConnectionMethod(); |
|
615 delete cm; |
|
616 } |
|
617 |
|
618 /** |
|
619 * Test case for testing connection method refreshing. |
|
620 * -Create a connection method |
|
621 * -Read the name of the connection method |
|
622 * -Change the name, but don't update CommsDat |
|
623 * -Refsesh connection method |
|
624 * -Check that the name is the original one |
|
625 * -Delete the connection method |
|
626 */ |
|
627 void TestCmMgrShim::tcConnectionMethodRefresh() |
|
628 { |
|
629 // Create the connection method |
|
630 CmConnectionMethodShim *cm = mCmManagerShim->createConnectionMethod( |
|
631 CMManagerShim::BearerTypeWlan); |
|
632 QVERIFY(cm != NULL); |
|
633 |
|
634 // Update to CommsDat |
|
635 cm->update(); |
|
636 |
|
637 // Check ID |
|
638 int id = cm->getIntAttribute(CMManagerShim::CmId); |
|
639 QCOMPARE(id, 1); |
|
640 |
|
641 // Check the default name |
|
642 QString name = cm->getStringAttribute(CMManagerShim::CmName); |
|
643 QCOMPARE(name, QString("Connection Method")); |
|
644 |
|
645 // Change name |
|
646 cm->setStringAttribute(CMManagerShim::CmName, "WlanBlaaBlaa"); |
|
647 // Do not update CommsDat |
|
648 |
|
649 // Check the changed name |
|
650 QString newName = cm->getStringAttribute(CMManagerShim::CmName); |
|
651 QCOMPARE(newName, QString("WlanBlaaBlaa")); |
|
652 |
|
653 // Refresh connection method |
|
654 cm->refresh(); |
|
655 |
|
656 // Delete the connection method reference |
|
657 delete cm; |
|
658 |
|
659 // Refetch the connection method |
|
660 cm = mCmManagerShim->connectionMethod(id); |
|
661 QVERIFY(cm != NULL); |
|
662 |
|
663 // Check that the bearer name in database is the original one |
|
664 newName = cm->getStringAttribute(CMManagerShim::CmName); |
|
665 QCOMPARE(newName, name); |
|
666 |
|
667 // Delete the connection method |
|
668 cm->deleteConnectionMethod(); |
|
669 delete cm; |
|
670 } |
|
671 |
|
672 /** |
|
673 * Test case for testing reading destination's connection methods. |
|
674 * -Create a destination |
|
675 * -Add a GPRS connection method to it. |
|
676 * -Add a WLAN connection method to it. |
|
677 * -Read number of connection methods. |
|
678 * -Read connection method by index. |
|
679 * -Read connection method by unknown index. |
|
680 * -Read connection method by id. |
|
681 * -Read connection method by unknown id. |
|
682 * -Delete the Destination (and connection methods). |
|
683 */ |
|
684 void TestCmMgrShim::tcDestinationReadConnectionMethods() |
|
685 { |
|
686 // Create a new destination |
|
687 CmDestinationShim *dest; |
|
688 dest = mCmManagerShim->createDestination("TestDestination"); |
|
689 QVERIFY(dest != NULL); |
|
690 uint destId = dest->id(); |
|
691 QVERIFY(destId >= 4000); |
|
692 |
|
693 // Check destination initial content |
|
694 int connMethodCount = dest->connectionMethodCount(); |
|
695 QCOMPARE(connMethodCount, 0); |
|
696 |
|
697 // Create a GPRS connection method |
|
698 CmConnectionMethodShim *cmGprs = mCmManagerShim->createConnectionMethod( |
|
699 CMManagerShim::BearerTypePacketData); |
|
700 QVERIFY(cmGprs != NULL); |
|
701 // Update to CommsDat |
|
702 cmGprs->update(); |
|
703 |
|
704 // Add the connection method to the destination |
|
705 int index = dest->addConnectionMethod(cmGprs); |
|
706 QCOMPARE(index, 0); |
|
707 // Update to CommsDat |
|
708 dest->update(); |
|
709 |
|
710 delete cmGprs; |
|
711 cmGprs = 0; |
|
712 |
|
713 // Create a WLAN connection method |
|
714 CmConnectionMethodShim *cmWlan = mCmManagerShim->createConnectionMethod( |
|
715 CMManagerShim::BearerTypeWlan); |
|
716 QVERIFY(cmWlan != NULL); |
|
717 // Update to CommsDat |
|
718 cmWlan->update(); |
|
719 |
|
720 // Add the connection method to the destination |
|
721 index = dest->addConnectionMethod(cmWlan); |
|
722 QCOMPARE(index, 0); |
|
723 // Update to CommsDat |
|
724 dest->update(); |
|
725 |
|
726 |
|
727 // Check number of destination's connection methods |
|
728 connMethodCount = dest->connectionMethodCount(); |
|
729 QCOMPARE(connMethodCount, 2); |
|
730 |
|
731 // Read connection method by index. |
|
732 CmConnectionMethodShim *cm = dest->connectionMethod(1); |
|
733 QVERIFY(cm != NULL); |
|
734 |
|
735 // Try to read connection method by unknown index. |
|
736 TEST_CATCH_AND_VERIFY( |
|
737 dest->connectionMethod(2), |
|
738 KErrArgument); |
|
739 |
|
740 // Read connection method by id. |
|
741 uint id = cmWlan->getIntAttribute(CMManagerShim::CmId); |
|
742 cm = dest->connectionMethodByID(id); |
|
743 QVERIFY(cm != NULL); |
|
744 |
|
745 delete cmWlan; |
|
746 cmWlan = 0; |
|
747 |
|
748 delete cm; |
|
749 cm = 0; |
|
750 |
|
751 // Try to read connection method by unknown id. |
|
752 TEST_CATCH_AND_VERIFY( |
|
753 dest->connectionMethodByID(100), |
|
754 KErrNotFound); |
|
755 |
|
756 // Delete the destination (and connection methods). |
|
757 dest->deleteDestination(); |
|
758 delete dest; |
|
759 } |
|
760 |
|
761 /** |
|
762 * Test case for testing removing connection method from single destination. |
|
763 * -Create 2 destinations |
|
764 * -Add a WLAN connection method to both. |
|
765 * -Remove the WLAN connection method from the first destination. |
|
766 * -Remove the WLAN connection method from the other destination. |
|
767 * -Delete the Destinations. |
|
768 * -Delete connection method. |
|
769 */ |
|
770 void TestCmMgrShim::tcDestinationRemoveConnectionMethod() |
|
771 { |
|
772 // Create a new destination |
|
773 CmDestinationShim *dest1; |
|
774 dest1 = mCmManagerShim->createDestination("TestDestination1"); |
|
775 QVERIFY(dest1 != NULL); |
|
776 uint destId1 = dest1->id(); |
|
777 QVERIFY(destId1 >= 4000); |
|
778 |
|
779 // Create another destination |
|
780 CmDestinationShim *dest2; |
|
781 dest2 = mCmManagerShim->createDestination("TestDestination2"); |
|
782 QVERIFY(dest2 != NULL); |
|
783 uint destId2 = dest2->id(); |
|
784 QVERIFY(destId2 >= 4000); |
|
785 |
|
786 // Check destinations initial content |
|
787 int connMethodCount = dest1->connectionMethodCount(); |
|
788 QCOMPARE(connMethodCount, 0); |
|
789 connMethodCount = dest2->connectionMethodCount(); |
|
790 QCOMPARE(connMethodCount, 0); |
|
791 |
|
792 // Create a WLAN connection method |
|
793 CmConnectionMethodShim *cmWlan = mCmManagerShim->createConnectionMethod( |
|
794 CMManagerShim::BearerTypeWlan); |
|
795 QVERIFY(cmWlan != NULL); |
|
796 // Update to CommsDat |
|
797 cmWlan->update(); |
|
798 |
|
799 uint cmWlanId = cmWlan->getIntAttribute(CMManagerShim::CmId); |
|
800 QCOMPARE(cmWlanId, (uint)1); |
|
801 |
|
802 // Add the connection method to the destination 1 |
|
803 int index = dest1->addConnectionMethod(cmWlan); |
|
804 QCOMPARE(index, 0); |
|
805 // Update to CommsDat |
|
806 dest1->update(); |
|
807 |
|
808 // Add the connection method to the destination 2 |
|
809 index = dest2->addConnectionMethod(cmWlan); |
|
810 QCOMPARE(index, 0); |
|
811 // Update to CommsDat |
|
812 dest2->update(); |
|
813 |
|
814 // Remove the WLAN connection method from destination 1 |
|
815 dest1->removeConnectionMethod(cmWlan); |
|
816 // Update to CommsDat |
|
817 dest1->update(); |
|
818 |
|
819 // Verify the delete |
|
820 connMethodCount = dest1->connectionMethodCount(); |
|
821 QCOMPARE(connMethodCount, 0); |
|
822 |
|
823 // Check that WLAN connection method still exists for destination 2 |
|
824 connMethodCount = dest2->connectionMethodCount(); |
|
825 QCOMPARE(connMethodCount, 1); |
|
826 |
|
827 // Remove the WLAN connection method from destination 2 |
|
828 dest2->removeConnectionMethod(cmWlan); |
|
829 // Update to CommsDat |
|
830 dest2->update(); |
|
831 |
|
832 // Verify the delete |
|
833 connMethodCount = dest2->connectionMethodCount(); |
|
834 QCOMPARE(connMethodCount, 0); |
|
835 |
|
836 // Delete destinations |
|
837 dest1->deleteDestination(); |
|
838 delete dest1; |
|
839 dest2->deleteDestination(); |
|
840 delete dest2; |
|
841 |
|
842 // Check that WLAN connection method still exists |
|
843 delete cmWlan; |
|
844 cmWlan = mCmManagerShim->connectionMethod(cmWlanId); |
|
845 QVERIFY(cmWlan != NULL); |
|
846 |
|
847 // Remove WLAN connection method. |
|
848 cmWlan->deleteConnectionMethod(); |
|
849 delete cmWlan; |
|
850 } |
|
851 |
|
852 /** |
|
853 * Test case for testing destination's cm priority reading and changing. |
|
854 * -Create a destination |
|
855 * -Add a GPRS connection method to it. |
|
856 * -Add a WLAN connection method to it. |
|
857 * -Read priority values of the connection methods |
|
858 * -Change the priority values |
|
859 * -Read the changed priority values |
|
860 * -Try to change the priority value to unsupported value |
|
861 * -Delete the destination (and connection methods) |
|
862 */ |
|
863 void TestCmMgrShim::tcDestinationPriority() |
|
864 { |
|
865 // Create a new destination |
|
866 CmDestinationShim *dest; |
|
867 dest = mCmManagerShim->createDestination("TestDestination"); |
|
868 QVERIFY(dest != NULL); |
|
869 uint destId = dest->id(); |
|
870 QVERIFY(destId >= 4000); |
|
871 |
|
872 // Create a GPRS connection method |
|
873 CmConnectionMethodShim *cmGprs = mCmManagerShim->createConnectionMethod( |
|
874 CMManagerShim::BearerTypePacketData); |
|
875 QVERIFY(cmGprs != NULL); |
|
876 // Update to CommsDat |
|
877 cmGprs->update(); |
|
878 |
|
879 // Add the connection method to the destination |
|
880 int index = dest->addConnectionMethod(cmGprs); |
|
881 QCOMPARE(index, 0); |
|
882 // Update to CommsDat |
|
883 dest->update(); |
|
884 |
|
885 // Create a WLAN connection method |
|
886 CmConnectionMethodShim *cmWlan = mCmManagerShim->createConnectionMethod( |
|
887 CMManagerShim::BearerTypeWlan); |
|
888 QVERIFY(cmWlan != NULL); |
|
889 // Update to CommsDat |
|
890 cmWlan->update(); |
|
891 |
|
892 // Add the connection method to the destination |
|
893 index = dest->addConnectionMethod(cmWlan); |
|
894 QCOMPARE(index, 0); |
|
895 // Update to CommsDat |
|
896 dest->update(); |
|
897 |
|
898 // Get the priority of connection methods |
|
899 int priority = dest->priority(cmWlan); |
|
900 QCOMPARE(priority, 1); |
|
901 priority = dest->priority(cmGprs); |
|
902 QCOMPARE(priority, 2); |
|
903 |
|
904 // Modify the priority of GPRS connection method |
|
905 dest->modifyPriority(cmGprs, 0); |
|
906 dest->modifyPriority(cmWlan, 1); |
|
907 // Update to CommsDat |
|
908 dest->update(); |
|
909 |
|
910 // Check the priorities |
|
911 priority = dest->priority(cmGprs); |
|
912 QCOMPARE(priority, 1); |
|
913 priority = dest->priority(cmWlan); |
|
914 QCOMPARE(priority, 2); |
|
915 |
|
916 // Try to modify the priority to forbidden value |
|
917 TEST_CATCH_AND_VERIFY( |
|
918 dest->modifyPriority(cmGprs, 2), |
|
919 KErrArgument); |
|
920 |
|
921 // Delete the whole destination including the remaining WLAN conn method. |
|
922 dest->deleteDestination(); |
|
923 |
|
924 delete dest; |
|
925 delete cmGprs; |
|
926 delete cmWlan; |
|
927 } |
|
928 |
|
929 /** |
|
930 * Test case for testing miscellaneous methods for destination. |
|
931 * -Create a destination |
|
932 * -Change the name of the destination |
|
933 * -Check if the destination is hidden |
|
934 * -Check if destination is "internet" with metadata. |
|
935 * -Delete the destination |
|
936 */ |
|
937 void TestCmMgrShim::tcDestinationMisc() |
|
938 { |
|
939 // Create a new destination |
|
940 CmDestinationShim *dest; |
|
941 dest = mCmManagerShim->createDestination("TestDestination"); |
|
942 QVERIFY(dest != NULL); |
|
943 uint destId = dest->id(); |
|
944 QVERIFY(destId >= 4000); |
|
945 |
|
946 // Change the name of the destination |
|
947 dest->setName("NewName"); |
|
948 // Update to CommsDat |
|
949 dest->update(); |
|
950 |
|
951 // Check the name |
|
952 QString name(dest->name()); |
|
953 QCOMPARE(name, QString("NewName")); |
|
954 |
|
955 // Check if destination is hidden |
|
956 bool hidden = dest->isHidden(); |
|
957 QCOMPARE(hidden, false); |
|
958 |
|
959 // Check "internet" metadata field |
|
960 uint metadata = dest->metadata(CMManagerShim::SnapMetadataInternet); |
|
961 QCOMPARE(metadata, (uint)false); |
|
962 |
|
963 // Delete the destination |
|
964 dest->deleteDestination(); |
|
965 delete dest; |
|
966 } |
|
967 |
|
968 /** |
|
969 * Test case for testing destination refreshing method. |
|
970 * -Create a destination |
|
971 * -Add a GPRS connection method, but don't update CommsDat |
|
972 * -Change the name of the destination, but don't update CommsDat |
|
973 * -Refresh destination |
|
974 * -Check that the changes are not valid anymore |
|
975 * -Delete the destination |
|
976 * -Delete the connection method |
|
977 */ |
|
978 void TestCmMgrShim::tcDestinationRefresh() |
|
979 { |
|
980 // Create a new destination |
|
981 CmDestinationShim *dest; |
|
982 dest = mCmManagerShim->createDestination("TestDestination"); |
|
983 QVERIFY(dest != NULL); |
|
984 uint destId = dest->id(); |
|
985 QVERIFY(destId >= 4000); |
|
986 dest->update(); |
|
987 |
|
988 // Create a GPRS connection method |
|
989 CmConnectionMethodShim *cmGprs = mCmManagerShim->createConnectionMethod( |
|
990 CMManagerShim::BearerTypePacketData); |
|
991 QVERIFY(cmGprs != NULL); |
|
992 // Update to CommsDat |
|
993 cmGprs->update(); |
|
994 |
|
995 // Add the connection method to the destination |
|
996 int index = dest->addConnectionMethod(cmGprs); |
|
997 QCOMPARE(index, 0); |
|
998 // Don't update CommsDat |
|
999 |
|
1000 // Change the name of the destination |
|
1001 dest->setName("NewName"); |
|
1002 // Don't update to CommsDat |
|
1003 |
|
1004 // Refresh destination |
|
1005 dest->refresh(); |
|
1006 |
|
1007 // Delete the destination reference |
|
1008 delete dest; |
|
1009 |
|
1010 // Refetch the destination |
|
1011 dest = mCmManagerShim->destination(destId); |
|
1012 QVERIFY(dest != NULL); |
|
1013 |
|
1014 // Check the name that it is the original one |
|
1015 QString name(dest->name()); |
|
1016 QCOMPARE(name, QString("TestDestination")); |
|
1017 |
|
1018 // Check destination content |
|
1019 int connMethodCount = dest->connectionMethodCount(); |
|
1020 QCOMPARE(connMethodCount, 0); |
|
1021 |
|
1022 // Delete the destination |
|
1023 dest->deleteDestination(); |
|
1024 delete dest; |
|
1025 |
|
1026 // Delete connection method |
|
1027 bool ok = cmGprs->deleteConnectionMethod(); |
|
1028 delete cmGprs; |
|
1029 QCOMPARE(ok, true); |
|
1030 } |
|
1031 |
|
1032 /** |
|
1033 * Test case for testing data reads using a invalid input data. |
|
1034 * All test reads in this case should fail to an exception. |
|
1035 */ |
|
1036 void TestCmMgrShim::tcDestinationInvalidParams() |
|
1037 { |
|
1038 // Create a new destination |
|
1039 CmDestinationShim *dest; |
|
1040 dest = mCmManagerShim->createDestination("TestDestination"); |
|
1041 QVERIFY(dest != NULL); |
|
1042 |
|
1043 // Update to CommsDat |
|
1044 dest->update(); |
|
1045 |
|
1046 // Try reading with an invalid connection method index |
|
1047 CmConnectionMethodShim *cm = 0; |
|
1048 TEST_CATCH_AND_VERIFY( |
|
1049 dest->connectionMethod(42), |
|
1050 KErrArgument); |
|
1051 QVERIFY(cm == 0); |
|
1052 |
|
1053 // Try reading with an invalid connection method ID |
|
1054 cm = 0; |
|
1055 TEST_CATCH_AND_VERIFY( |
|
1056 dest->connectionMethodByID(42), |
|
1057 KErrNotFound); |
|
1058 QVERIFY(cm == 0); |
|
1059 |
|
1060 // Delete the destination |
|
1061 dest->deleteDestination(); |
|
1062 delete dest; |
|
1063 } |
|
1064 |
|
1065 // ----------------------------------------------------------------------------- |
|
1066 // SUB TEST CASES |
|
1067 // ----------------------------------------------------------------------------- |
|
1068 |
|
1069 /** |
|
1070 * Case for deleting all destinations. |
|
1071 */ |
|
1072 void TestCmMgrShim::deleteDestinations() |
|
1073 { |
|
1074 // Read all destinations |
|
1075 QList<uint> destinations; |
|
1076 mCmManagerShim->allDestinations(destinations); |
|
1077 |
|
1078 // Delete the destinations |
|
1079 for (int i=0; i < destinations.count(); i++) { |
|
1080 CmDestinationShim *dest = mCmManagerShim->destination(destinations[i]); |
|
1081 dest->deleteDestination(); |
|
1082 delete dest; |
|
1083 } |
|
1084 } |
|
1085 |
|
1086 /** |
|
1087 * Case for deleting all connection methods. |
|
1088 */ |
|
1089 void TestCmMgrShim::deleteConnectionMethods() |
|
1090 { |
|
1091 // Read all connection methods |
|
1092 QList<uint> connMethods; |
|
1093 mCmManagerShim->connectionMethod(connMethods, false); |
|
1094 |
|
1095 // Remove all connection methods |
|
1096 for (int i=0; i < connMethods.count(); i++){ |
|
1097 CmConnectionMethodShim *cm = |
|
1098 mCmManagerShim->connectionMethod(connMethods[i]); |
|
1099 QVERIFY(cm != NULL); |
|
1100 bool ok = cm->deleteConnectionMethod(); |
|
1101 QVERIFY(ok == true); |
|
1102 delete cm; |
|
1103 } |
|
1104 } |