diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-03-05 02:10:19 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-03-05 03:34:33 (GMT) |
commit | 92c624b6e26cf950ca651cee59be8ab53ada9a7d (patch) | |
tree | b79048d0af50b5b7304a8c66d0a439164ac2e2c9 /tests/auto | |
parent | 445ae84fbd7d5ef04a426f8c32a79a369fed70eb (diff) | |
download | Qt-92c624b6e26cf950ca651cee59be8ab53ada9a7d.zip Qt-92c624b6e26cf950ca651cee59be8ab53ada9a7d.tar.gz Qt-92c624b6e26cf950ca651cee59be8ab53ada9a7d.tar.bz2 |
Don't keep polling network sessions open indefinitely.
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qnetworksession/test/tst_qnetworksession.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp index 58b1a48..4b56f77 100644 --- a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp @@ -85,6 +85,9 @@ private slots: void sessionOpenCloseStop_data(); void sessionOpenCloseStop(); + void sessionAutoClose_data(); + void sessionAutoClose(); + private: QNetworkConfigurationManager manager; @@ -1202,7 +1205,67 @@ bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration) { return true; } +void tst_QNetworkSession::sessionAutoClose_data() +{ + QTest::addColumn<QNetworkConfiguration>("configuration"); + + bool testData = false; + foreach (const QNetworkConfiguration &config, + manager.allConfigurations(QNetworkConfiguration::Discovered)) { + QNetworkSession session(config); + if (!session.sessionProperty(QLatin1String("AutoCloseSessionTimeout")).isValid()) + continue; + + testData = true; + + const QString name = config.name().isEmpty() ? QString("<Hidden>") : config.name(); + QTest::newRow(name.toLocal8Bit().constData()) << config; + } + + if (!testData) + QSKIP("No applicable configurations to test", SkipAll); +} + +void tst_QNetworkSession::sessionAutoClose() +{ + QFETCH(QNetworkConfiguration, configuration); + + QNetworkSession session(configuration); + + QVERIFY(session.configuration() == configuration); + QVariant autoCloseSession = session.sessionProperty(QLatin1String("AutoCloseSessionTimeout")); + + QVERIFY(autoCloseSession.isValid()); + + // property defaults to false + QCOMPARE(autoCloseSession.toInt(), -1); + + QSignalSpy closeSpy(&session, SIGNAL(closed())); + + session.open(); + session.waitForOpened(); + + if (!session.isOpen()) + QSKIP("Session not open", SkipSingle); + + // set session to auto close at next polling interval. + session.setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), 0); + + QTRY_VERIFY(!closeSpy.isEmpty()); + + QCOMPARE(session.state(), QNetworkSession::Connected); + + QVERIFY(!session.isOpen()); + + QVERIFY(session.configuration() == configuration); + + autoCloseSession = session.sessionProperty(QLatin1String("AutoCloseSessionTimeout")); + + QVERIFY(autoCloseSession.isValid()); + + QCOMPARE(autoCloseSession.toInt(), -1); +} QTEST_MAIN(tst_QNetworkSession) |