111 |
112 |
112 // Helper functions |
113 // Helper functions |
113 bool openSession(QNetworkSession *session); |
114 bool openSession(QNetworkSession *session); |
114 bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration = true); |
115 bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration = true); |
115 void updateConfigurations(); |
116 void updateConfigurations(); |
|
117 void printConfigurations(); |
116 QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfiguration::Type configType); |
118 QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfiguration::Type configType); |
117 |
119 |
118 void tst_QNetworkSession::initTestCase() |
120 void tst_QNetworkSession::initTestCase() |
119 { |
121 { |
120 qRegisterMetaType<QNetworkSession::State>("QNetworkSession::State"); |
122 qRegisterMetaType<QNetworkSession::State>("QNetworkSession::State"); |
121 qRegisterMetaType<QNetworkSession::SessionError>("QNetworkSession::SessionError"); |
123 qRegisterMetaType<QNetworkSession::SessionError>("QNetworkSession::SessionError"); |
122 qRegisterMetaType<QNetworkConfiguration>("QNetworkConfiguration"); |
124 qRegisterMetaType<QNetworkConfiguration>("QNetworkConfiguration"); |
123 qRegisterMetaType<QNetworkConfiguration::Type>("QNetworkConfiguration::Type"); |
125 qRegisterMetaType<QNetworkConfiguration::Type>("QNetworkConfiguration::Type"); |
124 |
126 |
|
127 // If you wish to skip tests, set value as false. This is often very convinient because tests are so lengthy. |
|
128 // Better way still would be to make this readable from a file. |
|
129 testsToRun["robustnessBombing"] = true; |
|
130 testsToRun["outOfProcessSession"] = true; |
|
131 testsToRun["invalidSession"] = true; |
|
132 testsToRun["repeatedOpenClose"] = true; |
|
133 testsToRun["roamingErrorCodes"] = true; |
|
134 testsToRun["sessionStop"] = true; |
|
135 testsToRun["sessionProperties"] = true; |
|
136 testsToRun["userChoiceSession"] = true; |
|
137 testsToRun["sessionOpenCloseStop"] = true; |
|
138 |
125 #if defined(Q_WS_MAEMO_6) || defined(Q_WS_MAEMO_5) |
139 #if defined(Q_WS_MAEMO_6) || defined(Q_WS_MAEMO_5) |
126 iapconf = new Maemo::IAPConf("007"); |
140 iapconf = new Maemo::IAPConf("007"); |
127 iapconf->setValue("ipv4_type", "AUTO"); |
141 iapconf->setValue("ipv4_type", "AUTO"); |
128 iapconf->setValue("wlan_wepkey1", "connt"); |
142 iapconf->setValue("wlan_wepkey1", "connt"); |
129 iapconf->setValue("wlan_wepdefkey", 1); |
143 iapconf->setValue("wlan_wepdefkey", 1); |
232 } |
246 } |
233 |
247 |
234 // Robustness test for calling interfaces in nonsense order / with nonsense parameters |
248 // Robustness test for calling interfaces in nonsense order / with nonsense parameters |
235 void tst_QNetworkSession::robustnessBombing() |
249 void tst_QNetworkSession::robustnessBombing() |
236 { |
250 { |
|
251 if (!testsToRun["robustnessBombing"]) { |
|
252 QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll); |
|
253 } |
|
254 |
237 QNetworkConfigurationManager mgr; |
255 QNetworkConfigurationManager mgr; |
238 QNetworkSession testSession(mgr.defaultConfiguration()); |
256 QNetworkSession testSession(mgr.defaultConfiguration()); |
239 // Should not reset even session is not opened |
257 // Should not reset even session is not opened |
240 testSession.migrate(); |
258 testSession.migrate(); |
241 testSession.accept(); |
259 testSession.accept(); |
242 testSession.ignore(); |
260 testSession.ignore(); |
243 testSession.reject(); |
261 testSession.reject(); |
244 quint64 temp; |
|
245 temp = testSession.bytesWritten(); |
|
246 temp = testSession.bytesReceived(); |
|
247 temp = testSession.activeTime(); |
|
248 } |
262 } |
249 |
263 |
250 |
264 |
251 void tst_QNetworkSession::invalidSession() |
265 void tst_QNetworkSession::invalidSession() |
252 { |
266 { |
|
267 if (!testsToRun["invalidSession"]) { |
|
268 QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll); |
|
269 } |
253 // 1. Verify that session created with invalid configuration remains in invalid state |
270 // 1. Verify that session created with invalid configuration remains in invalid state |
254 QNetworkSession session(QNetworkConfiguration(), 0); |
271 QNetworkSession session(QNetworkConfiguration(), 0); |
255 QVERIFY(!session.isOpen()); |
272 QVERIFY(!session.isOpen()); |
256 QVERIFY(session.state() == QNetworkSession::Invalid); |
273 QVERIFY(session.state() == QNetworkSession::Invalid); |
257 |
274 |
262 QVERIFY(errorSpy.count() == 1); |
279 QVERIFY(errorSpy.count() == 1); |
263 QNetworkSession::SessionError error = |
280 QNetworkSession::SessionError error = |
264 qvariant_cast<QNetworkSession::SessionError> (errorSpy.first().at(0)); |
281 qvariant_cast<QNetworkSession::SessionError> (errorSpy.first().at(0)); |
265 QVERIFY(error == QNetworkSession::InvalidConfigurationError); |
282 QVERIFY(error == QNetworkSession::InvalidConfigurationError); |
266 QVERIFY(session.state() == QNetworkSession::Invalid); |
283 QVERIFY(session.state() == QNetworkSession::Invalid); |
267 |
284 |
268 #ifdef QNETWORKSESSION_MANUAL_TESTS |
285 #ifdef QNETWORKSESSION_MANUAL_TESTS |
|
286 |
|
287 QNetworkConfiguration invalidatedConfig = suitableConfiguration("WLAN",QNetworkConfiguration::InternetAccessPoint); |
|
288 if (invalidatedConfig.isValid()) { |
|
289 // 3. Verify that invalidating a session after its successfully configured works |
|
290 QNetworkSession invalidatedSession(invalidatedConfig); |
|
291 qDebug() << "Delete the WLAN IAP from phone now (waiting 60 seconds): " << invalidatedConfig.name(); |
|
292 QTest::qWait(60000); |
|
293 QVERIFY(!invalidatedConfig.isValid()); |
|
294 QVERIFY(invalidatedSession.state() == QNetworkSession::Invalid); |
|
295 qDebug() << "Add the WLAN IAP back (waiting 60 seconds): " << invalidatedConfig.name(); |
|
296 QTest::qWait(60000); |
|
297 } |
|
298 |
269 QNetworkConfiguration definedConfig = suitableConfiguration("WLAN",QNetworkConfiguration::InternetAccessPoint); |
299 QNetworkConfiguration definedConfig = suitableConfiguration("WLAN",QNetworkConfiguration::InternetAccessPoint); |
270 if (definedConfig.isValid()) { |
300 if (definedConfig.isValid()) { |
271 // 3. Verify that opening a session with defined configuration emits error and enters notavailable-state |
301 // 4. Verify that opening a session with defined configuration emits error and enters notavailable-state |
272 // TODO these timer waits should be changed to waiting appropriate signals, now these wait excessively |
302 // TODO these timer waits should be changed to waiting appropriate signals, now these wait excessively |
273 qDebug() << "Shutdown WLAN IAP (waiting 60 seconds): " << definedConfig.name(); |
303 qDebug() << "Shutdown WLAN IAP (waiting 60 seconds): " << definedConfig.name(); |
274 QTest::qWait(60000); |
304 QTest::qWait(60000); |
275 // Shutting down WLAN should bring back to defined -state. |
305 // Shutting down WLAN should bring back to defined -state. |
276 QVERIFY((definedConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined); |
306 QVERIFY((definedConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined); |
277 QNetworkSession definedSession(definedConfig); |
307 QNetworkSession definedSession(definedConfig); |
278 QSignalSpy errorSpy(&definedSession, SIGNAL(error(QNetworkSession::SessionError))); |
308 QSignalSpy errorSpy(&definedSession, SIGNAL(error(QNetworkSession::SessionError))); |
279 QNetworkSession::SessionError sessionError; |
309 QNetworkSession::SessionError sessionError; |
|
310 updateConfigurations(); |
280 |
311 |
281 definedSession.open(); |
312 definedSession.open(); |
|
313 #ifdef Q_OS_SYMBIAN |
|
314 // On symbian, the connection opening is tried even with defined state. |
|
315 qDebug("Waiting for 10 seconds to all signals to propagate."); |
|
316 QTest::qWait(10000); |
|
317 #endif |
|
318 updateConfigurations(); |
282 |
319 |
283 QVERIFY(definedConfig.isValid()); // Session remains valid |
320 QVERIFY(definedConfig.isValid()); // Session remains valid |
284 QVERIFY(definedSession.state() == QNetworkSession::NotAvailable); // State is not available because WLAN is not in coverage |
321 QVERIFY(definedSession.state() == QNetworkSession::NotAvailable); // State is not available because WLAN is not in coverage |
285 QVERIFY(!errorSpy.isEmpty()); // Session tells with error about invalidated configuration |
322 QVERIFY(!errorSpy.isEmpty()); // Session tells with error about invalidated configuration |
286 sessionError = qvariant_cast<QNetworkSession::SessionError> (errorSpy.first().at(0)); |
323 sessionError = qvariant_cast<QNetworkSession::SessionError> (errorSpy.first().at(0)); |
287 qDebug() << "Error code is: " << sessionError; |
|
288 QVERIFY(sessionError == QNetworkSession::InvalidConfigurationError); |
324 QVERIFY(sessionError == QNetworkSession::InvalidConfigurationError); |
289 |
|
290 qDebug() << "Turn the WLAN IAP back on (waiting 60 seconds): " << definedConfig.name(); |
325 qDebug() << "Turn the WLAN IAP back on (waiting 60 seconds): " << definedConfig.name(); |
291 QTest::qWait(60000); |
326 QTest::qWait(60000); |
292 updateConfigurations(); |
327 updateConfigurations(); |
293 |
|
294 QVERIFY(definedConfig.state() == QNetworkConfiguration::Discovered); |
328 QVERIFY(definedConfig.state() == QNetworkConfiguration::Discovered); |
295 } |
329 } |
296 |
330 |
297 QNetworkConfiguration invalidatedConfig = suitableConfiguration("WLAN",QNetworkConfiguration::InternetAccessPoint); |
|
298 if (invalidatedConfig.isValid()) { |
|
299 // 4. Verify that invalidating a session after its successfully configured works |
|
300 QNetworkSession invalidatedSession(invalidatedConfig); |
|
301 QSignalSpy errorSpy(&invalidatedSession, SIGNAL(error(QNetworkSession::SessionError))); |
|
302 QNetworkSession::SessionError sessionError; |
|
303 |
|
304 qDebug() << "Delete the WLAN IAP from phone now (waiting 60 seconds): " << invalidatedConfig.name(); |
|
305 QTest::qWait(60000); |
|
306 |
|
307 invalidatedSession.open(); |
|
308 QVERIFY(!invalidatedConfig.isValid()); |
|
309 QVERIFY(invalidatedSession.state() == QNetworkSession::Invalid); |
|
310 QVERIFY(!errorSpy.isEmpty()); |
|
311 |
|
312 sessionError = qvariant_cast<QNetworkSession::SessionError> (errorSpy.first().at(0)); |
|
313 QVERIFY(sessionError == QNetworkSession::InvalidConfigurationError); |
|
314 qDebug() << "Add the WLAN IAP back (waiting 60 seconds): " << invalidatedConfig.name(); |
|
315 QTest::qWait(60000); |
|
316 } |
|
317 #endif |
331 #endif |
318 } |
332 } |
319 |
333 |
320 void tst_QNetworkSession::sessionProperties_data() |
334 void tst_QNetworkSession::sessionProperties_data() |
321 { |
335 { |
405 // QTest::newRow("Cellular_IAP") << "cellular" << QNetworkConfiguration::InternetAccessPoint << 3; |
419 // QTest::newRow("Cellular_IAP") << "cellular" << QNetworkConfiguration::InternetAccessPoint << 3; |
406 // QTest::newRow("SNAP") << "bearer_type_not_relevant_with_SNAPs" << QNetworkConfiguration::ServiceNetwork << 3; |
420 // QTest::newRow("SNAP") << "bearer_type_not_relevant_with_SNAPs" << QNetworkConfiguration::ServiceNetwork << 3; |
407 } |
421 } |
408 |
422 |
409 // Tests repeated-open close. |
423 // Tests repeated-open close. |
410 void tst_QNetworkSession::repeatedOpenClose() { |
424 void tst_QNetworkSession::repeatedOpenClose() |
|
425 { |
|
426 if (!testsToRun["repeatedOpenClose"]) { |
|
427 QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll); |
|
428 } |
|
429 |
411 QFETCH(QString, bearerType); |
430 QFETCH(QString, bearerType); |
412 QFETCH(QNetworkConfiguration::Type, configurationType); |
431 QFETCH(QNetworkConfiguration::Type, configurationType); |
413 QFETCH(int, repeatTimes); |
432 QFETCH(int, repeatTimes); |
414 |
433 |
415 // First check that opening once succeeds and determine if repeatable testing is doable |
434 // First check that opening once succeeds and determine if repeatable testing is doable |
421 QNetworkSession permanentSession(config); |
440 QNetworkSession permanentSession(config); |
422 if (!openSession(&permanentSession) || |
441 if (!openSession(&permanentSession) || |
423 !closeSession(&permanentSession)) { |
442 !closeSession(&permanentSession)) { |
424 QSKIP("Unable to open/close session, skipping this round of repeated open-close test.", SkipSingle); |
443 QSKIP("Unable to open/close session, skipping this round of repeated open-close test.", SkipSingle); |
425 } |
444 } |
426 for (int i = repeatTimes; i > 0; i--) { |
445 for (int i = 0; i < repeatTimes; i++) { |
|
446 qDebug() << "Opening, loop number " << i; |
427 QVERIFY(openSession(&permanentSession)); |
447 QVERIFY(openSession(&permanentSession)); |
|
448 qDebug() << "Closing, loop number, then waiting 5 seconds: " << i; |
428 QVERIFY(closeSession(&permanentSession)); |
449 QVERIFY(closeSession(&permanentSession)); |
429 } |
450 QTest::qWait(5000); |
430 } |
451 } |
431 |
452 } |
432 void tst_QNetworkSession::roamingErrorCodes() { |
453 |
|
454 void tst_QNetworkSession::roamingErrorCodes() |
|
455 { |
|
456 if (!testsToRun["roamingErrorCodes"]) { |
|
457 QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll); |
|
458 } |
433 #ifndef Q_OS_SYMBIAN |
459 #ifndef Q_OS_SYMBIAN |
434 QSKIP("Roaming supported on Symbian.", SkipAll); |
460 QSKIP("Roaming supported on Symbian.", SkipAll); |
435 #else |
461 #else |
436 QNetworkConfiguration wlanIapConfig = suitableConfiguration("WLAN", QNetworkConfiguration::InternetAccessPoint); |
462 QNetworkConfiguration wlanIapConfig = suitableConfiguration("WLAN", QNetworkConfiguration::InternetAccessPoint); |
437 if (!wlanIapConfig.isValid()) { |
463 if (!wlanIapConfig.isValid()) { |
451 QVERIFY(openSession(&adminIapSession)); |
477 QVERIFY(openSession(&adminIapSession)); |
452 QSignalSpy errorSpy(&iapSession, SIGNAL(error(QNetworkSession::SessionError))); |
478 QSignalSpy errorSpy(&iapSession, SIGNAL(error(QNetworkSession::SessionError))); |
453 adminIapSession.stop(); // requires NetworkControl capabilities |
479 adminIapSession.stop(); // requires NetworkControl capabilities |
454 QTRY_VERIFY(!errorSpy.isEmpty()); // wait for error signals |
480 QTRY_VERIFY(!errorSpy.isEmpty()); // wait for error signals |
455 QNetworkSession::SessionError error = qvariant_cast<QNetworkSession::SessionError>(errorSpy.first().at(0)); |
481 QNetworkSession::SessionError error = qvariant_cast<QNetworkSession::SessionError>(errorSpy.first().at(0)); |
|
482 QTest::qWait(2000); // Wait for a moment to all platform signals to propagate |
456 QVERIFY(error == QNetworkSession::SessionAbortedError); |
483 QVERIFY(error == QNetworkSession::SessionAbortedError); |
457 QVERIFY(iapSession.state() == QNetworkSession::Disconnected); |
484 QVERIFY(iapSession.state() == QNetworkSession::Disconnected); |
458 QVERIFY(adminIapSession.state() == QNetworkSession::Disconnected); |
485 QVERIFY(adminIapSession.state() == QNetworkSession::Disconnected); |
459 #endif // Q_OS_SYMBIAN |
486 #endif // Q_OS_SYMBIAN |
460 |
|
461 #ifdef QNETWORKSESSION_MANUAL_TESTS |
|
462 // Check for roaming error. |
|
463 // Case requires that you have controllable WLAN in Internet SNAP (only). |
|
464 QNetworkConfiguration snapConfig = suitableConfiguration("bearer_not_relevant_with_snaps", QNetworkConfiguration::ServiceNetwork); |
|
465 if (!snapConfig.isValid()) { |
|
466 QSKIP("No SNAP accessible, skipping test.", SkipAll); |
|
467 } |
|
468 QNetworkSession snapSession(snapConfig); |
|
469 QVERIFY(openSession(&snapSession)); |
|
470 QSignalSpy errorSpySnap(&snapSession, SIGNAL(error(QNetworkSession::SessionError))); |
|
471 qDebug("Disconnect the WLAN now"); |
|
472 QTRY_VERIFY(!errorSpySnap.isEmpty()); // wait for error signals |
|
473 QVERIFY(errorSpySnap.count() == 1); |
|
474 error = qvariant_cast<QNetworkSession::SessionError>(errorSpySnap.first().at(0)); |
|
475 qDebug() << "Error received when turning off wlan on SNAP: " << error; |
|
476 QVERIFY(error == QNetworkSession::RoamingError); |
|
477 |
|
478 qDebug("Connect the WLAN now"); |
|
479 QTest::qWait(60000); // Wait for WLAN to get up |
|
480 QNetworkConfiguration wlanIapConfig2 = suitableConfiguration("WLAN", QNetworkConfiguration::InternetAccessPoint); |
|
481 QNetworkSession iapSession2(wlanIapConfig2); |
|
482 QVERIFY(openSession(&iapSession2)); |
|
483 QSignalSpy errorSpy2(&iapSession2, SIGNAL(error(QNetworkSession::SessionError))); |
|
484 qDebug("Disconnect the WLAN now"); |
|
485 QTRY_VERIFY(!errorSpy2.isEmpty()); // wait for error signals |
|
486 QVERIFY(errorSpy2.count() == 1); |
|
487 error = qvariant_cast<QNetworkSession::SessionError>(errorSpy2.first().at(0)); |
|
488 QVERIFY(error == QNetworkSession::SessionAbortedError); |
|
489 QVERIFY(iapSession2.state() == QNetworkSession::Disconnected); |
|
490 #endif |
|
491 } |
487 } |
492 |
488 |
493 |
489 |
494 void tst_QNetworkSession::sessionStop_data() { |
490 void tst_QNetworkSession::sessionStop_data() { |
495 QTest::addColumn<QString>("bearerType"); |
491 QTest::addColumn<QString>("bearerType"); |
500 QTest::newRow("Cellular_IAP") << "cellular" << QNetworkConfiguration::InternetAccessPoint; |
496 QTest::newRow("Cellular_IAP") << "cellular" << QNetworkConfiguration::InternetAccessPoint; |
501 } |
497 } |
502 |
498 |
503 void tst_QNetworkSession::sessionStop() |
499 void tst_QNetworkSession::sessionStop() |
504 { |
500 { |
|
501 if (!testsToRun["sessionStop"]) { |
|
502 QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll); |
|
503 } |
505 #ifndef Q_OS_SYMBIAN |
504 #ifndef Q_OS_SYMBIAN |
506 QSKIP("Testcase contains mainly Symbian specific checks, because it is only platform to really support interface (IAP-level) Stop.", SkipAll); |
505 QSKIP("Testcase contains mainly Symbian specific checks, because it is only platform to really support interface (IAP-level) Stop.", SkipAll); |
507 #endif |
506 #endif |
508 QFETCH(QString, bearerType); |
507 QFETCH(QString, bearerType); |
509 QFETCH(QNetworkConfiguration::Type, configurationType); |
508 QFETCH(QNetworkConfiguration::Type, configurationType); |
510 |
509 |
511 int configWaitdelayInMs = 2000; |
510 int configWaitdelayInMs = 2000; |
|
511 |
|
512 updateConfigurations(); |
|
513 printConfigurations(); |
512 |
514 |
513 QNetworkConfiguration config = suitableConfiguration(bearerType, configurationType); |
515 QNetworkConfiguration config = suitableConfiguration(bearerType, configurationType); |
514 if (!config.isValid()) { |
516 if (!config.isValid()) { |
515 QSKIP("No suitable configurations, skipping this round of session stop test.", SkipSingle); |
517 QSKIP("No suitable configurations, skipping this round of session stop test.", SkipSingle); |
516 } |
518 } |
523 |
525 |
524 QSignalSpy closedSessionOpenedSpy(&closedSession, SIGNAL(opened())); |
526 QSignalSpy closedSessionOpenedSpy(&closedSession, SIGNAL(opened())); |
525 QSignalSpy closedSessionClosedSpy(&closedSession, SIGNAL(closed())); |
527 QSignalSpy closedSessionClosedSpy(&closedSession, SIGNAL(closed())); |
526 QSignalSpy closedSessionStateChangedSpy(&closedSession, SIGNAL(stateChanged(QNetworkSession::State))); |
528 QSignalSpy closedSessionStateChangedSpy(&closedSession, SIGNAL(stateChanged(QNetworkSession::State))); |
527 QSignalSpy closedErrorSpy(&closedSession, SIGNAL(error(QNetworkSession::SessionError))); |
529 QSignalSpy closedErrorSpy(&closedSession, SIGNAL(error(QNetworkSession::SessionError))); |
|
530 |
|
531 QSignalSpy openedSessionClosedSpy(&openedSession, SIGNAL(closed())); |
|
532 QSignalSpy openedSessionStateChangedSpy(&openedSession, SIGNAL(stateChanged(QNetworkSession::State))); |
528 |
533 |
529 QSignalSpy innocentSessionClosedSpy(&innocentSession, SIGNAL(closed())); |
534 QSignalSpy innocentSessionClosedSpy(&innocentSession, SIGNAL(closed())); |
530 QSignalSpy innocentSessionStateChangedSpy(&innocentSession, SIGNAL(stateChanged(QNetworkSession::State))); |
535 QSignalSpy innocentSessionStateChangedSpy(&innocentSession, SIGNAL(stateChanged(QNetworkSession::State))); |
531 QSignalSpy innocentErrorSpy(&innocentSession, SIGNAL(error(QNetworkSession::SessionError))); |
536 QSignalSpy innocentErrorSpy(&innocentSession, SIGNAL(error(QNetworkSession::SessionError))); |
532 QNetworkSession::SessionError sessionError; |
537 QNetworkSession::SessionError sessionError; |
539 // Clear signals caused by opening |
544 // Clear signals caused by opening |
540 closedSessionOpenedSpy.clear(); |
545 closedSessionOpenedSpy.clear(); |
541 closedSessionClosedSpy.clear(); |
546 closedSessionClosedSpy.clear(); |
542 closedSessionStateChangedSpy.clear(); |
547 closedSessionStateChangedSpy.clear(); |
543 closedErrorSpy.clear(); |
548 closedErrorSpy.clear(); |
|
549 openedSessionStateChangedSpy.clear(); |
|
550 openedSessionClosedSpy.clear(); |
|
551 |
544 openedSession.stop(); |
552 openedSession.stop(); |
545 |
553 |
|
554 qDebug("Waiting for %d ms to get all configurationChange signals from platform.", configWaitdelayInMs); |
|
555 QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals |
|
556 |
|
557 // First to closing, then to disconnected |
|
558 QVERIFY(openedSessionStateChangedSpy.count() == 2); |
|
559 QVERIFY(!openedSessionClosedSpy.isEmpty()); |
546 QVERIFY(openedSession.state() == QNetworkSession::Disconnected); |
560 QVERIFY(openedSession.state() == QNetworkSession::Disconnected); |
547 QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals |
|
548 QVERIFY(config.state() != QNetworkConfiguration::Active); |
561 QVERIFY(config.state() != QNetworkConfiguration::Active); |
549 |
562 |
550 // 2. Verify that stopping a session based on non-connected configuration does nothing |
563 // 2. Verify that stopping a session based on non-connected configuration does nothing |
551 qDebug("----------2. Verify that stopping a session based on non-connected configuration does nothing"); |
564 qDebug("----------2. Verify that stopping a session based on non-connected configuration does nothing"); |
552 QNetworkSession::State closedSessionOriginalState = closedSession.state(); |
565 QNetworkSession::State closedSessionOriginalState = closedSession.state(); |
568 QVERIFY(closedSession.state() == closedSessionOriginalState); // State remains |
581 QVERIFY(closedSession.state() == closedSessionOriginalState); // State remains |
569 |
582 |
570 // 3. Check that stopping a opened session affects also other opened session based on the same configuration. |
583 // 3. Check that stopping a opened session affects also other opened session based on the same configuration. |
571 if (config.type() == QNetworkConfiguration::InternetAccessPoint) { |
584 if (config.type() == QNetworkConfiguration::InternetAccessPoint) { |
572 qDebug("----------3. Check that stopping a opened session affects also other opened session based on the same configuration."); |
585 qDebug("----------3. Check that stopping a opened session affects also other opened session based on the same configuration."); |
|
586 |
573 QVERIFY(openSession(&openedSession)); |
587 QVERIFY(openSession(&openedSession)); |
574 QVERIFY(openSession(&innocentSession)); |
588 QVERIFY(openSession(&innocentSession)); |
575 |
589 |
576 configChangeSpy.clear(); |
590 configChangeSpy.clear(); |
577 innocentSessionClosedSpy.clear(); |
591 innocentSessionClosedSpy.clear(); |
578 innocentSessionStateChangedSpy.clear(); |
592 innocentSessionStateChangedSpy.clear(); |
579 innocentErrorSpy.clear(); |
593 innocentErrorSpy.clear(); |
580 |
594 |
581 openedSession.stop(); |
595 openedSession.stop(); |
582 qDebug("Waiting for %d ms to get all configurationChange signals from platform.", configWaitdelayInMs); |
596 qDebug("Waiting for %d ms to get all configurationChange signals from platform.", configWaitdelayInMs); |
583 QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals |
597 QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals |
584 |
598 QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals |
|
599 |
585 QVERIFY(!innocentSessionClosedSpy.isEmpty()); |
600 QVERIFY(!innocentSessionClosedSpy.isEmpty()); |
586 QVERIFY(!innocentSessionStateChangedSpy.isEmpty()); |
601 QVERIFY(!innocentSessionStateChangedSpy.isEmpty()); |
587 QVERIFY(!innocentErrorSpy.isEmpty()); |
602 QVERIFY(!innocentErrorSpy.isEmpty()); |
588 QVERIFY(innocentSession.state() == QNetworkSession::Disconnected); |
603 QVERIFY(innocentSession.state() == QNetworkSession::Disconnected); |
589 QVERIFY(openedSession.state() == QNetworkSession::Disconnected); |
604 QVERIFY(openedSession.state() == QNetworkSession::Disconnected); |
599 // 4. Check that stopping a non-opened session stops the other session based on the |
614 // 4. Check that stopping a non-opened session stops the other session based on the |
600 // same configuration if configuration is IAP. Stopping closed SNAP session has no impact on other opened SNAP session. |
615 // same configuration if configuration is IAP. Stopping closed SNAP session has no impact on other opened SNAP session. |
601 if (config.type() == QNetworkConfiguration::ServiceNetwork) { |
616 if (config.type() == QNetworkConfiguration::ServiceNetwork) { |
602 qDebug("----------4. Skip for SNAP configuration."); |
617 qDebug("----------4. Skip for SNAP configuration."); |
603 } else if (config.type() == QNetworkConfiguration::InternetAccessPoint) { |
618 } else if (config.type() == QNetworkConfiguration::InternetAccessPoint) { |
604 qDebug("----------4. Check that stopping a non-opened session stops the other session based on the same configuration"); |
619 qDebug("----------4. Check that stopping a non-opened session stops the other session based on the same configuration"); |
605 QVERIFY(openSession(&innocentSession)); |
620 qDebug("----------4.1 Opening innocent session"); |
|
621 QVERIFY(openSession(&innocentSession)); |
606 qDebug("Waiting for %d ms after open to make sure all platform indications are propagated", configWaitdelayInMs); |
622 qDebug("Waiting for %d ms after open to make sure all platform indications are propagated", configWaitdelayInMs); |
607 QTest::qWait(configWaitdelayInMs); |
623 QTest::qWait(configWaitdelayInMs); |
|
624 qDebug("----------4.2 Calling closedSession.stop()"); |
608 closedSession.stop(); |
625 closedSession.stop(); |
609 qDebug("Waiting for %d ms to get all configurationChange signals from platform..", configWaitdelayInMs); |
626 qDebug("Waiting for %d ms to get all configurationChange signals from platform..", configWaitdelayInMs); |
610 QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals |
627 QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals |
611 |
628 |
|
629 QTest::qWait(configWaitdelayInMs); |
|
630 QTest::qWait(configWaitdelayInMs); |
|
631 |
612 QVERIFY(!innocentSessionClosedSpy.isEmpty()); |
632 QVERIFY(!innocentSessionClosedSpy.isEmpty()); |
613 QVERIFY(!innocentSessionStateChangedSpy.isEmpty()); |
633 QVERIFY(!innocentSessionStateChangedSpy.isEmpty()); |
614 QVERIFY(!innocentErrorSpy.isEmpty()); |
634 QVERIFY(!innocentErrorSpy.isEmpty()); |
615 QVERIFY(innocentSession.state() == QNetworkSession::Disconnected); |
635 QVERIFY(innocentSession.state() == QNetworkSession::Disconnected); |
616 QVERIFY(closedSession.state() == QNetworkSession::Disconnected); |
636 QVERIFY(closedSession.state() == QNetworkSession::Disconnected); |
799 QNetworkSession::State previousState = session.state(); |
838 QNetworkSession::State previousState = session.state(); |
800 bool expectStateChange = previousState != QNetworkSession::Connected; |
839 bool expectStateChange = previousState != QNetworkSession::Connected; |
801 |
840 |
802 session.open(); |
841 session.open(); |
803 |
842 |
|
843 #if defined(Q_OS_SYMBIAN) |
|
844 // Opening & closing multiple connections in a row sometimes |
|
845 // results hanging of connection opening on Symbian devices |
|
846 // => If first open fails, wait a moment and try again. |
|
847 if (!session.waitForOpened()) { |
|
848 qDebug("**** Session open Timeout - Wait 5 seconds and try once again ****"); |
|
849 session.close(); |
|
850 QTest::qWait(5000); // Wait a while before trying to open session again |
|
851 session.open(); |
|
852 session.waitForOpened(); |
|
853 } |
|
854 #else |
804 session.waitForOpened(); |
855 session.waitForOpened(); |
|
856 #endif |
805 |
857 |
806 if (session.isOpen()) |
858 if (session.isOpen()) |
807 QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); |
859 QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); |
808 if (!errorSpy.isEmpty()) { |
860 if (!errorSpy.isEmpty()) { |
809 QNetworkSession::SessionError error = |
861 QNetworkSession::SessionError error = |
873 QVERIFY(!session2.isOpen()); |
925 QVERIFY(!session2.isOpen()); |
874 QVERIFY(session2.state() == QNetworkSession::Connected); |
926 QVERIFY(session2.state() == QNetworkSession::Connected); |
875 QVERIFY(session.error() == QNetworkSession::UnknownSessionError); |
927 QVERIFY(session.error() == QNetworkSession::UnknownSessionError); |
876 |
928 |
877 session2.open(); |
929 session2.open(); |
878 |
930 |
879 QTRY_VERIFY(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty()); |
931 QTRY_VERIFY(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty()); |
880 |
932 |
|
933 if (errorSpy2.isEmpty()) { |
|
934 QVERIFY(session2.isOpen()); |
|
935 QVERIFY(session2.state() == QNetworkSession::Connected); |
|
936 } |
881 QVERIFY(session.isOpen()); |
937 QVERIFY(session.isOpen()); |
882 QVERIFY(session2.isOpen()); |
|
883 QVERIFY(session.state() == QNetworkSession::Connected); |
938 QVERIFY(session.state() == QNetworkSession::Connected); |
884 QVERIFY(session2.state() == QNetworkSession::Connected); |
|
885 #if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) |
939 #if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) |
886 // On Symbian emulator, the support for data bearers is limited |
940 // On Symbian emulator, the support for data bearers is limited |
887 QVERIFY(session.interface().isValid()); |
941 QVERIFY(session.interface().isValid()); |
888 #endif |
942 #endif |
889 QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); |
943 if (errorSpy2.isEmpty()) { |
890 QCOMPARE(session.interface().index(), session2.interface().index()); |
944 QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); |
|
945 QCOMPARE(session.interface().index(), session2.interface().index()); |
|
946 } |
891 } |
947 } |
892 |
948 |
893 sessionOpenedSpy2.clear(); |
949 sessionOpenedSpy2.clear(); |
894 |
950 |
895 if (forceSessionStop) { |
951 if (forceSessionStop && session2.isOpen()) { |
896 // Test forcing the second session to stop the interface. |
952 // Test forcing the second session to stop the interface. |
897 QNetworkSession::State previousState = session.state(); |
953 QNetworkSession::State previousState = session.state(); |
898 #ifdef Q_CC_NOKIAX86 |
954 #ifdef Q_CC_NOKIAX86 |
899 // For S60 emulator builds: RConnection::Stop does not work on all Emulators |
955 // For S60 emulator builds: RConnection::Stop does not work on all Emulators |
900 bool expectStateChange = false; |
956 bool expectStateChange = false; |
901 #else |
957 #else |
902 bool expectStateChange = previousState != QNetworkSession::Disconnected; |
958 bool expectStateChange = previousState != QNetworkSession::Disconnected; |
903 #endif |
959 #endif |
904 |
|
905 session2.stop(); |
960 session2.stop(); |
906 |
961 |
|
962 // QNetworkSession::stop() must result either closed() signal |
|
963 // or error() signal |
907 QTRY_VERIFY(!sessionClosedSpy2.isEmpty() || !errorSpy2.isEmpty()); |
964 QTRY_VERIFY(!sessionClosedSpy2.isEmpty() || !errorSpy2.isEmpty()); |
908 |
|
909 QVERIFY(!session2.isOpen()); |
965 QVERIFY(!session2.isOpen()); |
910 |
966 |
911 if (!errorSpy2.isEmpty()) { |
967 if (!errorSpy2.isEmpty()) { |
912 QVERIFY(!errorSpy.isEmpty()); |
968 // QNetworkSession::stop() resulted error() signal for session2 |
|
969 // => also session should emit error() signal |
|
970 QTRY_VERIFY(!errorSpy.isEmpty()); |
913 |
971 |
914 // check for SessionAbortedError |
972 // check for SessionAbortedError |
915 QNetworkSession::SessionError error = |
973 QNetworkSession::SessionError error = |
916 qvariant_cast<QNetworkSession::SessionError>(errorSpy.first().at(0)); |
974 qvariant_cast<QNetworkSession::SessionError>(errorSpy.first().at(0)); |
917 QNetworkSession::SessionError error2 = |
975 QNetworkSession::SessionError error2 = |
973 QVERIFY(state == QNetworkSession::Closing); |
1034 QVERIFY(state == QNetworkSession::Closing); |
974 |
1035 |
975 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(3).at(0)); |
1036 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(3).at(0)); |
976 QVERIFY(state == QNetworkSession::Disconnected); |
1037 QVERIFY(state == QNetworkSession::Disconnected); |
977 |
1038 |
|
1039 |
|
1040 QTRY_VERIFY(session.state() == QNetworkSession::Roaming || |
|
1041 session.state() == QNetworkSession::Connected || |
|
1042 session.state() == QNetworkSession::Disconnected); |
|
1043 |
978 QTRY_VERIFY(stateChangedSpy.count() > 0); |
1044 QTRY_VERIFY(stateChangedSpy.count() > 0); |
979 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(0).at(0)); |
1045 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(stateChangedSpy.count() - 1).at(0)); |
|
1046 |
980 if (state == QNetworkSession::Roaming) { |
1047 if (state == QNetworkSession::Roaming) { |
981 QTRY_VERIFY(!errorSpy.isEmpty() || stateChangedSpy.count() > 1); |
1048 QTRY_VERIFY(session.state() == QNetworkSession::Connected); |
|
1049 QTRY_VERIFY(session2.state() == QNetworkSession::Connected); |
|
1050 roamedSuccessfully = true; |
|
1051 } else if (state == QNetworkSession::Disconnected) { |
|
1052 QTRY_VERIFY(!errorSpy.isEmpty()); |
|
1053 QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected); |
|
1054 } else if (state == QNetworkSession::Connected) { |
|
1055 QTRY_VERIFY(errorSpy.isEmpty()); |
982 if (stateChangedSpy.count() > 1) { |
1056 if (stateChangedSpy.count() > 1) { |
983 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(1).at(0)); |
1057 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(stateChangedSpy.count() - 2).at(0)); |
984 if (state == QNetworkSession::Connected) { |
1058 QVERIFY(state == QNetworkSession::Roaming); |
985 roamedSuccessfully = true; |
|
986 QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected); |
|
987 } |
|
988 } |
1059 } |
989 } |
1060 roamedSuccessfully = true; |
|
1061 } |
|
1062 |
990 if (roamedSuccessfully) { |
1063 if (roamedSuccessfully) { |
991 QString configId = session.sessionProperty("ActiveConfiguration").toString(); |
1064 QString configId = session.sessionProperty("ActiveConfiguration").toString(); |
992 QNetworkConfiguration config = manager.configurationFromIdentifier(configId); |
1065 QNetworkConfiguration config = manager.configurationFromIdentifier(configId); |
993 QNetworkSession session3(config); |
1066 QNetworkSession session3(config); |
994 QSignalSpy errorSpy3(&session3, SIGNAL(error(QNetworkSession::SessionError))); |
1067 QSignalSpy errorSpy3(&session3, SIGNAL(error(QNetworkSession::SessionError))); |
995 QSignalSpy sessionOpenedSpy3(&session3, SIGNAL(opened())); |
1068 QSignalSpy sessionOpenedSpy3(&session3, SIGNAL(opened())); |
996 |
|
997 session3.open(); |
1069 session3.open(); |
998 session3.waitForOpened(); |
1070 session3.waitForOpened(); |
999 |
|
1000 if (session.isOpen()) |
1071 if (session.isOpen()) |
1001 QVERIFY(!sessionOpenedSpy3.isEmpty() || !errorSpy3.isEmpty()); |
1072 QVERIFY(!sessionOpenedSpy3.isEmpty() || !errorSpy3.isEmpty()); |
1002 |
|
1003 session.stop(); |
1073 session.stop(); |
1004 |
|
1005 QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); |
1074 QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); |
1006 QTRY_VERIFY(session3.state() == QNetworkSession::Disconnected); |
|
1007 } |
1075 } |
1008 #ifndef Q_CC_NOKIAX86 |
1076 #ifndef Q_CC_NOKIAX86 |
1009 if (!roamedSuccessfully) |
1077 if (!roamedSuccessfully) |
1010 QVERIFY(!errorSpy.isEmpty()); |
1078 QVERIFY(!errorSpy.isEmpty()); |
1011 #endif |
1079 #endif |
1012 } else { |
1080 } else { |
1013 QCOMPARE(stateChangedSpy2.count(), 2); |
1081 QTest::qWait(2000); // Wait awhile to get all signals from platform |
1014 |
1082 |
1015 QNetworkSession::State state = |
1083 if (stateChangedSpy2.count() == 2) { |
1016 qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(0).at(0)); |
1084 QNetworkSession::State state = |
1017 QVERIFY(state == QNetworkSession::Closing); |
1085 qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(0).at(0)); |
1018 |
1086 QVERIFY(state == QNetworkSession::Closing); |
1019 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(1).at(0)); |
1087 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(1).at(0)); |
1020 QVERIFY(state == QNetworkSession::Disconnected); |
1088 QVERIFY(state == QNetworkSession::Disconnected); |
|
1089 } else { // Assume .count() == 1 |
|
1090 QCOMPARE(stateChangedSpy2.count(), 1); |
|
1091 QNetworkSession::State state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(0).at(0)); |
|
1092 // Symbian version dependant. |
|
1093 QVERIFY(state == QNetworkSession::Disconnected); |
|
1094 } |
1021 } |
1095 } |
1022 |
1096 |
1023 QTRY_VERIFY(!sessionClosedSpy.isEmpty()); |
1097 QTRY_VERIFY(!sessionClosedSpy.isEmpty()); |
1024 QVERIFY(session.state() == QNetworkSession::Disconnected); |
1098 QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); |
1025 QVERIFY(session2.state() == QNetworkSession::Disconnected); |
|
1026 } |
1099 } |
1027 |
1100 |
1028 QVERIFY(errorSpy2.isEmpty()); |
1101 QVERIFY(errorSpy2.isEmpty()); |
1029 |
1102 |
1030 ++inProcessSessionManagementCount; |
1103 ++inProcessSessionManagementCount; |
1136 |
1209 |
1137 // Note: outOfProcessSession requires that at least one configuration is |
1210 // Note: outOfProcessSession requires that at least one configuration is |
1138 // at Discovered -state. |
1211 // at Discovered -state. |
1139 void tst_QNetworkSession::outOfProcessSession() |
1212 void tst_QNetworkSession::outOfProcessSession() |
1140 { |
1213 { |
|
1214 if (!testsToRun["outOfProcessSession"]) { |
|
1215 QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll); |
|
1216 } |
1141 #if defined(Q_OS_SYMBIAN) && defined(__WINS__) |
1217 #if defined(Q_OS_SYMBIAN) && defined(__WINS__) |
1142 QSKIP("Symbian emulator does not support two [QR]PRocesses linking a dll (QtBearer.dll) with global writeable static data.", SkipAll); |
1218 QSKIP("Symbian emulator does not support two [QR]PRocesses linking a dll (QtBearer.dll) with global writeable static data.", SkipAll); |
1143 #endif |
1219 #endif |
|
1220 updateConfigurations(); |
|
1221 QTest::qWait(2000); |
|
1222 |
1144 QNetworkConfigurationManager manager; |
1223 QNetworkConfigurationManager manager; |
1145 // Create a QNetworkConfigurationManager to detect configuration changes made in Lackey. This |
1224 // Create a QNetworkConfigurationManager to detect configuration changes made in Lackey. This |
1146 // is actually the essence of this testcase - to check that platform mediates/reflects changes |
1225 // is actually the essence of this testcase - to check that platform mediates/reflects changes |
1147 // regardless of process boundaries. The interprocess communication is more like a way to get |
1226 // regardless of process boundaries. The interprocess communication is more like a way to get |
1148 // this test-case act correctly and timely. |
1227 // this test-case act correctly and timely. |
1239 QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfiguration::Type configType) { |
1319 QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfiguration::Type configType) { |
1240 |
1320 |
1241 // Refresh configurations and derive configurations matching given parameters. |
1321 // Refresh configurations and derive configurations matching given parameters. |
1242 QNetworkConfigurationManager mgr; |
1322 QNetworkConfigurationManager mgr; |
1243 QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted())); |
1323 QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted())); |
|
1324 |
1244 mgr.updateConfigurations(); |
1325 mgr.updateConfigurations(); |
1245 QTRY_NOOP(updateSpy.count() == 1); |
1326 QTRY_NOOP(updateSpy.count() == 1); |
1246 if (updateSpy.count() != 1) { |
1327 if (updateSpy.count() != 1) { |
1247 qDebug("tst_QNetworkSession::suitableConfiguration() failure: unable to update configurations"); |
1328 qDebug("tst_QNetworkSession::suitableConfiguration() failure: unable to update configurations"); |
1248 return QNetworkConfiguration(); |
1329 return QNetworkConfiguration(); |
1249 } |
1330 } |
1250 QList<QNetworkConfiguration> discoveredConfigs = mgr.allConfigurations(QNetworkConfiguration::Discovered); |
1331 QList<QNetworkConfiguration> discoveredConfigs = mgr.allConfigurations(QNetworkConfiguration::Discovered); |
1251 foreach(QNetworkConfiguration config, discoveredConfigs) { |
1332 foreach(QNetworkConfiguration config, discoveredConfigs) { |
1252 if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { |
1333 if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { |
1253 // qDebug() << "Dumping config because is active: " << config.name(); |
|
1254 discoveredConfigs.removeOne(config); |
1334 discoveredConfigs.removeOne(config); |
1255 } else if (config.type() != configType) { |
1335 } else if (config.type() != configType) { |
1256 // qDebug() << "Dumping config because type (IAP/SNAP) mismatches: " << config.name(); |
1336 // qDebug() << "Dumping config because type (IAP/SNAP) mismatches: " << config.name(); |
1257 discoveredConfigs.removeOne(config); |
1337 discoveredConfigs.removeOne(config); |
1258 } else if ((config.type() == QNetworkConfiguration::InternetAccessPoint) && |
1338 } else if ((config.type() == QNetworkConfiguration::InternetAccessPoint) && |
1285 QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted())); |
1365 QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted())); |
1286 mgr.updateConfigurations(); |
1366 mgr.updateConfigurations(); |
1287 QTRY_NOOP(updateSpy.count() == 1); |
1367 QTRY_NOOP(updateSpy.count() == 1); |
1288 } |
1368 } |
1289 |
1369 |
|
1370 // A convinience-function: updates and prints all available confiurations and their states |
|
1371 void printConfigurations() |
|
1372 { |
|
1373 QNetworkConfigurationManager manager; |
|
1374 QList<QNetworkConfiguration> allConfigs = |
|
1375 manager.allConfigurations(); |
|
1376 qDebug("tst_QNetworkSession::printConfigurations QNetworkConfigurationManager gives following configurations: "); |
|
1377 foreach(QNetworkConfiguration config, allConfigs) { |
|
1378 qDebug() << "Name of the configuration: " << config.name(); |
|
1379 qDebug() << "State of the configuration: " << config.state(); |
|
1380 } |
|
1381 } |
|
1382 |
1290 // A convinience function for test-cases: opens the given configuration and return |
1383 // A convinience function for test-cases: opens the given configuration and return |
1291 // true if it was done gracefully. |
1384 // true if it was done gracefully. |
1292 bool openSession(QNetworkSession *session) { |
1385 bool openSession(QNetworkSession *session) { |
|
1386 bool result = true; |
1293 QNetworkConfigurationManager mgr; |
1387 QNetworkConfigurationManager mgr; |
1294 QSignalSpy openedSpy(session, SIGNAL(opened())); |
1388 QSignalSpy openedSpy(session, SIGNAL(opened())); |
1295 QSignalSpy stateChangeSpy(session, SIGNAL(stateChanged(QNetworkSession::State))); |
1389 QSignalSpy stateChangeSpy(session, SIGNAL(stateChanged(QNetworkSession::State))); |
1296 QSignalSpy errorSpy(session, SIGNAL(error(QNetworkSession::SessionError))); |
1390 QSignalSpy errorSpy(session, SIGNAL(error(QNetworkSession::SessionError))); |
1297 QSignalSpy configChangeSpy(&mgr, SIGNAL(configurationChanged(QNetworkConfiguration))); |
1391 QSignalSpy configChangeSpy(&mgr, SIGNAL(configurationChanged(QNetworkConfiguration))); |
1298 // Store some initial statuses, because expected signals differ if the config is already |
1392 // Store some initial statuses, because expected signals differ if the config is already |
1299 // active by some other session |
1393 // active by some other session |
1300 QNetworkConfiguration::StateFlags configInitState = session->configuration().state(); |
1394 QNetworkConfiguration::StateFlags configInitState = session->configuration().state(); |
1301 QNetworkSession::State sessionInitState = session->state(); |
1395 QNetworkSession::State sessionInitState = session->state(); |
|
1396 qDebug() << "tst_QNetworkSession::openSession() name of the configuration to be opened: " << session->configuration().name(); |
|
1397 qDebug() << "tst_QNetworkSession::openSession() state of the configuration to be opened: " << session->configuration().state(); |
|
1398 qDebug() << "tst_QNetworkSession::openSession() state of the session to be opened: " << session->state(); |
1302 |
1399 |
1303 if (session->isOpen() || |
1400 if (session->isOpen() || |
1304 !session->sessionProperty("ActiveConfiguration").toString().isEmpty()) { |
1401 !session->sessionProperty("ActiveConfiguration").toString().isEmpty()) { |
1305 qDebug("tst_QNetworkSession::openSession() failure: session was already open / active."); |
1402 qDebug("tst_QNetworkSession::openSession() failure: session was already open / active."); |
1306 return false; |
1403 result = false; |
1307 } else { |
1404 } else { |
1308 session->open(); |
1405 session->open(); |
1309 session->waitForOpened(120000); // Bringing interfaces up and down may take time at platform |
1406 session->waitForOpened(120000); // Bringing interfaces up and down may take time at platform |
1310 } |
1407 } |
|
1408 QTest::qWait(5000); // Wait a moment to ensure all signals are propagated |
1311 // Check that connection opening went by the book. Add checks here if more strictness needed. |
1409 // Check that connection opening went by the book. Add checks here if more strictness needed. |
1312 if (!session->isOpen()) { |
1410 if (!session->isOpen()) { |
1313 qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::open() failed."); |
1411 qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::open() failed."); |
1314 return false; |
1412 result = false; |
1315 } |
1413 } |
1316 if (openedSpy.count() != 1) { |
1414 if (openedSpy.count() != 1) { |
1317 qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::opened() - signal not received."); |
1415 qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::opened() - signal not received."); |
1318 return false; |
1416 result = false; |
1319 } |
1417 } |
1320 if (!errorSpy.isEmpty()) { |
1418 if (!errorSpy.isEmpty()) { |
1321 qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::error() - signal was detected."); |
1419 qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::error() - signal was detected."); |
1322 return false; |
1420 result = false; |
1323 } |
1421 } |
1324 if (sessionInitState != QNetworkSession::Connected && |
1422 if (sessionInitState != QNetworkSession::Connected && |
1325 stateChangeSpy.isEmpty()) { |
1423 stateChangeSpy.isEmpty()) { |
1326 qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::stateChanged() - signals not detected."); |
1424 qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::stateChanged() - signals not detected."); |
1327 return false; |
1425 result = false; |
1328 } |
1426 } |
1329 if (configInitState != QNetworkConfiguration::Active && |
1427 if (configInitState != QNetworkConfiguration::Active && |
1330 configChangeSpy.isEmpty()) { |
1428 configChangeSpy.isEmpty()) { |
1331 qDebug("tst_QNetworkSession::openSession() failure: QNetworkConfigurationManager::configurationChanged() - signals not detected."); |
1429 qDebug("tst_QNetworkSession::openSession() failure: QNetworkConfigurationManager::configurationChanged() - signals not detected."); |
1332 return false; |
1430 result = false; |
1333 } |
1431 } |
1334 if (session->configuration().state() != QNetworkConfiguration::Active) { |
1432 if (session->configuration().state() != QNetworkConfiguration::Active) { |
1335 qDebug("tst_QNetworkSession::openSession() failure: session's configuration is not in 'Active' -state."); |
1433 qDebug("tst_QNetworkSession::openSession() failure: session's configuration is not in 'Active' -state."); |
1336 return false; |
1434 qDebug() << "tst_QNetworkSession::openSession() state is: " << session->configuration().state(); |
1337 } |
1435 result = false; |
1338 return true; |
1436 } |
|
1437 if (result == false) { |
|
1438 qDebug() << "tst_QNetworkSession::openSession() opening session failed."; |
|
1439 } else { |
|
1440 qDebug() << "tst_QNetworkSession::openSession() opening session succeeded."; |
|
1441 } |
|
1442 qDebug() << "tst_QNetworkSession::openSession() name of the configuration is: " << session->configuration().name(); |
|
1443 qDebug() << "tst_QNetworkSession::openSession() configuration state is: " << session->configuration().state(); |
|
1444 qDebug() << "tst_QNetworkSession::openSession() session state is: " << session->state(); |
|
1445 |
|
1446 return result; |
1339 } |
1447 } |
1340 |
1448 |
1341 // Helper function for closing opened session. Performs checks that |
1449 // Helper function for closing opened session. Performs checks that |
1342 // session is closed gradefully (e.g. signals). Function does not delete |
1450 // session is closed gradefully (e.g. signals). Function does not delete |
1343 // the session. The lastSessionOnConfiguration (true by default) is used to |
1451 // the session. The lastSessionOnConfiguration (true by default) is used to |
1357 QSignalSpy sessionClosedSpy(session, SIGNAL(closed())); |
1470 QSignalSpy sessionClosedSpy(session, SIGNAL(closed())); |
1358 QSignalSpy sessionStateChangedSpy(session, SIGNAL(stateChanged(QNetworkSession::State))); |
1471 QSignalSpy sessionStateChangedSpy(session, SIGNAL(stateChanged(QNetworkSession::State))); |
1359 QSignalSpy sessionErrorSpy(session, SIGNAL(error(QNetworkSession::SessionError))); |
1472 QSignalSpy sessionErrorSpy(session, SIGNAL(error(QNetworkSession::SessionError))); |
1360 QSignalSpy configChangeSpy(&mgr, SIGNAL(configurationChanged(QNetworkConfiguration))); |
1473 QSignalSpy configChangeSpy(&mgr, SIGNAL(configurationChanged(QNetworkConfiguration))); |
1361 |
1474 |
|
1475 bool result = true; |
1362 session->close(); |
1476 session->close(); |
|
1477 QTest::qWait(5000); // Wait a moment so that all signals are propagated |
1363 |
1478 |
1364 if (!sessionErrorSpy.isEmpty()) { |
1479 if (!sessionErrorSpy.isEmpty()) { |
1365 qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::error() received."); |
1480 qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::error() received."); |
1366 return false; |
1481 result = false; |
1367 } |
1482 } |
1368 if (sessionClosedSpy.count() != 1) { |
1483 if (sessionClosedSpy.count() != 1) { |
1369 qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::closed() signal not received."); |
1484 qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::closed() signal not received."); |
1370 return false; |
1485 result = false; |
1371 } |
1486 } |
1372 if (lastSessionOnConfiguration && |
1487 if (lastSessionOnConfiguration && |
1373 sessionStateChangedSpy.isEmpty()) { |
1488 sessionStateChangedSpy.isEmpty()) { |
1374 qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::stateChanged() signals not received."); |
1489 qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::stateChanged() signals not received."); |
1375 return false; |
1490 result = false; |
1376 } |
1491 } |
1377 if (lastSessionOnConfiguration && |
1492 if (lastSessionOnConfiguration && |
1378 session->state() != QNetworkSession::Disconnected) { |
1493 session->state() != QNetworkSession::Disconnected) { |
1379 qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession is not in Disconnected -state"); |
1494 qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession is not in Disconnected -state"); |
1380 return false; |
1495 result = false; |
1381 } |
1496 } |
1382 QTRY_NOOP(!configChangeSpy.isEmpty()); |
1497 QTRY_NOOP(!configChangeSpy.isEmpty()); |
1383 if (lastSessionOnConfiguration && |
1498 if (lastSessionOnConfiguration && |
1384 configChangeSpy.isEmpty()) { |
1499 configChangeSpy.isEmpty()) { |
1385 qDebug("tst_QNetworkSession::closeSession() failure: QNetworkConfigurationManager::configurationChanged() - signal not detected."); |
1500 qDebug("tst_QNetworkSession::closeSession() failure: QNetworkConfigurationManager::configurationChanged() - signal not detected."); |
1386 return false; |
1501 result = false; |
1387 } |
1502 } |
1388 if (lastSessionOnConfiguration && |
1503 if (lastSessionOnConfiguration && |
1389 session->configuration().state() == QNetworkConfiguration::Active) { |
1504 session->configuration().state() == QNetworkConfiguration::Active) { |
1390 qDebug("tst_QNetworkSession::closeSession() failure: session's configuration is still in active state."); |
1505 qDebug("tst_QNetworkSession::closeSession() failure: session's configuration is still in active state."); |
1391 return false; |
1506 result = false; |
1392 } |
1507 } |
1393 return true; |
1508 if (result == false) { |
|
1509 qDebug() << "tst_QNetworkSession::closeSession() closing session failed."; |
|
1510 } else { |
|
1511 qDebug() << "tst_QNetworkSession::closeSession() closing session succeeded."; |
|
1512 } |
|
1513 qDebug() << "tst_QNetworkSession::closeSession() name of the configuration is: " << session->configuration().name(); |
|
1514 qDebug() << "tst_QNetworkSession::closeSession() configuration state is: " << session->configuration().state(); |
|
1515 qDebug() << "tst_QNetworkSession::closeSession() session state is: " << session->state(); |
|
1516 return result; |
1394 } |
1517 } |
1395 |
1518 |
1396 QTEST_MAIN(tst_QNetworkSession) |
1519 QTEST_MAIN(tst_QNetworkSession) |
1397 |
1520 |
1398 #include "tst_qnetworksession.moc" |
1521 #include "tst_qnetworksession.moc" |