72 |
72 |
73 private slots: |
73 private slots: |
74 |
74 |
75 void robustnessBombing(); |
75 void robustnessBombing(); |
76 |
76 |
|
77 void sessionClosing_data(); |
|
78 void sessionClosing(); |
|
79 |
77 void outOfProcessSession(); |
80 void outOfProcessSession(); |
78 void invalidSession(); |
81 void invalidSession(); |
79 |
82 |
80 void repeatedOpenClose_data(); |
83 void repeatedOpenClose_data(); |
81 void repeatedOpenClose(); |
84 void repeatedOpenClose(); |
82 |
85 |
83 void roamingErrorCodes(); |
|
84 |
|
85 void sessionStop_data(); |
86 void sessionStop_data(); |
86 void sessionStop(); |
87 void sessionStop(); |
87 |
88 |
|
89 void roamingErrorCodes(); |
|
90 |
88 void sessionProperties_data(); |
91 void sessionProperties_data(); |
89 void sessionProperties(); |
92 void sessionProperties(); |
90 |
93 |
91 void userChoiceSession_data(); |
94 void userChoiceSession_data(); |
92 void userChoiceSession(); |
95 void userChoiceSession(); |
125 qRegisterMetaType<QNetworkConfiguration::Type>("QNetworkConfiguration::Type"); |
128 qRegisterMetaType<QNetworkConfiguration::Type>("QNetworkConfiguration::Type"); |
126 |
129 |
127 // If you wish to skip tests, set value as false. This is often very convinient because tests are so lengthy. |
130 // 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. |
131 // Better way still would be to make this readable from a file. |
129 testsToRun["robustnessBombing"] = true; |
132 testsToRun["robustnessBombing"] = true; |
|
133 testsToRun["sessionClosing"] = true; |
130 testsToRun["outOfProcessSession"] = true; |
134 testsToRun["outOfProcessSession"] = true; |
131 testsToRun["invalidSession"] = true; |
135 testsToRun["invalidSession"] = true; |
132 testsToRun["repeatedOpenClose"] = true; |
136 testsToRun["repeatedOpenClose"] = true; |
133 testsToRun["roamingErrorCodes"] = true; |
137 testsToRun["roamingErrorCodes"] = true; |
134 testsToRun["sessionStop"] = true; |
138 testsToRun["sessionStop"] = true; |
259 testSession.accept(); |
263 testSession.accept(); |
260 testSession.ignore(); |
264 testSession.ignore(); |
261 testSession.reject(); |
265 testSession.reject(); |
262 } |
266 } |
263 |
267 |
|
268 void tst_QNetworkSession::sessionClosing_data() { |
|
269 QTest::addColumn<QString>("bearerType"); |
|
270 QTest::addColumn<QNetworkConfiguration::Type>("configurationType"); |
|
271 |
|
272 QTest::newRow("WLAN_IAP") << "WLAN" << QNetworkConfiguration::InternetAccessPoint; |
|
273 QTest::newRow("Cellular_IAP") << "cellular" << QNetworkConfiguration::InternetAccessPoint; |
|
274 QTest::newRow("SNAP") << "bearer_type_not_relevant_with_SNAPs" << QNetworkConfiguration::ServiceNetwork; |
|
275 } |
|
276 |
|
277 // Testcase for closing the session at unexpected times |
|
278 void tst_QNetworkSession::sessionClosing() |
|
279 { |
|
280 if (!testsToRun["sessionClosing"]) { |
|
281 QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll); |
|
282 } |
|
283 QFETCH(QString, bearerType); |
|
284 QFETCH(QNetworkConfiguration::Type, configurationType); |
|
285 |
|
286 // Update configurations so that WLANs are discovered too. |
|
287 updateConfigurations(); |
|
288 |
|
289 // First check that opening once succeeds and determine if test is doable |
|
290 QNetworkConfiguration config = suitableConfiguration(bearerType, configurationType); |
|
291 if (!config.isValid()) { |
|
292 QSKIP("No suitable configurations, skipping this round of repeated open-close test.", SkipSingle); |
|
293 } |
|
294 qDebug() << "Using following configuration to bomb with close(): " << config.name(); |
|
295 QNetworkSession session(config); |
|
296 if (!openSession(&session) || |
|
297 !closeSession(&session)) { |
|
298 QSKIP("Unable to open/close session, skipping this round of close() bombing.", SkipSingle); |
|
299 } |
|
300 |
|
301 qDebug() << "Closing without issuing open()"; |
|
302 session.close(); |
|
303 |
|
304 for (int i = 0; i < 25; i++) { |
|
305 qDebug() << "Opening and then waiting: " << i * 100 << " ms before closing."; |
|
306 session.open(); |
|
307 QTest::qWait(i*100); |
|
308 session.close(); |
|
309 // Sooner or later session must end in Disconnected state, |
|
310 // no matter what the phase was. |
|
311 QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); |
|
312 QTest::qWait(200); // Give platform a breathe, otherwise we'll be catching other errors |
|
313 } |
|
314 } |
264 |
315 |
265 void tst_QNetworkSession::invalidSession() |
316 void tst_QNetworkSession::invalidSession() |
266 { |
317 { |
267 if (!testsToRun["invalidSession"]) { |
318 if (!testsToRun["invalidSession"]) { |
268 QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll); |
319 QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll); |
1042 session.state() == QNetworkSession::Disconnected); |
1093 session.state() == QNetworkSession::Disconnected); |
1043 |
1094 |
1044 QTRY_VERIFY(stateChangedSpy.count() > 0); |
1095 QTRY_VERIFY(stateChangedSpy.count() > 0); |
1045 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(stateChangedSpy.count() - 1).at(0)); |
1096 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(stateChangedSpy.count() - 1).at(0)); |
1046 |
1097 |
|
1098 for (int i = 0; i < stateChangedSpy.count(); i++) { |
|
1099 QNetworkSession::State state_temp = |
|
1100 qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(i).at(0)); |
|
1101 // Extra debug because a fragile point in testcase because statuses vary. |
|
1102 qDebug() << "------- Statechange spy at: " << i << " is " << state_temp; |
|
1103 } |
|
1104 |
1047 if (state == QNetworkSession::Roaming) { |
1105 if (state == QNetworkSession::Roaming) { |
1048 QTRY_VERIFY(session.state() == QNetworkSession::Connected); |
1106 QTRY_VERIFY(session.state() == QNetworkSession::Connected); |
1049 QTRY_VERIFY(session2.state() == QNetworkSession::Connected); |
1107 QTRY_VERIFY(session2.state() == QNetworkSession::Connected); |
|
1108 roamedSuccessfully = true; |
|
1109 } else if (state == QNetworkSession::Closing) { |
|
1110 QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected); |
|
1111 QTRY_VERIFY(session.state() == QNetworkSession::Connected); |
1050 roamedSuccessfully = true; |
1112 roamedSuccessfully = true; |
1051 } else if (state == QNetworkSession::Disconnected) { |
1113 } else if (state == QNetworkSession::Disconnected) { |
1052 QTRY_VERIFY(!errorSpy.isEmpty()); |
1114 QTRY_VERIFY(!errorSpy.isEmpty()); |
1053 QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected); |
1115 QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected); |
1054 } else if (state == QNetworkSession::Connected) { |
1116 } else if (state == QNetworkSession::Connected) { |
1055 QTRY_VERIFY(errorSpy.isEmpty()); |
1117 QTRY_VERIFY(errorSpy.isEmpty()); |
|
1118 |
1056 if (stateChangedSpy.count() > 1) { |
1119 if (stateChangedSpy.count() > 1) { |
1057 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(stateChangedSpy.count() - 2).at(0)); |
1120 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(stateChangedSpy.count() - 2).at(0)); |
1058 QVERIFY(state == QNetworkSession::Roaming); |
1121 QVERIFY(state == QNetworkSession::Roaming); |
1059 } |
1122 } |
1060 roamedSuccessfully = true; |
1123 roamedSuccessfully = true; |
1084 QNetworkSession::State state = |
1147 QNetworkSession::State state = |
1085 qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(0).at(0)); |
1148 qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(0).at(0)); |
1086 QVERIFY(state == QNetworkSession::Closing); |
1149 QVERIFY(state == QNetworkSession::Closing); |
1087 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(1).at(0)); |
1150 state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(1).at(0)); |
1088 QVERIFY(state == QNetworkSession::Disconnected); |
1151 QVERIFY(state == QNetworkSession::Disconnected); |
1089 } else { // Assume .count() == 1 |
1152 } else { |
1090 QCOMPARE(stateChangedSpy2.count(), 1); |
1153 QVERIFY(stateChangedSpy2.count() >= 1); |
1091 QNetworkSession::State state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(0).at(0)); |
1154 |
|
1155 for (int i = 0; i < stateChangedSpy2.count(); i++) { |
|
1156 QNetworkSession::State state_temp = |
|
1157 qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(i).at(0)); |
|
1158 // Extra debug because a fragile point in testcase. |
|
1159 qDebug() << "+++++ Statechange spy at: " << i << " is " << state_temp; |
|
1160 } |
|
1161 |
|
1162 QNetworkSession::State state = |
|
1163 qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(stateChangedSpy2.count() - 1).at(0)); |
1092 // Symbian version dependant. |
1164 // Symbian version dependant. |
1093 QVERIFY(state == QNetworkSession::Disconnected); |
1165 QVERIFY(state == QNetworkSession::Disconnected); |
1094 } |
1166 } |
1095 } |
1167 } |
1096 |
1168 |