summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-05-17 06:24:00 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-05-17 06:24:00 (GMT)
commit21b388616a0daf06d27d1e1d471e8423fff44f50 (patch)
tree080641177a6dab05b021bcc4e75e97fc6cc52e3d /tests
parent58c08b1195add26e2ff96844885ea9d6c124da30 (diff)
parentf60eeb5c165d5b9e5998edae7785cc893a613bca (diff)
downloadQt-21b388616a0daf06d27d1e1d471e8423fff44f50.zip
Qt-21b388616a0daf06d27d1e1d471e8423fff44f50.tar.gz
Qt-21b388616a0daf06d27d1e1d471e8423fff44f50.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/bic/tst_bic.cpp2
-rw-r--r--tests/auto/declarative/qdeclarativeitem/data/keyspriority.qml9
-rw-r--r--tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp131
-rw-r--r--tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp9
-rw-r--r--tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp27
-rw-r--r--tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp7
-rw-r--r--tests/auto/qnetworksession/lackey/main.cpp24
-rw-r--r--tests/auto/qnetworksession/test/tst_qnetworksession.cpp391
-rw-r--r--tests/auto/qtcpsocket/tst_qtcpsocket.cpp26
-rw-r--r--tests/manual/bearerex/bearerex.cpp18
10 files changed, 482 insertions, 162 deletions
diff --git a/tests/auto/bic/tst_bic.cpp b/tests/auto/bic/tst_bic.cpp
index 010965c..400fcc1 100644
--- a/tests/auto/bic/tst_bic.cpp
+++ b/tests/auto/bic/tst_bic.cpp
@@ -191,7 +191,7 @@ void tst_Bic::sizesAndVTables_data()
#elif defined Q_OS_MAC && defined(__i386__)
# define FILESUFFIX "macx-gcc-ia32"
#elif defined Q_OS_MAC && defined(__amd64__)
-# define FILESUFFIX "macx-gcc-amd64";
+# define FILESUFFIX "macx-gcc-amd64"
#elif defined Q_OS_WIN && defined Q_CC_GNU
# define FILESUFFIX "win32-gcc-ia32"
#else
diff --git a/tests/auto/declarative/qdeclarativeitem/data/keyspriority.qml b/tests/auto/declarative/qdeclarativeitem/data/keyspriority.qml
new file mode 100644
index 0000000..171536b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeitem/data/keyspriority.qml
@@ -0,0 +1,9 @@
+import Qt 4.7
+import Test 1.0
+
+KeyTestItem {
+ focus: true
+ Keys.onPressed: keysTestObject.keyPress(event.key, event.text, event.modifiers)
+ Keys.onReleased: { keysTestObject.keyRelease(event.key, event.text, event.modifiers); event.accepted = true; }
+ Keys.priority: keysTestObject.processLast ? Keys.AfterItem : Keys.BeforeItem
+}
diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
index f4edeb2..ecc813e 100644
--- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
+++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
@@ -55,7 +55,9 @@ public:
tst_QDeclarativeItem();
private slots:
+ void initTestCase();
void keys();
+ void keysProcessingOrder();
void keyNavigation();
void smooth();
void clip();
@@ -79,8 +81,11 @@ private:
class KeysTestObject : public QObject
{
Q_OBJECT
+
+ Q_PROPERTY(bool processLast READ processLast NOTIFY processLastChanged)
+
public:
- KeysTestObject() : mKey(0), mModifiers(0), mForwardedKey(0) {}
+ KeysTestObject() : mKey(0), mModifiers(0), mForwardedKey(0), mLast(false) {}
void reset() {
mKey = 0;
@@ -89,6 +94,14 @@ public:
mForwardedKey = 0;
}
+ bool processLast() const { return mLast; }
+ void setProcessLast(bool b) {
+ if (b != mLast) {
+ mLast = b;
+ emit processLastChanged();
+ }
+ }
+
public slots:
void keyPress(int key, QString text, int modifiers) {
mKey = key;
@@ -104,20 +117,73 @@ public slots:
mForwardedKey = key;
}
+signals:
+ void processLastChanged();
+
public:
int mKey;
QString mText;
int mModifiers;
int mForwardedKey;
+ bool mLast;
private:
};
+class KeyTestItem : public QDeclarativeItem
+{
+ Q_OBJECT
+public:
+ KeyTestItem(QDeclarativeItem *parent=0) : QDeclarativeItem(parent), mKey(0) {}
+
+protected:
+ void keyPressEvent(QKeyEvent *e) {
+ keyPressPreHandler(e);
+ if (e->isAccepted())
+ return;
+
+ mKey = e->key();
+
+ if (e->key() == Qt::Key_A)
+ e->accept();
+ else
+ e->ignore();
+
+ if (!e->isAccepted())
+ QDeclarativeItem::keyPressEvent(e);
+ }
+
+ void keyReleaseEvent(QKeyEvent *e) {
+ keyReleasePreHandler(e);
+
+ if (e->isAccepted())
+ return;
+
+ if (e->key() == Qt::Key_B)
+ e->accept();
+ else
+ e->ignore();
+
+ if (!e->isAccepted())
+ QDeclarativeItem::keyReleaseEvent(e);
+ }
+
+public:
+ int mKey;
+};
+
+QML_DECLARE_TYPE(KeyTestItem);
+
tst_QDeclarativeItem::tst_QDeclarativeItem()
{
}
+void tst_QDeclarativeItem::initTestCase()
+{
+ qmlRegisterType<KeyTestItem>("Test",1,0,"KeyTestItem");
+}
+
void tst_QDeclarativeItem::keys()
{
QDeclarativeView *canvas = new QDeclarativeView(0);
@@ -214,6 +280,69 @@ void tst_QDeclarativeItem::keys()
QCOMPARE(testObject->mKey, 0);
QVERIFY(!key.isAccepted());
+ canvas->rootContext()->setContextProperty("enableKeyHanding", QVariant(true));
+
+ key = QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, "", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QCOMPARE(testObject->mKey, int(Qt::Key_Return));
+ QVERIFY(key.isAccepted());
+
+ delete canvas;
+ delete testObject;
+}
+
+void tst_QDeclarativeItem::keysProcessingOrder()
+{
+ QDeclarativeView *canvas = new QDeclarativeView(0);
+ canvas->setFixedSize(240,320);
+
+ KeysTestObject *testObject = new KeysTestObject;
+ canvas->rootContext()->setContextProperty("keysTestObject", testObject);
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/keyspriority.qml"));
+ canvas->show();
+ qApp->processEvents();
+
+ KeyTestItem *testItem = qobject_cast<KeyTestItem*>(canvas->rootObject());
+ QVERIFY(testItem);
+
+ QEvent wa(QEvent::WindowActivate);
+ QApplication::sendEvent(canvas, &wa);
+ QFocusEvent fe(QEvent::FocusIn);
+ QApplication::sendEvent(canvas, &fe);
+
+ QKeyEvent key(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier, "A", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QCOMPARE(testObject->mKey, int(Qt::Key_A));
+ QCOMPARE(testObject->mText, QLatin1String("A"));
+ QVERIFY(testObject->mModifiers == Qt::NoModifier);
+ QVERIFY(key.isAccepted());
+
+ testObject->reset();
+
+ testObject->setProcessLast(true);
+
+ key = QKeyEvent(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier, "A", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QCOMPARE(testObject->mKey, 0);
+ QVERIFY(key.isAccepted());
+
+ testObject->reset();
+
+ key = QKeyEvent(QEvent::KeyPress, Qt::Key_B, Qt::NoModifier, "B", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QCOMPARE(testObject->mKey, int(Qt::Key_B));
+ QCOMPARE(testObject->mText, QLatin1String("B"));
+ QVERIFY(testObject->mModifiers == Qt::NoModifier);
+ QVERIFY(!key.isAccepted());
+
+ testObject->reset();
+
+ key = QKeyEvent(QEvent::KeyRelease, Qt::Key_B, Qt::NoModifier, "B", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QCOMPARE(testObject->mKey, 0);
+ QVERIFY(key.isAccepted());
+
delete canvas;
delete testObject;
}
diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
index b56ff13..59580ea 100644
--- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
+++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
@@ -104,13 +104,14 @@ tst_QDeclarativeLoader::tst_QDeclarativeLoader()
void tst_QDeclarativeLoader::url()
{
QDeclarativeComponent component(&engine);
- component.setData(QByteArray("import Qt 4.7\nLoader { source: \"Rect120x60.qml\" }"), TEST_FILE(""));
+ component.setData(QByteArray("import Qt 4.7\nLoader { property int did_load: 0; onLoaded: did_load=123; source: \"Rect120x60.qml\" }"), TEST_FILE(""));
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
QVERIFY(loader != 0);
QVERIFY(loader->item());
QVERIFY(loader->source() == QUrl::fromLocalFile(SRCDIR "/data/Rect120x60.qml"));
QCOMPARE(loader->progress(), 1.0);
QCOMPARE(loader->status(), QDeclarativeLoader::Ready);
+ QCOMPARE(loader->property("did_load").toInt(), 123);
QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
delete loader;
@@ -427,7 +428,7 @@ void tst_QDeclarativeLoader::networkRequestUrl()
server.serveDirectory(SRCDIR "/data");
QDeclarativeComponent component(&engine);
- component.setData(QByteArray("import Qt 4.7\nLoader { source: \"http://127.0.0.1:14450/Rect120x60.qml\" }"), QUrl::fromLocalFile(SRCDIR "/dummy.qml"));
+ component.setData(QByteArray("import Qt 4.7\nLoader { property int did_load : 0; source: \"http://127.0.0.1:14450/Rect120x60.qml\"; onLoaded: did_load=123 }"), QUrl::fromLocalFile(SRCDIR "/dummy.qml"));
if (component.isError())
qDebug() << component.errors();
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
@@ -437,6 +438,7 @@ void tst_QDeclarativeLoader::networkRequestUrl()
QVERIFY(loader->item());
QCOMPARE(loader->progress(), 1.0);
+ QCOMPARE(loader->property("did_load").toInt(), 123);
QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
delete loader;
@@ -483,7 +485,7 @@ void tst_QDeclarativeLoader::failNetworkRequest()
QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Network error for URL http://127.0.0.1:14450/IDontExist.qml");
QDeclarativeComponent component(&engine);
- component.setData(QByteArray("import Qt 4.7\nLoader { source: \"http://127.0.0.1:14450/IDontExist.qml\" }"), QUrl::fromLocalFile("http://127.0.0.1:14450/dummy.qml"));
+ component.setData(QByteArray("import Qt 4.7\nLoader { property int did_load: 123; source: \"http://127.0.0.1:14450/IDontExist.qml\"; onLoaded: did_load=456 }"), QUrl::fromLocalFile("http://127.0.0.1:14450/dummy.qml"));
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
QVERIFY(loader != 0);
@@ -491,6 +493,7 @@ void tst_QDeclarativeLoader::failNetworkRequest()
QVERIFY(loader->item() == 0);
QCOMPARE(loader->progress(), 0.0);
+ QCOMPARE(loader->property("did_load").toInt(), 123);
QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0);
delete loader;
diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp
index 7a23773..e639014 100644
--- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp
+++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp
@@ -687,7 +687,13 @@ void tst_QDeclarativePositioners::test_conflictinganchors()
component.setData("import Qt 4.7\nColumn { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
item = qobject_cast<QDeclarativeItem*>(component.create());
QVERIFY(item);
- QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom or verticalCenter anchors for items inside Column"));
+ QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
+ warningMessage.clear();
+
+ component.setData("import Qt 4.7\nColumn { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
+ item = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(item);
+ QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
warningMessage.clear();
component.setData("import Qt 4.7\nColumn { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
@@ -699,7 +705,13 @@ void tst_QDeclarativePositioners::test_conflictinganchors()
component.setData("import Qt 4.7\nRow { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
item = qobject_cast<QDeclarativeItem*>(component.create());
QVERIFY(item);
- QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right or horizontalCenter anchors for items inside Row"));
+ QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
+ warningMessage.clear();
+
+ component.setData("import Qt 4.7\nRow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
+ item = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(item);
+ QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
warningMessage.clear();
component.setData("import Qt 4.7\nRow { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
@@ -714,10 +726,21 @@ void tst_QDeclarativePositioners::test_conflictinganchors()
QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
warningMessage.clear();
+ component.setData("import Qt 4.7\nGrid { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
+ item = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(item);
+ QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
+ warningMessage.clear();
+
component.setData("import Qt 4.7\nFlow { Item { anchors.verticalCenter: parent.verticalCenter } }", QUrl::fromLocalFile(""));
item = qobject_cast<QDeclarativeItem*>(component.create());
QVERIFY(item);
QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
+
+ component.setData("import Qt 4.7\nFlow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
+ item = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(item);
+ QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
}
QDeclarativeView *tst_QDeclarativePositioners::createView(const QString &filename)
diff --git a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp
index ce3acb7..a3cccb2 100644
--- a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp
+++ b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp
@@ -45,6 +45,13 @@
#include <QtNetwork/qnetworkconfiguration.h>
#include <QtNetwork/qnetworkconfigmanager.h>
+/*
+ Although this unit test doesn't use QNetworkAccessManager
+ this include is used to ensure that bearer continues to compile against
+ Qt 4.7+ which has a QNetworkConfiguration enabled QNetworkAccessManager
+*/
+#include <QNetworkAccessManager>
+
#if defined(Q_WS_MAEMO_6) || defined(Q_WS_MAEMO_5)
#include <stdio.h>
#include <iapconf.h>
diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp
index 8759b52..ec2fad9 100644
--- a/tests/auto/qnetworksession/lackey/main.cpp
+++ b/tests/auto/qnetworksession/lackey/main.cpp
@@ -47,6 +47,8 @@
#include <QtNetwork/qnetworkconfigmanager.h>
#include <QtNetwork/qnetworksession.h>
+#include <QEventLoop>
+#include <QTimer>
#include <QDebug>
QT_USE_NAMESPACE
@@ -60,15 +62,14 @@ int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
- // Cannot read/write to processes on WinCE or Symbian.
- // Easiest alternative is to use sockets for IPC.
-
- QLocalSocket oopSocket;
-
- oopSocket.connectToServer("tst_qnetworksession");
- oopSocket.waitForConnected(-1);
-
+ // Update configurations so that everything is up to date for this process too.
+ // Event loop is used to wait for awhile.
QNetworkConfigurationManager manager;
+ manager.updateConfigurations();
+ QEventLoop iIgnoreEventLoop;
+ QTimer::singleShot(3000, &iIgnoreEventLoop, SLOT(quit()));
+ iIgnoreEventLoop.exec();
+
QList<QNetworkConfiguration> discovered =
manager.allConfigurations(QNetworkConfiguration::Discovered);
@@ -82,6 +83,13 @@ int main(int argc, char** argv)
return NO_DISCOVERED_CONFIGURATIONS_ERROR;
}
+ // Cannot read/write to processes on WinCE or Symbian.
+ // Easiest alternative is to use sockets for IPC.
+ QLocalSocket oopSocket;
+
+ oopSocket.connectToServer("tst_qnetworksession");
+ oopSocket.waitForConnected(-1);
+
qDebug() << "Lackey started";
QNetworkSession *session = 0;
diff --git a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
index 23cdc6a..934a50e 100644
--- a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
+++ b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
@@ -100,6 +100,7 @@ private slots:
private:
QNetworkConfigurationManager manager;
+ QMap<QString, bool> testsToRun;
int inProcessSessionManagementCount;
@@ -117,6 +118,7 @@ private:
bool openSession(QNetworkSession *session);
bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration = true);
void updateConfigurations();
+void printConfigurations();
QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfiguration::Type configType);
void tst_QNetworkSession::initTestCase()
@@ -125,7 +127,19 @@ void tst_QNetworkSession::initTestCase()
qRegisterMetaType<QNetworkSession::SessionError>("QNetworkSession::SessionError");
qRegisterMetaType<QNetworkConfiguration>("QNetworkConfiguration");
qRegisterMetaType<QNetworkConfiguration::Type>("QNetworkConfiguration::Type");
-
+
+ // If you wish to skip tests, set value as false. This is often very convinient because tests are so lengthy.
+ // Better way still would be to make this readable from a file.
+ testsToRun["robustnessBombing"] = true;
+ testsToRun["outOfProcessSession"] = true;
+ testsToRun["invalidSession"] = true;
+ testsToRun["repeatedOpenClose"] = true;
+ testsToRun["roamingErrorCodes"] = true;
+ testsToRun["sessionStop"] = true;
+ testsToRun["sessionProperties"] = true;
+ testsToRun["userChoiceSession"] = true;
+ testsToRun["sessionOpenCloseStop"] = true;
+
#if defined(Q_WS_MAEMO_6) || defined(Q_WS_MAEMO_5)
iapconf = new Maemo::IAPConf("007");
iapconf->setValue("ipv4_type", "AUTO");
@@ -238,6 +252,10 @@ void tst_QNetworkSession::cleanupTestCase()
// Robustness test for calling interfaces in nonsense order / with nonsense parameters
void tst_QNetworkSession::robustnessBombing()
{
+ if (!testsToRun["robustnessBombing"]) {
+ QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll);
+ }
+
QNetworkConfigurationManager mgr;
QNetworkSession testSession(mgr.defaultConfiguration());
// Should not reset even session is not opened
@@ -245,15 +263,14 @@ void tst_QNetworkSession::robustnessBombing()
testSession.accept();
testSession.ignore();
testSession.reject();
- quint64 temp;
- temp = testSession.bytesWritten();
- temp = testSession.bytesReceived();
- temp = testSession.activeTime();
}
void tst_QNetworkSession::invalidSession()
-{
+{
+ if (!testsToRun["invalidSession"]) {
+ QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll);
+ }
// 1. Verify that session created with invalid configuration remains in invalid state
QNetworkSession session(QNetworkConfiguration(), 0);
QVERIFY(!session.isOpen());
@@ -270,11 +287,24 @@ void tst_QNetworkSession::invalidSession()
QVERIFY(error == QNetworkSession::InvalidConfigurationError);
QVERIFY(session.error() == QNetworkSession::InvalidConfigurationError);
QVERIFY(session.state() == QNetworkSession::Invalid);
-
+
#ifdef QNETWORKSESSION_MANUAL_TESTS
+
+ QNetworkConfiguration invalidatedConfig = suitableConfiguration("WLAN",QNetworkConfiguration::InternetAccessPoint);
+ if (invalidatedConfig.isValid()) {
+ // 3. Verify that invalidating a session after its successfully configured works
+ QNetworkSession invalidatedSession(invalidatedConfig);
+ qDebug() << "Delete the WLAN IAP from phone now (waiting 60 seconds): " << invalidatedConfig.name();
+ QTest::qWait(60000);
+ QVERIFY(!invalidatedConfig.isValid());
+ QVERIFY(invalidatedSession.state() == QNetworkSession::Invalid);
+ qDebug() << "Add the WLAN IAP back (waiting 60 seconds): " << invalidatedConfig.name();
+ QTest::qWait(60000);
+ }
+
QNetworkConfiguration definedConfig = suitableConfiguration("WLAN",QNetworkConfiguration::InternetAccessPoint);
if (definedConfig.isValid()) {
- // 3. Verify that opening a session with defined configuration emits error and enters notavailable-state
+ // 4. Verify that opening a session with defined configuration emits error and enters notavailable-state
// TODO these timer waits should be changed to waiting appropriate signals, now these wait excessively
qDebug() << "Shutdown WLAN IAP (waiting 60 seconds): " << definedConfig.name();
QTest::qWait(60000);
@@ -283,43 +313,27 @@ void tst_QNetworkSession::invalidSession()
QNetworkSession definedSession(definedConfig);
QSignalSpy errorSpy(&definedSession, SIGNAL(error(QNetworkSession::SessionError)));
QNetworkSession::SessionError sessionError;
+ updateConfigurations();
definedSession.open();
+#ifdef Q_OS_SYMBIAN
+ // On symbian, the connection opening is tried even with defined state.
+ qDebug("Waiting for 10 seconds to all signals to propagate.");
+ QTest::qWait(10000);
+#endif
+ updateConfigurations();
QVERIFY(definedConfig.isValid()); // Session remains valid
QVERIFY(definedSession.state() == QNetworkSession::NotAvailable); // State is not available because WLAN is not in coverage
QVERIFY(!errorSpy.isEmpty()); // Session tells with error about invalidated configuration
sessionError = qvariant_cast<QNetworkSession::SessionError> (errorSpy.first().at(0));
- qDebug() << "Error code is: " << sessionError;
QVERIFY(sessionError == QNetworkSession::InvalidConfigurationError);
-
qDebug() << "Turn the WLAN IAP back on (waiting 60 seconds): " << definedConfig.name();
QTest::qWait(60000);
- updateConfigurations();
-
+ updateConfigurations();
QVERIFY(definedConfig.state() == QNetworkConfiguration::Discovered);
}
-
- QNetworkConfiguration invalidatedConfig = suitableConfiguration("WLAN",QNetworkConfiguration::InternetAccessPoint);
- if (invalidatedConfig.isValid()) {
- // 4. Verify that invalidating a session after its successfully configured works
- QNetworkSession invalidatedSession(invalidatedConfig);
- QSignalSpy errorSpy(&invalidatedSession, SIGNAL(error(QNetworkSession::SessionError)));
- QNetworkSession::SessionError sessionError;
-
- qDebug() << "Delete the WLAN IAP from phone now (waiting 60 seconds): " << invalidatedConfig.name();
- QTest::qWait(60000);
-
- invalidatedSession.open();
- QVERIFY(!invalidatedConfig.isValid());
- QVERIFY(invalidatedSession.state() == QNetworkSession::Invalid);
- QVERIFY(!errorSpy.isEmpty());
-
- sessionError = qvariant_cast<QNetworkSession::SessionError> (errorSpy.first().at(0));
- QVERIFY(sessionError == QNetworkSession::InvalidConfigurationError);
- qDebug() << "Add the WLAN IAP back (waiting 60 seconds): " << invalidatedConfig.name();
- QTest::qWait(60000);
- }
+
#endif
}
@@ -337,12 +351,12 @@ void tst_QNetworkSession::sessionProperties_data()
void tst_QNetworkSession::sessionProperties()
{
+ if (!testsToRun["sessionProperties"]) {
+ QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll);
+ }
QFETCH(QNetworkConfiguration, configuration);
-
QNetworkSession session(configuration);
-
QVERIFY(session.configuration() == configuration);
-
QStringList validBearerNames = QStringList() << QLatin1String("Unknown")
<< QLatin1String("Ethernet")
<< QLatin1String("WLAN")
@@ -356,9 +370,6 @@ void tst_QNetworkSession::sessionProperties()
if (!configuration.isValid()) {
QVERIFY(configuration.bearerName().isEmpty());
} else {
- qDebug() << "Type:" << configuration.type()
- << "Bearer:" << configuration.bearerName();
-
switch (configuration.type())
{
case QNetworkConfiguration::ServiceNetwork:
@@ -374,9 +385,7 @@ void tst_QNetworkSession::sessionProperties()
// QNetworkSession::interface() should return an invalid interface unless
// session is in the connected state.
- qDebug() << "Session state:" << session.state();
#ifndef QT_NO_NETWORKINTERFACE
- qDebug() << "Session iface:" << session.interface().isValid() << session.interface().name();
#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__))
// On Symbian emulator, the support for data bearers is limited
QCOMPARE(session.state() == QNetworkSession::Connected, session.interface().isValid());
@@ -420,7 +429,12 @@ void tst_QNetworkSession::repeatedOpenClose_data() {
}
// Tests repeated-open close.
-void tst_QNetworkSession::repeatedOpenClose() {
+void tst_QNetworkSession::repeatedOpenClose()
+{
+ if (!testsToRun["repeatedOpenClose"]) {
+ QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll);
+ }
+
QFETCH(QString, bearerType);
QFETCH(QNetworkConfiguration::Type, configurationType);
QFETCH(int, repeatTimes);
@@ -436,13 +450,20 @@ void tst_QNetworkSession::repeatedOpenClose() {
!closeSession(&permanentSession)) {
QSKIP("Unable to open/close session, skipping this round of repeated open-close test.", SkipSingle);
}
- for (int i = repeatTimes; i > 0; i--) {
+ for (int i = 0; i < repeatTimes; i++) {
+ qDebug() << "Opening, loop number " << i;
QVERIFY(openSession(&permanentSession));
+ qDebug() << "Closing, loop number, then waiting 5 seconds: " << i;
QVERIFY(closeSession(&permanentSession));
+ QTest::qWait(5000);
}
}
-void tst_QNetworkSession::roamingErrorCodes() {
+void tst_QNetworkSession::roamingErrorCodes()
+{
+ if (!testsToRun["roamingErrorCodes"]) {
+ QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll);
+ }
#ifndef Q_OS_SYMBIAN
QSKIP("Roaming supported on Symbian.", SkipAll);
#else
@@ -466,41 +487,11 @@ void tst_QNetworkSession::roamingErrorCodes() {
adminIapSession.stop(); // requires NetworkControl capabilities
QTRY_VERIFY(!errorSpy.isEmpty()); // wait for error signals
QNetworkSession::SessionError error = qvariant_cast<QNetworkSession::SessionError>(errorSpy.first().at(0));
+ QTest::qWait(2000); // Wait for a moment to all platform signals to propagate
QVERIFY(error == QNetworkSession::SessionAbortedError);
QVERIFY(iapSession.state() == QNetworkSession::Disconnected);
QVERIFY(adminIapSession.state() == QNetworkSession::Disconnected);
#endif // Q_OS_SYMBIAN
-
-#ifdef QNETWORKSESSION_MANUAL_TESTS
- // Check for roaming error.
- // Case requires that you have controllable WLAN in Internet SNAP (only).
- QNetworkConfiguration snapConfig = suitableConfiguration("bearer_not_relevant_with_snaps", QNetworkConfiguration::ServiceNetwork);
- if (!snapConfig.isValid()) {
- QSKIP("No SNAP accessible, skipping test.", SkipAll);
- }
- QNetworkSession snapSession(snapConfig);
- QVERIFY(openSession(&snapSession));
- QSignalSpy errorSpySnap(&snapSession, SIGNAL(error(QNetworkSession::SessionError)));
- qDebug("Disconnect the WLAN now");
- QTRY_VERIFY(!errorSpySnap.isEmpty()); // wait for error signals
- QVERIFY(errorSpySnap.count() == 1);
- error = qvariant_cast<QNetworkSession::SessionError>(errorSpySnap.first().at(0));
- qDebug() << "Error received when turning off wlan on SNAP: " << error;
- QVERIFY(error == QNetworkSession::RoamingError);
-
- qDebug("Connect the WLAN now");
- QTest::qWait(60000); // Wait for WLAN to get up
- QNetworkConfiguration wlanIapConfig2 = suitableConfiguration("WLAN", QNetworkConfiguration::InternetAccessPoint);
- QNetworkSession iapSession2(wlanIapConfig2);
- QVERIFY(openSession(&iapSession2));
- QSignalSpy errorSpy2(&iapSession2, SIGNAL(error(QNetworkSession::SessionError)));
- qDebug("Disconnect the WLAN now");
- QTRY_VERIFY(!errorSpy2.isEmpty()); // wait for error signals
- QVERIFY(errorSpy2.count() == 1);
- error = qvariant_cast<QNetworkSession::SessionError>(errorSpy2.first().at(0));
- QVERIFY(error == QNetworkSession::SessionAbortedError);
- QVERIFY(iapSession2.state() == QNetworkSession::Disconnected);
-#endif
}
@@ -515,6 +506,9 @@ void tst_QNetworkSession::sessionStop_data() {
void tst_QNetworkSession::sessionStop()
{
+ if (!testsToRun["sessionStop"]) {
+ QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll);
+ }
#ifndef Q_OS_SYMBIAN
QSKIP("Testcase contains mainly Symbian specific checks, because it is only platform to really support interface (IAP-level) Stop.", SkipAll);
#endif
@@ -522,6 +516,9 @@ void tst_QNetworkSession::sessionStop()
QFETCH(QNetworkConfiguration::Type, configurationType);
int configWaitdelayInMs = 2000;
+
+ updateConfigurations();
+ printConfigurations();
QNetworkConfiguration config = suitableConfiguration(bearerType, configurationType);
if (!config.isValid()) {
@@ -539,6 +536,9 @@ void tst_QNetworkSession::sessionStop()
QSignalSpy closedSessionStateChangedSpy(&closedSession, SIGNAL(stateChanged(QNetworkSession::State)));
QSignalSpy closedErrorSpy(&closedSession, SIGNAL(error(QNetworkSession::SessionError)));
+ QSignalSpy openedSessionClosedSpy(&openedSession, SIGNAL(closed()));
+ QSignalSpy openedSessionStateChangedSpy(&openedSession, SIGNAL(stateChanged(QNetworkSession::State)));
+
QSignalSpy innocentSessionClosedSpy(&innocentSession, SIGNAL(closed()));
QSignalSpy innocentSessionStateChangedSpy(&innocentSession, SIGNAL(stateChanged(QNetworkSession::State)));
QSignalSpy innocentErrorSpy(&innocentSession, SIGNAL(error(QNetworkSession::SessionError)));
@@ -554,10 +554,18 @@ void tst_QNetworkSession::sessionStop()
closedSessionClosedSpy.clear();
closedSessionStateChangedSpy.clear();
closedErrorSpy.clear();
+ openedSessionStateChangedSpy.clear();
+ openedSessionClosedSpy.clear();
+
openedSession.stop();
- QVERIFY(openedSession.state() == QNetworkSession::Disconnected);
+ qDebug("Waiting for %d ms to get all configurationChange signals from platform.", configWaitdelayInMs);
QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals
+
+ // First to closing, then to disconnected
+ QVERIFY(openedSessionStateChangedSpy.count() == 2);
+ QVERIFY(!openedSessionClosedSpy.isEmpty());
+ QVERIFY(openedSession.state() == QNetworkSession::Disconnected);
QVERIFY(config.state() != QNetworkConfiguration::Active);
// 2. Verify that stopping a session based on non-connected configuration does nothing
@@ -583,18 +591,20 @@ void tst_QNetworkSession::sessionStop()
// 3. Check that stopping a opened session affects also other opened session based on the same configuration.
if (config.type() == QNetworkConfiguration::InternetAccessPoint) {
qDebug("----------3. Check that stopping a opened session affects also other opened session based on the same configuration.");
+
QVERIFY(openSession(&openedSession));
QVERIFY(openSession(&innocentSession));
-
+
configChangeSpy.clear();
innocentSessionClosedSpy.clear();
innocentSessionStateChangedSpy.clear();
innocentErrorSpy.clear();
-
+
openedSession.stop();
qDebug("Waiting for %d ms to get all configurationChange signals from platform.", configWaitdelayInMs);
QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals
-
+ QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals
+
QVERIFY(!innocentSessionClosedSpy.isEmpty());
QVERIFY(!innocentSessionStateChangedSpy.isEmpty());
QVERIFY(!innocentErrorSpy.isEmpty());
@@ -614,14 +624,19 @@ void tst_QNetworkSession::sessionStop()
if (config.type() == QNetworkConfiguration::ServiceNetwork) {
qDebug("----------4. Skip for SNAP configuration.");
} else if (config.type() == QNetworkConfiguration::InternetAccessPoint) {
- qDebug("----------4. Check that stopping a non-opened session stops the other session based on the same configuration");
- QVERIFY(openSession(&innocentSession));
+ qDebug("----------4. Check that stopping a non-opened session stops the other session based on the same configuration");
+ qDebug("----------4.1 Opening innocent session");
+ QVERIFY(openSession(&innocentSession));
qDebug("Waiting for %d ms after open to make sure all platform indications are propagated", configWaitdelayInMs);
QTest::qWait(configWaitdelayInMs);
+ qDebug("----------4.2 Calling closedSession.stop()");
closedSession.stop();
qDebug("Waiting for %d ms to get all configurationChange signals from platform..", configWaitdelayInMs);
QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals
+ QTest::qWait(configWaitdelayInMs);
+ QTest::qWait(configWaitdelayInMs);
+
QVERIFY(!innocentSessionClosedSpy.isEmpty());
QVERIFY(!innocentSessionStateChangedSpy.isEmpty());
QVERIFY(!innocentErrorSpy.isEmpty());
@@ -653,6 +668,9 @@ void tst_QNetworkSession::userChoiceSession_data()
void tst_QNetworkSession::userChoiceSession()
{
+ if (!testsToRun["userChoiceSession"]) {
+ QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll);
+ }
QFETCH(QNetworkConfiguration, configuration);
QVERIFY(configuration.type() == QNetworkConfiguration::UserChoice);
@@ -682,7 +700,20 @@ void tst_QNetworkSession::userChoiceSession()
session.open();
+#if defined(Q_OS_SYMBIAN)
+ // Opening & closing multiple connections in a row sometimes
+ // results hanging of connection opening on Symbian devices
+ // => If first open fails, wait a moment and try again.
+ if (!session.waitForOpened()) {
+ qDebug("**** Session open Timeout - Wait 5 seconds and try once again ****");
+ session.close();
+ QTest::qWait(5000); // Wait a while before trying to open session again
+ session.open();
+ session.waitForOpened();
+ }
+#else
session.waitForOpened();
+#endif
if (session.isOpen())
QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty());
@@ -786,6 +817,9 @@ void tst_QNetworkSession::sessionOpenCloseStop_data()
void tst_QNetworkSession::sessionOpenCloseStop()
{
+ if (!testsToRun["sessionOpenCloseStop"]) {
+ QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll);
+ }
QFETCH(QNetworkConfiguration, configuration);
QFETCH(bool, forceSessionStop);
@@ -818,7 +852,20 @@ void tst_QNetworkSession::sessionOpenCloseStop()
session.open();
+#if defined(Q_OS_SYMBIAN)
+ // Opening & closing multiple connections in a row sometimes
+ // results hanging of connection opening on Symbian devices
+ // => If first open fails, wait a moment and try again.
+ if (!session.waitForOpened()) {
+ qDebug("**** Session open Timeout - Wait 5 seconds and try once again ****");
+ session.close();
+ QTest::qWait(5000); // Wait a while before trying to open session again
+ session.open();
+ session.waitForOpened();
+ }
+#else
session.waitForOpened();
+#endif
if (session.isOpen())
QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty());
@@ -894,26 +941,30 @@ void tst_QNetworkSession::sessionOpenCloseStop()
QVERIFY(session.error() == QNetworkSession::UnknownSessionError);
session2.open();
-
+
QTRY_VERIFY(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty());
+ if (errorSpy2.isEmpty()) {
+ QVERIFY(session2.isOpen());
+ QVERIFY(session2.state() == QNetworkSession::Connected);
+ }
QVERIFY(session.isOpen());
- QVERIFY(session2.isOpen());
QVERIFY(session.state() == QNetworkSession::Connected);
- QVERIFY(session2.state() == QNetworkSession::Connected);
#ifndef QT_NO_NETWORKINTERFACE
#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__))
// On Symbian emulator, the support for data bearers is limited
QVERIFY(session.interface().isValid());
#endif
- QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress());
- QCOMPARE(session.interface().index(), session2.interface().index());
+ if (errorSpy2.isEmpty()) {
+ QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress());
+ QCOMPARE(session.interface().index(), session2.interface().index());
+ }
#endif
}
sessionOpenedSpy2.clear();
- if (forceSessionStop) {
+ if (forceSessionStop && session2.isOpen()) {
// Test forcing the second session to stop the interface.
QNetworkSession::State previousState = session.state();
#ifdef Q_CC_NOKIAX86
@@ -922,15 +973,17 @@ void tst_QNetworkSession::sessionOpenCloseStop()
#else
bool expectStateChange = previousState != QNetworkSession::Disconnected;
#endif
-
session2.stop();
+ // QNetworkSession::stop() must result either closed() signal
+ // or error() signal
QTRY_VERIFY(!sessionClosedSpy2.isEmpty() || !errorSpy2.isEmpty());
-
QVERIFY(!session2.isOpen());
if (!errorSpy2.isEmpty()) {
- QVERIFY(!errorSpy.isEmpty());
+ // QNetworkSession::stop() resulted error() signal for session2
+ // => also session should emit error() signal
+ QTRY_VERIFY(!errorSpy.isEmpty());
// check for SessionAbortedError
QNetworkSession::SessionError error =
@@ -950,9 +1003,12 @@ void tst_QNetworkSession::sessionOpenCloseStop()
QVERIFY(errorSpy.isEmpty());
QVERIFY(errorSpy2.isEmpty());
-
+
+ // Wait for Disconnected state
+ QTRY_NOOP(session2.state() == QNetworkSession::Disconnected);
+
if (expectStateChange)
- QTRY_VERIFY(stateChangedSpy2.count() >= 2 || !errorSpy2.isEmpty());
+ QTRY_VERIFY(stateChangedSpy2.count() >= 1 || !errorSpy2.isEmpty());
if (!errorSpy2.isEmpty()) {
QVERIFY(session2.state() == previousState);
@@ -996,16 +1052,29 @@ void tst_QNetworkSession::sessionOpenCloseStop()
state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(3).at(0));
QVERIFY(state == QNetworkSession::Disconnected);
+
+ QTRY_VERIFY(session.state() == QNetworkSession::Roaming ||
+ session.state() == QNetworkSession::Connected ||
+ session.state() == QNetworkSession::Disconnected);
+
QTRY_VERIFY(stateChangedSpy.count() > 0);
- state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(0).at(0));
+ state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(stateChangedSpy.count() - 1).at(0));
+
if (state == QNetworkSession::Roaming) {
- QTRY_VERIFY(!errorSpy.isEmpty() || stateChangedSpy.count() > 1);
- if (stateChangedSpy.count() > 1 &&
- qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(1).at(0)) ==
- QNetworkSession::Connected) {
- roamedSuccessfully = true;
+ QTRY_VERIFY(session.state() == QNetworkSession::Connected);
+ QTRY_VERIFY(session2.state() == QNetworkSession::Connected);
+ roamedSuccessfully = true;
+ } else if (state == QNetworkSession::Disconnected) {
+ QTRY_VERIFY(!errorSpy.isEmpty());
+ QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected);
+ } else if (state == QNetworkSession::Connected) {
+ QTRY_VERIFY(errorSpy.isEmpty());
+ if (stateChangedSpy.count() > 1) {
+ state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(stateChangedSpy.count() - 2).at(0));
+ QVERIFY(state == QNetworkSession::Roaming);
}
- }
+ roamedSuccessfully = true;
+ }
if (roamedSuccessfully) {
QString configId = session.sessionProperty("ActiveConfiguration").toString();
@@ -1013,37 +1082,36 @@ void tst_QNetworkSession::sessionOpenCloseStop()
QNetworkSession session3(config);
QSignalSpy errorSpy3(&session3, SIGNAL(error(QNetworkSession::SessionError)));
QSignalSpy sessionOpenedSpy3(&session3, SIGNAL(opened()));
-
session3.open();
- session3.waitForOpened();
-
+ session3.waitForOpened();
if (session.isOpen())
QVERIFY(!sessionOpenedSpy3.isEmpty() || !errorSpy3.isEmpty());
-
session.stop();
-
QTRY_VERIFY(session.state() == QNetworkSession::Disconnected);
- QTRY_VERIFY(session3.state() == QNetworkSession::Disconnected);
}
#ifndef Q_CC_NOKIAX86
if (!roamedSuccessfully)
QVERIFY(!errorSpy.isEmpty());
#endif
} else {
- QCOMPARE(stateChangedSpy2.count(), 2);
-
- QNetworkSession::State state =
- qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(0).at(0));
- QVERIFY(state == QNetworkSession::Closing);
-
- state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(1).at(0));
- QVERIFY(state == QNetworkSession::Disconnected);
+ QTest::qWait(2000); // Wait awhile to get all signals from platform
+
+ if (stateChangedSpy2.count() == 2) {
+ QNetworkSession::State state =
+ qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(0).at(0));
+ QVERIFY(state == QNetworkSession::Closing);
+ state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(1).at(0));
+ QVERIFY(state == QNetworkSession::Disconnected);
+ } else { // Assume .count() == 1
+ QCOMPARE(stateChangedSpy2.count(), 1);
+ QNetworkSession::State state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(0).at(0));
+ // Symbian version dependant.
+ QVERIFY(state == QNetworkSession::Disconnected);
+ }
}
QTRY_VERIFY(!sessionClosedSpy.isEmpty());
-
QTRY_VERIFY(session.state() == QNetworkSession::Disconnected);
- QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected);
}
QVERIFY(errorSpy2.isEmpty());
@@ -1062,7 +1130,7 @@ void tst_QNetworkSession::sessionOpenCloseStop()
QVERIFY(!session.isOpen());
#endif
QVERIFY(!session2.isOpen());
- } else {
+ } else if (session2.isOpen()) {
// Test closing the second session.
{
int stateChangedCountBeforeClose = stateChangedSpy2.count();
@@ -1161,11 +1229,15 @@ QDebug operator<<(QDebug debug, const QList<QNetworkConfiguration> &list)
// at Discovered -state.
void tst_QNetworkSession::outOfProcessSession()
{
- qDebug() << "START";
-
+ if (!testsToRun["outOfProcessSession"]) {
+ QSKIP("Temporary skip due to value set false (or it is missing) in testsToRun map", SkipAll);
+ }
#if defined(Q_OS_SYMBIAN) && defined(__WINS__)
QSKIP("Symbian emulator does not support two [QR]PRocesses linking a dll (QtBearer.dll) with global writeable static data.", SkipAll);
#endif
+ updateConfigurations();
+ QTest::qWait(2000);
+
QNetworkConfigurationManager manager;
// Create a QNetworkConfigurationManager to detect configuration changes made in Lackey. This
// is actually the essence of this testcase - to check that platform mediates/reflects changes
@@ -1182,16 +1254,15 @@ void tst_QNetworkSession::outOfProcessSession()
QLocalServer::removeServer("tst_qnetworksession");
oopServer.listen("tst_qnetworksession");
- qDebug() << "starting lackey";
QProcess lackey;
lackey.start("lackey/lackey");
qDebug() << lackey.error() << lackey.errorString();
QVERIFY(lackey.waitForStarted());
- qDebug() << "waiting for connection";
+
QVERIFY(oopServer.waitForNewConnection(-1));
QLocalSocket *oopSocket = oopServer.nextPendingConnection();
- qDebug() << "got connection";
+
do {
QByteArray output;
@@ -1258,7 +1329,6 @@ void tst_QNetworkSession::outOfProcessSession()
default:
QSKIP("Lackey failed", SkipAll);
}
- qDebug("STOP");
}
// A convinience / helper function for testcases. Return the first matching configuration.
@@ -1269,6 +1339,7 @@ QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfigur
// Refresh configurations and derive configurations matching given parameters.
QNetworkConfigurationManager mgr;
QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted()));
+
mgr.updateConfigurations();
QTRY_NOOP(updateSpy.count() == 1);
if (updateSpy.count() != 1) {
@@ -1277,8 +1348,7 @@ QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfigur
}
QList<QNetworkConfiguration> discoveredConfigs = mgr.allConfigurations(QNetworkConfiguration::Discovered);
foreach(QNetworkConfiguration config, discoveredConfigs) {
- if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
- // qDebug() << "Dumping config because is active: " << config.name();
+ if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
discoveredConfigs.removeOne(config);
} else if (config.type() != configType) {
// qDebug() << "Dumping config because type (IAP/SNAP) mismatches: " << config.name();
@@ -1315,9 +1385,23 @@ void updateConfigurations()
QTRY_NOOP(updateSpy.count() == 1);
}
+// A convinience-function: updates and prints all available confiurations and their states
+void printConfigurations()
+{
+ QNetworkConfigurationManager manager;
+ QList<QNetworkConfiguration> allConfigs =
+ manager.allConfigurations();
+ qDebug("tst_QNetworkSession::printConfigurations QNetworkConfigurationManager gives following configurations: ");
+ foreach(QNetworkConfiguration config, allConfigs) {
+ qDebug() << "Name of the configuration: " << config.name();
+ qDebug() << "State of the configuration: " << config.state();
+ }
+}
+
// A convinience function for test-cases: opens the given configuration and return
// true if it was done gracefully.
bool openSession(QNetworkSession *session) {
+ bool result = true;
QNetworkConfigurationManager mgr;
QSignalSpy openedSpy(session, SIGNAL(opened()));
QSignalSpy stateChangeSpy(session, SIGNAL(stateChanged(QNetworkSession::State)));
@@ -1327,43 +1411,57 @@ bool openSession(QNetworkSession *session) {
// active by some other session
QNetworkConfiguration::StateFlags configInitState = session->configuration().state();
QNetworkSession::State sessionInitState = session->state();
+ qDebug() << "tst_QNetworkSession::openSession() name of the configuration to be opened: " << session->configuration().name();
+ qDebug() << "tst_QNetworkSession::openSession() state of the configuration to be opened: " << session->configuration().state();
+ qDebug() << "tst_QNetworkSession::openSession() state of the session to be opened: " << session->state();
if (session->isOpen() ||
!session->sessionProperty("ActiveConfiguration").toString().isEmpty()) {
qDebug("tst_QNetworkSession::openSession() failure: session was already open / active.");
- return false;
+ result = false;
} else {
session->open();
session->waitForOpened(120000); // Bringing interfaces up and down may take time at platform
}
+ QTest::qWait(5000); // Wait a moment to ensure all signals are propagated
// Check that connection opening went by the book. Add checks here if more strictness needed.
if (!session->isOpen()) {
qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::open() failed.");
- return false;
+ result = false;
}
if (openedSpy.count() != 1) {
qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::opened() - signal not received.");
- return false;
+ result = false;
}
if (!errorSpy.isEmpty()) {
qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::error() - signal was detected.");
- return false;
+ result = false;
}
if (sessionInitState != QNetworkSession::Connected &&
stateChangeSpy.isEmpty()) {
qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::stateChanged() - signals not detected.");
- return false;
+ result = false;
}
if (configInitState != QNetworkConfiguration::Active &&
configChangeSpy.isEmpty()) {
qDebug("tst_QNetworkSession::openSession() failure: QNetworkConfigurationManager::configurationChanged() - signals not detected.");
- return false;
+ result = false;
}
if (session->configuration().state() != QNetworkConfiguration::Active) {
qDebug("tst_QNetworkSession::openSession() failure: session's configuration is not in 'Active' -state.");
- return false;
+ qDebug() << "tst_QNetworkSession::openSession() state is: " << session->configuration().state();
+ result = false;
+ }
+ if (result == false) {
+ qDebug() << "tst_QNetworkSession::openSession() opening session failed.";
+ } else {
+ qDebug() << "tst_QNetworkSession::openSession() opening session succeeded.";
}
- return true;
+ qDebug() << "tst_QNetworkSession::openSession() name of the configuration is: " << session->configuration().name();
+ qDebug() << "tst_QNetworkSession::openSession() configuration state is: " << session->configuration().state();
+ qDebug() << "tst_QNetworkSession::openSession() session state is: " << session->state();
+
+ return result;
}
// Helper function for closing opened session. Performs checks that
@@ -1376,6 +1474,11 @@ bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration) {
qDebug("tst_QNetworkSession::closeSession() failure: NULL session given");
return false;
}
+
+ qDebug() << "tst_QNetworkSession::closeSession() name of the configuration to be closed: " << session->configuration().name();
+ qDebug() << "tst_QNetworkSession::closeSession() state of the configuration to be closed: " << session->configuration().state();
+ qDebug() << "tst_QNetworkSession::closeSession() state of the session to be closed: " << session->state();
+
if (session->state() != QNetworkSession::Connected ||
!session->isOpen()) {
qDebug("tst_QNetworkSession::closeSession() failure: session is not opened.");
@@ -1387,38 +1490,48 @@ bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration) {
QSignalSpy sessionErrorSpy(session, SIGNAL(error(QNetworkSession::SessionError)));
QSignalSpy configChangeSpy(&mgr, SIGNAL(configurationChanged(QNetworkConfiguration)));
+ bool result = true;
session->close();
+ QTest::qWait(5000); // Wait a moment so that all signals are propagated
if (!sessionErrorSpy.isEmpty()) {
qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::error() received.");
- return false;
+ result = false;
}
if (sessionClosedSpy.count() != 1) {
qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::closed() signal not received.");
- return false;
+ result = false;
}
if (lastSessionOnConfiguration &&
sessionStateChangedSpy.isEmpty()) {
qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::stateChanged() signals not received.");
- return false;
+ result = false;
}
if (lastSessionOnConfiguration &&
session->state() != QNetworkSession::Disconnected) {
qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession is not in Disconnected -state");
- return false;
+ result = false;
}
QTRY_NOOP(!configChangeSpy.isEmpty());
if (lastSessionOnConfiguration &&
configChangeSpy.isEmpty()) {
qDebug("tst_QNetworkSession::closeSession() failure: QNetworkConfigurationManager::configurationChanged() - signal not detected.");
- return false;
+ result = false;
}
if (lastSessionOnConfiguration &&
session->configuration().state() == QNetworkConfiguration::Active) {
qDebug("tst_QNetworkSession::closeSession() failure: session's configuration is still in active state.");
- return false;
+ result = false;
}
- return true;
+ if (result == false) {
+ qDebug() << "tst_QNetworkSession::closeSession() closing session failed.";
+ } else {
+ qDebug() << "tst_QNetworkSession::closeSession() closing session succeeded.";
+ }
+ qDebug() << "tst_QNetworkSession::closeSession() name of the configuration is: " << session->configuration().name();
+ qDebug() << "tst_QNetworkSession::closeSession() configuration state is: " << session->configuration().state();
+ qDebug() << "tst_QNetworkSession::closeSession() session state is: " << session->state();
+ return result;
}
void tst_QNetworkSession::sessionAutoClose_data()
diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
index cd512a1..31cae40 100644
--- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
@@ -144,6 +144,7 @@ private slots:
void blockingIMAP();
void nonBlockingIMAP();
void hostNotFound();
+ void timeoutConnect_data();
void timeoutConnect();
void delayedClose();
void partialRead();
@@ -544,19 +545,36 @@ void tst_QTcpSocket::hostNotFound()
}
//----------------------------------------------------------------------------------
+void tst_QTcpSocket::timeoutConnect_data()
+{
+ QTest::addColumn<QString>("address");
+ QTest::newRow("host") << QtNetworkSettings::serverName();
+ QTest::newRow("ip") << QtNetworkSettings::serverIP().toString();
+}
void tst_QTcpSocket::timeoutConnect()
{
+ QFETCH(QString, address);
QTcpSocket *socket = newSocket();
- // Outgoing port 53 is firewalled in the Oslo office.
- socket->connectToHost("cisco.com", 53);
+ QElapsedTimer timer;
+ timer.start();
+
+ // Port 1357 is configured to drop packets on the test server
+ socket->connectToHost(address, 1357);
+ QVERIFY(timer.elapsed() < 50);
QVERIFY(!socket->waitForConnected(200));
QCOMPARE(socket->state(), QTcpSocket::UnconnectedState);
QCOMPARE(int(socket->error()), int(QTcpSocket::SocketTimeoutError));
- socket->connectToHost("cisco.com", 53);
- QTest::qSleep(50);
+ timer.start();
+ socket->connectToHost(address, 1357);
+ QVERIFY(timer.elapsed() < 50);
+ QTimer::singleShot(50, &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(5);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QVERIFY(socket->state() == QTcpSocket::ConnectingState
+ || socket->state() == QTcpSocket::HostLookupState);
socket->abort();
QCOMPARE(socket->state(), QTcpSocket::UnconnectedState);
QCOMPARE(socket->openMode(), QIODevice::NotOpen);
diff --git a/tests/manual/bearerex/bearerex.cpp b/tests/manual/bearerex/bearerex.cpp
index 19246a2..bf60dd1 100644
--- a/tests/manual/bearerex/bearerex.cpp
+++ b/tests/manual/bearerex/bearerex.cpp
@@ -300,8 +300,12 @@ SessionTab::SessionTab(QNetworkConfiguration* apNetworkConfiguration,
SessionTab::~SessionTab()
{
+ // Need to be nulled, because modal dialogs may return after destruction of this object and
+ // use already released resources.
delete m_NetworkSession;
+ m_NetworkSession = NULL;
delete m_http;
+ m_http = NULL;
}
void SessionTab::on_createQHttpButton_clicked()
@@ -551,10 +555,16 @@ void SessionTab::done(bool error)
msgBox.setText(QString("HTTP request finished successfully.\nReceived ")+QString::number(result.length())+QString(" bytes."));
}
msgBox.exec();
-
- sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+
- QString(" / ")+
- QString::number(m_NetworkSession->bytesReceived()));
+ // Check if the networksession still exists - it may have gone after returning from
+ // the modal dialog (in the case that app has been closed, and deleting QHttp will
+ // trigger the done() invokation).
+ if (m_NetworkSession) {
+ sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+
+ QString(" / ")+
+ QString::number(m_NetworkSession->bytesReceived()));
+ } else {
+ sentRecDataLineEdit->setText("Data amounts not available.");
+ }
}
// End of file