summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qbearertestcommon.h74
-rw-r--r--tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro15
-rw-r--r--tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp335
-rw-r--r--tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro15
-rw-r--r--tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp303
-rw-r--r--tests/auto/qnetworksession/lackey/lackey.pro12
-rw-r--r--tests/auto/qnetworksession/lackey/main.cpp138
-rw-r--r--tests/auto/qnetworksession/qnetworksession.pro2
-rw-r--r--tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp873
-rw-r--r--tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro21
10 files changed, 1788 insertions, 0 deletions
diff --git a/tests/auto/qbearertestcommon.h b/tests/auto/qbearertestcommon.h
new file mode 100644
index 0000000..3356bd6
--- /dev/null
+++ b/tests/auto/qbearertestcommon.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QBEARERTESTCOMMON_H
+#define QBEARERTESTCOMMON_H
+
+// Will try to wait for the condition while allowing event processing
+#define QTRY_VERIFY(__expr) \
+ do { \
+ const int __step = 50; \
+ const int __timeout = 90000; \
+ if (!(__expr)) { \
+ QTest::qWait(0); \
+ } \
+ for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \
+ QTest::qWait(__step); \
+ } \
+ QVERIFY(__expr); \
+ } while(0)
+
+// Will try to wait for the condition while allowing event processing
+#define QTRY_COMPARE(__expr, __expected) \
+ do { \
+ const int __step = 50; \
+ const int __timeout = 90000; \
+ if ((__expr) != (__expected)) { \
+ QTest::qWait(0); \
+ } \
+ for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
+ QTest::qWait(__step); \
+ } \
+ QCOMPARE(__expr, __expected); \
+ } while(0)
+
+#endif
+
diff --git a/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro
new file mode 100644
index 0000000..0b2ed1a
--- /dev/null
+++ b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro
@@ -0,0 +1,15 @@
+SOURCES += tst_qnetworkconfigmanager.cpp
+HEADERS += ../qbearertestcommon.h
+TARGET = tst_qnetworkconfigurationmanager
+CONFIG += testcase
+
+QT = core network
+
+INCLUDEPATH += ../../../src/bearer
+
+include(../../../common.pri)
+qtAddLibrary(QtBearer)
+
+symbian {
+ TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData
+}
diff --git a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp
new file mode 100644
index 0000000..796677d
--- /dev/null
+++ b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp
@@ -0,0 +1,335 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include "../qbearertestcommon.h"
+#include "qnetworkconfiguration.h"
+#include "qnetworkconfigmanager.h"
+
+#ifdef MAEMO
+#include <stdio.h>
+#include <iapconf.h>
+#endif
+
+QTM_USE_NAMESPACE
+class tst_QNetworkConfigurationManager : public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+
+private slots:
+ void allConfigurations();
+ void defaultConfiguration();
+ void configurationFromIdentifier();
+
+private:
+#ifdef MAEMO
+ Maemo::IAPConf *iapconf;
+ Maemo::IAPConf *iapconf2;
+ Maemo::IAPConf *gprsiap;
+#define MAX_IAPS 50
+ Maemo::IAPConf *iaps[MAX_IAPS];
+ QProcess *icd_stub;
+#endif
+};
+
+void tst_QNetworkConfigurationManager::initTestCase()
+{
+#ifdef MAEMO
+ iapconf = new Maemo::IAPConf("007");
+ iapconf->setValue("ipv4_type", "AUTO");
+ iapconf->setValue("wlan_wepkey1", "connt");
+ iapconf->setValue("wlan_wepdefkey", 1);
+ iapconf->setValue("wlan_ssid", QByteArray("JamesBond"));
+ iapconf->setValue("name", "James Bond");
+ iapconf->setValue("type", "WLAN_INFRA");
+
+ gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP");
+ gprsiap->setValue("ask_password", false);
+ gprsiap->setValue("gprs_accesspointname", "internet");
+ gprsiap->setValue("gprs_password", "");
+ gprsiap->setValue("gprs_username", "");
+ gprsiap->setValue("ipv4_autodns", true);
+ gprsiap->setValue("ipv4_type", "AUTO");
+ gprsiap->setValue("sim_imsi", "244070123456789");
+ gprsiap->setValue("name", "MI6");
+ gprsiap->setValue("type", "GPRS");
+
+ iapconf2 = new Maemo::IAPConf("osso.net");
+ iapconf2->setValue("ipv4_type", "AUTO");
+ iapconf2->setValue("wlan_wepkey1", "osso.net");
+ iapconf2->setValue("wlan_wepdefkey", 1);
+ iapconf2->setValue("wlan_ssid", QByteArray("osso.net"));
+ iapconf2->setValue("name", "osso.net");
+ iapconf2->setValue("type", "WLAN_INFRA");
+ iapconf2->setValue("wlan_security", "WEP");
+
+ /* Create large number of IAPs in the gconf and see what happens */
+ fflush(stdout);
+ printf("Creating %d IAPS: ", MAX_IAPS);
+ for (int i=0; i<MAX_IAPS; i++) {
+ QString num = QString().sprintf("%d", i);
+ QString iap = "iap-" + num;
+ iaps[i] = new Maemo::IAPConf(iap);
+ iaps[i]->setValue("name", QString("test-iap-")+num);
+ iaps[i]->setValue("type", "WLAN_INFRA");
+ iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii());
+ iaps[i]->setValue("wlan_security", "WPA_PSK");
+ iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num);
+ printf(".");
+ fflush(stdout);
+ }
+ printf("\n");
+ fflush(stdout);
+
+ icd_stub = new QProcess(this);
+ icd_stub->start("/usr/bin/icd2_stub.py");
+ QTest::qWait(1000);
+
+ // Add a known network to scan list that icd2 stub returns
+ QProcess dbus_send;
+ // 007 network
+ dbus_send.start("dbus-send --type=method_call --system "
+ "--dest=com.nokia.icd2 /com/nokia/icd2 "
+ "com.nokia.icd2.testing.add_available_network "
+ "string:'' uint32:0 string:'' "
+ "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55");
+ dbus_send.waitForFinished();
+
+ // osso.net network
+ dbus_send.start("dbus-send --type=method_call --system "
+ "--dest=com.nokia.icd2 /com/nokia/icd2 "
+ "com.nokia.icd2.testing.add_available_network "
+ "string:'' uint32:0 string:'' "
+ "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116");
+ dbus_send.waitForFinished();
+#endif
+}
+
+
+void tst_QNetworkConfigurationManager::cleanupTestCase()
+{
+#ifdef MAEMO
+ iapconf->clear();
+ delete iapconf;
+ iapconf2->clear();
+ delete iapconf2;
+ gprsiap->clear();
+ delete gprsiap;
+
+ printf("Deleting %d IAPS : ", MAX_IAPS);
+ for (int i=0; i<MAX_IAPS; i++) {
+ iaps[i]->clear();
+ delete iaps[i];
+ printf(".");
+ fflush(stdout);
+ }
+ printf("\n");
+ qDebug() << "Deleted" << MAX_IAPS << "IAPs";
+
+ icd_stub->terminate();
+ icd_stub->waitForFinished();
+#endif
+}
+
+void tst_QNetworkConfigurationManager::init()
+{
+}
+
+void tst_QNetworkConfigurationManager::cleanup()
+{
+}
+
+void printConfigurationDetails(const QNetworkConfiguration& p)
+{
+ qDebug() << p.name() <<": isvalid->" <<p.isValid() << " type->"<< p.type() <<
+ " roaming->" << p.isRoamingAvailable() << "identifier->" << p.identifier() <<
+ " purpose->" << p.purpose() << " state->" << p.state();
+}
+
+void tst_QNetworkConfigurationManager::allConfigurations()
+{
+ QNetworkConfigurationManager manager;
+ QList<QNetworkConfiguration> preScanConfigs = manager.allConfigurations();
+
+ foreach(QNetworkConfiguration c, preScanConfigs)
+ {
+ QVERIFY2(c.type()!=QNetworkConfiguration::UserChoice, "allConfiguration must not return UserChoice configs");
+ }
+
+ QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
+ manager.updateConfigurations(); //initiate scans
+ QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+
+ QList<QNetworkConfiguration> configs = manager.allConfigurations();
+
+ int all = configs.count();
+ qDebug() << "All configurations:" << all;
+ QVERIFY(all);
+ foreach(QNetworkConfiguration p, configs) {
+ QVERIFY(p.isValid());
+ printConfigurationDetails(p);
+ QVERIFY(p.type() != QNetworkConfiguration::Invalid);
+ QVERIFY(p.type() != QNetworkConfiguration::UserChoice);
+ }
+
+ configs = manager.allConfigurations(QNetworkConfiguration::Undefined);
+ int undefined = configs.count();
+ QVERIFY(undefined <= all);
+ qDebug() << "Undefined configurations:" << undefined;
+ foreach( const QNetworkConfiguration p, configs) {
+ printConfigurationDetails(p);
+ QVERIFY(p.state() & QNetworkConfiguration::Undefined);
+ QVERIFY(!(p.state() & QNetworkConfiguration::Defined));
+ }
+
+ //get defined configs only (same as all)
+ configs = manager.allConfigurations(QNetworkConfiguration::Defined);
+ int defined = configs.count();
+ qDebug() << "Defined configurations:" << defined;
+ QVERIFY(defined <= all);
+ foreach( const QNetworkConfiguration p, configs) {
+ printConfigurationDetails(p);
+ QVERIFY(p.state() & QNetworkConfiguration::Defined);
+ QVERIFY(!(p.state() & QNetworkConfiguration::Undefined));
+ }
+
+ //get discovered configurations only
+ configs = manager.allConfigurations(QNetworkConfiguration::Discovered);
+ int discovered = configs.count();
+ //QVERIFY(discovered);
+ qDebug() << "Discovered configurations:" << discovered;
+ foreach(const QNetworkConfiguration p, configs) {
+ printConfigurationDetails(p);
+ QVERIFY(p.isValid());
+ QVERIFY(!(p.state() & QNetworkConfiguration::Undefined));
+ QVERIFY(p.state() & QNetworkConfiguration::Defined);
+ QVERIFY(p.state() & QNetworkConfiguration::Discovered);
+ }
+
+ //getactive configurations only
+ configs = manager.allConfigurations(QNetworkConfiguration::Active);
+ int active = configs.count();
+ if (active)
+ QVERIFY(manager.isOnline());
+ else
+ QVERIFY(!manager.isOnline());
+
+ //QVERIFY(active);
+ qDebug() << "Active configurations:" << active;
+ foreach(const QNetworkConfiguration p, configs) {
+ printConfigurationDetails(p);
+ QVERIFY(p.isValid());
+ QVERIFY(!(p.state() & QNetworkConfiguration::Undefined));
+ QVERIFY(p.state() & QNetworkConfiguration::Active);
+ QVERIFY(p.state() & QNetworkConfiguration::Discovered);
+ QVERIFY(p.state() & QNetworkConfiguration::Defined);
+ }
+
+ QVERIFY(all >= discovered);
+ QVERIFY(discovered >= active);
+}
+
+
+void tst_QNetworkConfigurationManager::defaultConfiguration()
+{
+ QNetworkConfigurationManager manager;
+ QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
+ manager.updateConfigurations(); //initiate scans
+ QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+
+ QList<QNetworkConfiguration> configs = manager.allConfigurations();
+ QNetworkConfiguration defaultConfig = manager.defaultConfiguration();
+
+ bool confirm = configs.contains(defaultConfig);
+ bool isUserChoice = (defaultConfig.type() == QNetworkConfiguration::UserChoice);
+
+ //user choice config is not part of allConfigurations()
+ QVERIFY(isUserChoice != confirm);
+ if (!isUserChoice) {
+ QVERIFY(confirm || !defaultConfig.isValid());
+ QVERIFY(!(confirm && !defaultConfig.isValid()));
+ } else {
+ QVERIFY(defaultConfig.isValid());
+ QCOMPARE(defaultConfig.name(), QString("UserChoice"));
+ QCOMPARE(defaultConfig.children().count(), 0);
+ QVERIFY(!defaultConfig.isRoamingAvailable());
+ QCOMPARE(defaultConfig.state(), QNetworkConfiguration::Discovered);
+ QNetworkConfiguration copy = manager.configurationFromIdentifier(defaultConfig.identifier());
+ QVERIFY(copy == defaultConfig);
+ }
+}
+
+void tst_QNetworkConfigurationManager::configurationFromIdentifier()
+{
+ QNetworkConfigurationManager manager;
+ QSet<QString> allIdentifier;
+
+ //force an update to get maximum number of configs
+ QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
+ manager.updateConfigurations(); //initiate scans
+ QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+
+ QList<QNetworkConfiguration> configs = manager.allConfigurations();
+
+ foreach(QNetworkConfiguration c, configs) {
+ QVERIFY(!allIdentifier.contains(c.identifier()));
+ allIdentifier.insert(c.identifier());
+
+ QNetworkConfiguration direct = manager.configurationFromIdentifier(c.identifier());
+ QVERIFY(direct.isValid());
+ QVERIFY(direct == c);
+ }
+
+ //assume that there is no item with identifier 'FooBar'
+ QVERIFY(!allIdentifier.contains("FooBar"));
+ QNetworkConfiguration invalid = manager.configurationFromIdentifier("FooBar");
+ QVERIFY(!invalid.isValid());
+}
+
+
+QTEST_MAIN(tst_QNetworkConfigurationManager)
+#include "tst_qnetworkconfigmanager.moc"
diff --git a/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro
new file mode 100644
index 0000000..61e4097
--- /dev/null
+++ b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro
@@ -0,0 +1,15 @@
+SOURCES += tst_qnetworkconfiguration.cpp
+HEADERS += ../qbearertestcommon.h
+TARGET = tst_qnetworkconfiguration
+CONFIG += testcase
+
+QT = core network
+
+INCLUDEPATH += ../../../src/bearer
+
+include(../../../common.pri)
+qtAddLibrary(QtBearer)
+
+symbian {
+ TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData
+}
diff --git a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp
new file mode 100644
index 0000000..cbb13f3
--- /dev/null
+++ b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp
@@ -0,0 +1,303 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include "../qbearertestcommon.h"
+#include "qnetworkconfiguration.h"
+#include "qnetworkconfigmanager.h"
+
+#ifdef MAEMO
+#include <stdio.h>
+#include <iapconf.h>
+#endif
+
+QTM_USE_NAMESPACE
+class tst_QNetworkConfiguration : public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+private slots:
+ void invalidPoint();
+ void comparison();
+ void children();
+ void isRoamingAvailable();
+
+private:
+#ifdef MAEMO
+ Maemo::IAPConf *iapconf;
+ Maemo::IAPConf *iapconf2;
+ Maemo::IAPConf *gprsiap;
+#define MAX_IAPS 50
+ Maemo::IAPConf *iaps[MAX_IAPS];
+ QProcess *icd_stub;
+#endif
+};
+
+void tst_QNetworkConfiguration::initTestCase()
+{
+#ifdef MAEMO
+ iapconf = new Maemo::IAPConf("007");
+ iapconf->setValue("ipv4_type", "AUTO");
+ iapconf->setValue("wlan_wepkey1", "connt");
+ iapconf->setValue("wlan_wepdefkey", 1);
+ iapconf->setValue("wlan_ssid", QByteArray("JamesBond"));
+ iapconf->setValue("name", "James Bond");
+ iapconf->setValue("type", "WLAN_INFRA");
+
+ iapconf2 = new Maemo::IAPConf("osso.net");
+ iapconf2->setValue("ipv4_type", "AUTO");
+ iapconf2->setValue("wlan_wepkey1", "osso.net");
+ iapconf2->setValue("wlan_wepdefkey", 1);
+ iapconf2->setValue("wlan_ssid", QByteArray("osso.net"));
+ iapconf2->setValue("name", "osso.net");
+ iapconf2->setValue("type", "WLAN_INFRA");
+ iapconf2->setValue("wlan_security", "WEP");
+
+ gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP");
+ gprsiap->setValue("ask_password", false);
+ gprsiap->setValue("gprs_accesspointname", "internet");
+ gprsiap->setValue("gprs_password", "");
+ gprsiap->setValue("gprs_username", "");
+ gprsiap->setValue("ipv4_autodns", true);
+ gprsiap->setValue("ipv4_type", "AUTO");
+ gprsiap->setValue("sim_imsi", "244070123456789");
+ gprsiap->setValue("name", "MI6");
+ gprsiap->setValue("type", "GPRS");
+
+ /* Create large number of IAPs in the gconf and see what happens */
+ fflush(stdout);
+ printf("Creating %d IAPS: ", MAX_IAPS);
+ for (int i=0; i<MAX_IAPS; i++) {
+ QString num = QString().sprintf("%d", i);
+ QString iap = "iap-" + num;
+ iaps[i] = new Maemo::IAPConf(iap);
+ iaps[i]->setValue("name", QString("test-iap-")+num);
+ iaps[i]->setValue("type", "WLAN_INFRA");
+ iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii());
+ iaps[i]->setValue("wlan_security", "WPA_PSK");
+ iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num);
+ printf(".");
+ fflush(stdout);
+ }
+ printf("\n");
+ fflush(stdout);
+
+ icd_stub = new QProcess(this);
+ icd_stub->start("/usr/bin/icd2_stub.py");
+ QTest::qWait(1000);
+
+ // Add a known network to scan list that icd2 stub returns
+ QProcess dbus_send;
+ // 007 network
+ dbus_send.start("dbus-send --type=method_call --system "
+ "--dest=com.nokia.icd2 /com/nokia/icd2 "
+ "com.nokia.icd2.testing.add_available_network "
+ "string:'' uint32:0 string:'' "
+ "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55");
+ dbus_send.waitForFinished();
+
+ // osso.net network
+ dbus_send.start("dbus-send --type=method_call --system "
+ "--dest=com.nokia.icd2 /com/nokia/icd2 "
+ "com.nokia.icd2.testing.add_available_network "
+ "string:'' uint32:0 string:'' "
+ "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116");
+ dbus_send.waitForFinished();
+#endif
+}
+
+void tst_QNetworkConfiguration::cleanupTestCase()
+{
+#ifdef MAEMO
+ iapconf->clear();
+ delete iapconf;
+ iapconf2->clear();
+ delete iapconf2;
+ gprsiap->clear();
+ delete gprsiap;
+
+ printf("Deleting %d IAPS : ", MAX_IAPS);
+ for (int i=0; i<MAX_IAPS; i++) {
+ iaps[i]->clear();
+ delete iaps[i];
+ printf(".");
+ fflush(stdout);
+ }
+ printf("\n");
+ qDebug() << "Deleted" << MAX_IAPS << "IAPs";
+
+ // Terminate icd2 stub
+ icd_stub->terminate();
+ icd_stub->waitForFinished();
+#endif
+}
+
+void tst_QNetworkConfiguration::invalidPoint()
+{
+ QNetworkConfiguration pt;
+
+ QVERIFY(pt.name().isEmpty());
+ QVERIFY(!pt.isValid());
+ QVERIFY(pt.type() == QNetworkConfiguration::Invalid);
+ QVERIFY(!(pt.state() & QNetworkConfiguration::Defined));
+ QVERIFY(!(pt.state() & QNetworkConfiguration::Discovered));
+ QVERIFY(!(pt.state() & QNetworkConfiguration::Active));
+ QVERIFY(!pt.isRoamingAvailable());
+
+ QNetworkConfiguration pt2(pt);
+ QVERIFY(pt2.name().isEmpty());
+ QVERIFY(!pt2.isValid());
+ QVERIFY(pt2.type() == QNetworkConfiguration::Invalid);
+ QVERIFY(!(pt2.state() & QNetworkConfiguration::Defined));
+ QVERIFY(!(pt2.state() & QNetworkConfiguration::Discovered));
+ QVERIFY(!(pt2.state() & QNetworkConfiguration::Active));
+ QVERIFY(!pt2.isRoamingAvailable());
+
+}
+
+void tst_QNetworkConfiguration::comparison()
+{
+ //test copy constructor and assignment operator
+ //compare invalid connection points
+ QNetworkConfiguration pt1;
+ QVERIFY(!pt1.isValid());
+ QVERIFY(pt1.type() == QNetworkConfiguration::Invalid);
+
+ QNetworkConfiguration pt2(pt1);
+ QVERIFY(pt1==pt2);
+ QVERIFY(!(pt1!=pt2));
+ QVERIFY(pt1.name() == pt2.name());
+ QVERIFY(pt1.isValid() == pt2.isValid());
+ QVERIFY(pt1.type() == pt2.type());
+ QVERIFY(pt1.state() == pt2.state());
+ QVERIFY(pt1.purpose() == pt2.purpose());
+
+
+ QNetworkConfiguration pt3;
+ pt3 = pt1;
+ QVERIFY(pt1==pt3);
+ QVERIFY(!(pt1!=pt3));
+ QVERIFY(pt1.name() == pt3.name());
+ QVERIFY(pt1.isValid() == pt3.isValid());
+ QVERIFY(pt1.type() == pt3.type());
+ QVERIFY(pt1.state() == pt3.state());
+ QVERIFY(pt1.purpose() == pt3.purpose());
+
+ //test case must run on machine that has valid connection points
+ QNetworkConfigurationManager manager;
+ QList<QNetworkConfiguration> preScanConfigs = manager.allConfigurations();
+
+ QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
+ manager.updateConfigurations(); //initiate scans
+ QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+
+ QList<QNetworkConfiguration> configs = manager.allConfigurations(QNetworkConfiguration::Discovered);
+ QVERIFY(configs.count());
+ QNetworkConfiguration defaultConfig = manager.defaultConfiguration();
+ QVERIFY(defaultConfig.isValid());
+ QVERIFY(defaultConfig.type() != QNetworkConfiguration::Invalid);
+ QVERIFY(!defaultConfig.name().isEmpty());
+
+ pt3 = defaultConfig;
+ QVERIFY(defaultConfig==pt3);
+ QVERIFY(!(defaultConfig!=pt3));
+ QVERIFY(defaultConfig.name() == pt3.name());
+ QVERIFY(defaultConfig.isValid() == pt3.isValid());
+ QVERIFY(defaultConfig.type() == pt3.type());
+ QVERIFY(defaultConfig.state() == pt3.state());
+ QVERIFY(defaultConfig.purpose() == pt3.purpose());
+}
+
+void tst_QNetworkConfiguration::children()
+{
+ QNetworkConfigurationManager manager;
+ QList<QNetworkConfiguration> configs = manager.allConfigurations();
+
+ foreach(QNetworkConfiguration c, configs)
+ {
+ if ( c.type() == QNetworkConfiguration::ServiceNetwork ) {
+ qDebug() << "found service network" << c.name() << c.children().count();
+ QVERIFY(c.isValid());
+ QList<QNetworkConfiguration> members = c.children();
+ foreach(QNetworkConfiguration child, members) {
+ QVERIFY(child.isValid());
+ QVERIFY(configs.contains(child));
+ qDebug() << "\t" << child.name();
+ }
+ }
+ }
+}
+
+void tst_QNetworkConfiguration::isRoamingAvailable()
+{
+ QNetworkConfigurationManager manager;
+ QList<QNetworkConfiguration> configs = manager.allConfigurations();
+
+ //force update to get maximum list
+ QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
+ manager.updateConfigurations(); //initiate scans
+ QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+
+ foreach(QNetworkConfiguration c, configs)
+ {
+ QVERIFY(QNetworkConfiguration::UserChoice != c.type());
+ QVERIFY(QNetworkConfiguration::Invalid != c.type());
+ if ( c.type() == QNetworkConfiguration::ServiceNetwork ) {
+ //cannot test flag as some SNAPs may not support roaming anyway
+ //QVERIFY(c.roamingavailable())
+ if ( c.children().count() <= 1 )
+ QVERIFY(!c.isRoamingAvailable());
+ foreach(QNetworkConfiguration child, c.children()) {
+ QVERIFY(QNetworkConfiguration::InternetAccessPoint == child.type());
+ QCOMPARE(child.children().count(), 0);
+ }
+ } else {
+ QVERIFY(!c.isRoamingAvailable());
+ }
+ }
+}
+
+QTEST_MAIN(tst_QNetworkConfiguration)
+#include "tst_qnetworkconfiguration.moc"
diff --git a/tests/auto/qnetworksession/lackey/lackey.pro b/tests/auto/qnetworksession/lackey/lackey.pro
new file mode 100644
index 0000000..4cb8555
--- /dev/null
+++ b/tests/auto/qnetworksession/lackey/lackey.pro
@@ -0,0 +1,12 @@
+SOURCES += main.cpp
+TARGET = qnetworksessionlackey
+INCLUDEPATH += ../../../../src/bearer
+DEPENDPATH += ../../../../src/bearer
+
+QT = core network
+
+CONFIG+= testcase
+
+include(../../../../common.pri)
+
+qtAddLibrary(QtBearer)
diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp
new file mode 100644
index 0000000..53f6f4f
--- /dev/null
+++ b/tests/auto/qnetworksession/lackey/main.cpp
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QCoreApplication>
+#include <QStringList>
+#include <QLocalSocket>
+#include <qnetworkconfigmanager.h>
+#include <qnetworkconfiguration.h>
+#include <qnetworksession.h>
+
+#include <QDebug>
+
+QTM_USE_NAMESPACE
+
+
+#define NO_DISCOVERED_CONFIGURATIONS_ERROR 1
+#define SESSION_OPEN_ERROR 2
+
+int main(int argc, char** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QNetworkConfigurationManager manager;
+ QList<QNetworkConfiguration> discovered =
+ manager.allConfigurations(QNetworkConfiguration::Discovered);
+
+ if (discovered.isEmpty())
+ 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;
+ do {
+ if (session) {
+ delete session;
+ session = 0;
+ }
+
+ qDebug() << "Discovered configurations:" << discovered.count();
+
+ if (discovered.isEmpty()) {
+ qDebug() << "No more configurations";
+ break;
+ }
+
+ qDebug() << "Taking first configuration";
+
+ QNetworkConfiguration config = discovered.takeFirst();
+ if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
+ qDebug() << config.name() << "is active";
+ continue;
+ }
+
+ qDebug() << "Creating session for" << config.name() << config.identifier();
+
+ session = new QNetworkSession(config);
+
+ QString output = QString("Starting session for %1\n").arg(config.identifier());
+ oopSocket.write(output.toAscii());
+ oopSocket.waitForBytesWritten();
+
+ session->open();
+ session->waitForOpened();
+ } while (!(session && session->isActive()));
+
+ qDebug() << "loop done";
+
+ if (!session) {
+ qDebug() << "Could not start session";
+
+ oopSocket.disconnectFromServer();
+ oopSocket.waitForDisconnected(-1);
+
+ return SESSION_OPEN_ERROR;
+ }
+
+ QString output = QString("Started session for %1\n").arg(session->configuration().identifier());
+ oopSocket.write(output.toAscii());
+ oopSocket.waitForBytesWritten();
+
+ oopSocket.waitForReadyRead();
+ oopSocket.readLine();
+
+ session->stop();
+
+ delete session;
+
+ oopSocket.disconnectFromServer();
+ oopSocket.waitForDisconnected(-1);
+
+ return 0;
+}
diff --git a/tests/auto/qnetworksession/qnetworksession.pro b/tests/auto/qnetworksession/qnetworksession.pro
new file mode 100644
index 0000000..14dbb3e
--- /dev/null
+++ b/tests/auto/qnetworksession/qnetworksession.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS = lackey tst_qnetworksession
diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp
new file mode 100644
index 0000000..cbd4c8f
--- /dev/null
+++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp
@@ -0,0 +1,873 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QLocalServer>
+#include <QLocalSocket>
+#include "../../qbearertestcommon.h"
+#include <qnetworkconfigmanager.h>
+#include <qnetworksession.h>
+
+#ifdef MAEMO
+#include <stdio.h>
+#include <iapconf.h>
+#endif
+
+QTM_USE_NAMESPACE
+
+Q_DECLARE_METATYPE(QNetworkConfiguration)
+Q_DECLARE_METATYPE(QNetworkSession::State);
+Q_DECLARE_METATYPE(QNetworkSession::SessionError);
+
+class tst_QNetworkSession : public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+private slots:
+ void invalidSession();
+
+ void sessionProperties_data();
+ void sessionProperties();
+
+ void userChoiceSession_data();
+ void userChoiceSession();
+
+ void sessionOpenCloseStop_data();
+ void sessionOpenCloseStop();
+
+ void outOfProcessSession();
+
+private:
+ QNetworkConfigurationManager manager;
+
+ uint inProcessSessionManagementCount;
+
+#ifdef MAEMO
+ Maemo::IAPConf *iapconf;
+ Maemo::IAPConf *iapconf2;
+ Maemo::IAPConf *gprsiap;
+#define MAX_IAPS 10
+ Maemo::IAPConf *iaps[MAX_IAPS];
+ QProcess *icd_stub;
+#endif
+};
+
+void tst_QNetworkSession::initTestCase()
+{
+ qRegisterMetaType<QNetworkSession::State>("QNetworkSession::State");
+ qRegisterMetaType<QNetworkSession::SessionError>("QNetworkSession::SessionError");
+ qRegisterMetaType<QNetworkConfiguration>("QNetworkConfiguration");
+
+#ifdef MAEMO
+ iapconf = new Maemo::IAPConf("007");
+ iapconf->setValue("ipv4_type", "AUTO");
+ iapconf->setValue("wlan_wepkey1", "connt");
+ iapconf->setValue("wlan_wepdefkey", 1);
+ iapconf->setValue("wlan_ssid", QByteArray("JamesBond"));
+ iapconf->setValue("name", "James Bond");
+ iapconf->setValue("type", "WLAN_INFRA");
+
+ gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP");
+ gprsiap->setValue("ask_password", false);
+ gprsiap->setValue("gprs_accesspointname", "internet");
+ gprsiap->setValue("gprs_password", "");
+ gprsiap->setValue("gprs_username", "");
+ gprsiap->setValue("ipv4_autodns", true);
+ gprsiap->setValue("ipv4_type", "AUTO");
+ gprsiap->setValue("sim_imsi", "244070123456789");
+ gprsiap->setValue("name", "MI6");
+ gprsiap->setValue("type", "GPRS");
+
+ iapconf2 = new Maemo::IAPConf("osso.net");
+ iapconf2->setValue("ipv4_type", "AUTO");
+ iapconf2->setValue("wlan_wepkey1", "osso.net");
+ iapconf2->setValue("wlan_wepdefkey", 1);
+ iapconf2->setValue("wlan_ssid", QByteArray("osso.net"));
+ iapconf2->setValue("name", "osso.net");
+ iapconf2->setValue("type", "WLAN_INFRA");
+ iapconf2->setValue("wlan_security", "WEP");
+
+ /* Create large number of IAPs in the gconf and see what happens */
+ fflush(stdout);
+ printf("Creating %d IAPS: ", MAX_IAPS);
+ for (int i=0; i<MAX_IAPS; i++) {
+ QString num = QString().sprintf("%d", i);
+ QString iap = "iap-" + num;
+ iaps[i] = new Maemo::IAPConf(iap);
+ iaps[i]->setValue("name", QString("test-iap-")+num);
+ iaps[i]->setValue("type", "WLAN_INFRA");
+ iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii());
+ iaps[i]->setValue("wlan_security", "WPA_PSK");
+ iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num);
+ printf(".");
+ fflush(stdout);
+ }
+ printf("\n");
+ fflush(stdout);
+
+ icd_stub = new QProcess(this);
+ icd_stub->start("/usr/bin/icd2_stub.py");
+ QTest::qWait(1000);
+
+ // Add a known network to scan list that icd2 stub returns
+ QProcess dbus_send;
+ // 007 network
+ dbus_send.start("dbus-send --type=method_call --system "
+ "--dest=com.nokia.icd2 /com/nokia/icd2 "
+ "com.nokia.icd2.testing.add_available_network "
+ "string:'' uint32:0 string:'' "
+ "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55");
+ dbus_send.waitForFinished();
+
+ // osso.net network
+ dbus_send.start("dbus-send --type=method_call --system "
+ "--dest=com.nokia.icd2 /com/nokia/icd2 "
+ "com.nokia.icd2.testing.add_available_network "
+ "string:'' uint32:0 string:'' "
+ "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116");
+ dbus_send.waitForFinished();
+#endif
+
+ inProcessSessionManagementCount = 0;
+
+ QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
+ manager.updateConfigurations();
+ QTRY_VERIFY(spy.count() == 1);
+}
+
+void tst_QNetworkSession::cleanupTestCase()
+{
+ if (!(manager.capabilities() & QNetworkConfigurationManager::SystemSessionSupport) &&
+ (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces) &&
+ inProcessSessionManagementCount == 0) {
+ QFAIL("No usable configurations found to complete all possible "
+ "tests in inProcessSessionManagement()");
+ }
+
+#ifdef MAEMO
+ iapconf->clear();
+ delete iapconf;
+ iapconf2->clear();
+ delete iapconf2;
+ gprsiap->clear();
+ delete gprsiap;
+
+ printf("Deleting %d IAPS : ", MAX_IAPS);
+ for (int i=0; i<MAX_IAPS; i++) {
+ iaps[i]->clear();
+ delete iaps[i];
+ printf(".");
+ fflush(stdout);
+ }
+ printf("\n");
+ qDebug() << "Deleted" << MAX_IAPS << "IAPs";
+
+ icd_stub->terminate();
+ icd_stub->waitForFinished();
+#endif
+}
+
+void tst_QNetworkSession::invalidSession()
+{
+ QNetworkSession session(QNetworkConfiguration(), 0);
+ QVERIFY(!session.isActive());
+ QVERIFY(session.state() == QNetworkSession::Invalid);
+}
+
+void tst_QNetworkSession::sessionProperties_data()
+{
+ QTest::addColumn<QNetworkConfiguration>("configuration");
+
+ QTest::newRow("invalid configuration") << QNetworkConfiguration();
+
+ foreach (const QNetworkConfiguration &config, manager.allConfigurations()) {
+ const QString name = config.name().isEmpty() ? QString("<Hidden>") : config.name();
+ QTest::newRow(name.toLocal8Bit().constData()) << config;
+ }
+}
+
+void tst_QNetworkSession::sessionProperties()
+{
+ QFETCH(QNetworkConfiguration, configuration);
+
+ QNetworkSession session(configuration);
+
+ QVERIFY(session.configuration() == configuration);
+
+ QStringList validBearerNames = QStringList() << QString()
+ << QLatin1String("Ethernet")
+ << QLatin1String("WLAN")
+ << QLatin1String("2G")
+ << QLatin1String("CDMA2000")
+ << QLatin1String("WCDMA")
+ << QLatin1String("HSPA")
+ << QLatin1String("Bluetooth")
+ << QLatin1String("WiMAX");
+
+ if (!configuration.isValid())
+ QVERIFY(session.bearerName().isEmpty());
+ else
+ QVERIFY(validBearerNames.contains(session.bearerName()));
+
+ // QNetworkSession::interface() should return an invalid interface unless
+ // session is in the connected state.
+ QCOMPARE(session.state() == QNetworkSession::Connected, session.interface().isValid());
+
+ if (!configuration.isValid()) {
+ QVERIFY(configuration.state() == QNetworkConfiguration::Undefined &&
+ session.state() == QNetworkSession::Invalid);
+ } else {
+ switch (configuration.state()) {
+ case QNetworkConfiguration::Undefined:
+ QVERIFY(session.state() == QNetworkSession::NotAvailable);
+ break;
+ case QNetworkConfiguration::Defined:
+ QVERIFY(session.state() == QNetworkSession::NotAvailable);
+ break;
+ case QNetworkConfiguration::Discovered:
+ QVERIFY(session.state() == QNetworkSession::Connecting ||
+ session.state() == QNetworkSession::Disconnected);
+ break;
+ case QNetworkConfiguration::Active:
+ QVERIFY(session.state() == QNetworkSession::Connected ||
+ session.state() == QNetworkSession::Closing ||
+ session.state() == QNetworkSession::Roaming);
+ break;
+ default:
+ QFAIL("Invalid configuration state");
+ };
+ }
+}
+
+void tst_QNetworkSession::userChoiceSession_data()
+{
+ QTest::addColumn<QNetworkConfiguration>("configuration");
+
+ QNetworkConfiguration config = manager.defaultConfiguration();
+ if (config.type() == QNetworkConfiguration::UserChoice)
+ QTest::newRow("UserChoice") << config;
+ else
+ QSKIP("Default configuration is not a UserChoice configuration.", SkipAll);
+}
+
+void tst_QNetworkSession::userChoiceSession()
+{
+ QFETCH(QNetworkConfiguration, configuration);
+
+ QVERIFY(configuration.type() == QNetworkConfiguration::UserChoice);
+
+ QNetworkSession session(configuration);
+
+ QVERIFY(session.configuration() == configuration);
+
+ QVERIFY(!session.isActive());
+
+ QVERIFY(session.sessionProperty("ActiveConfigurationIdentifier").toString().isEmpty());
+
+
+ // The remaining tests require the session to be not NotAvailable.
+ if (session.state() == QNetworkSession::NotAvailable)
+ QSKIP("Network is not available.", SkipSingle);
+
+ QSignalSpy sessionOpenedSpy(&session, SIGNAL(opened()));
+ QSignalSpy sessionClosedSpy(&session, SIGNAL(closed()));
+ QSignalSpy stateChangedSpy(&session, SIGNAL(stateChanged(QNetworkSession::State)));
+ QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError)));
+
+ // Test opening the session.
+ {
+ bool expectStateChange = session.state() != QNetworkSession::Connected;
+
+ session.open();
+
+ session.waitForOpened();
+
+ if (session.isActive())
+ QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty());
+ if (!errorSpy.isEmpty()) {
+ QNetworkSession::SessionError error =
+ qvariant_cast<QNetworkSession::SessionError>(errorSpy.first().at(0));
+ if (error == QNetworkSession::OperationNotSupportedError) {
+ // The session needed to bring up the interface,
+ // but the operation is not supported.
+ QSKIP("Configuration does not support open().", SkipSingle);
+ } else if (error == QNetworkSession::InvalidConfigurationError) {
+ // The session needed to bring up the interface, but it is not possible for the
+ // specified configuration.
+ if ((session.configuration().state() & QNetworkConfiguration::Discovered) ==
+ QNetworkConfiguration::Discovered) {
+ QFAIL("Failed to open session for Discovered configuration.");
+ } else {
+ QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle);
+ }
+ } else if (error == QNetworkSession::UnknownSessionError) {
+ QSKIP("Unknown session error.", SkipSingle);
+ } else {
+ QFAIL("Error opening session.");
+ }
+ } else if (!sessionOpenedSpy.isEmpty()) {
+ QCOMPARE(sessionOpenedSpy.count(), 1);
+ QVERIFY(sessionClosedSpy.isEmpty());
+ QVERIFY(errorSpy.isEmpty());
+
+ if (expectStateChange)
+ QTRY_VERIFY(!stateChangedSpy.isEmpty());
+
+ QVERIFY(session.state() == QNetworkSession::Connected);
+ QVERIFY(session.interface().isValid());
+
+ const QString userChoiceIdentifier =
+ session.sessionProperty("UserChoiceConfigurationIdentifier").toString();
+
+ QVERIFY(!userChoiceIdentifier.isEmpty());
+ QVERIFY(userChoiceIdentifier != configuration.identifier());
+
+ QNetworkConfiguration userChoiceConfiguration =
+ manager.configurationFromIdentifier(userChoiceIdentifier);
+
+ QVERIFY(userChoiceConfiguration.isValid());
+ QVERIFY(userChoiceConfiguration.type() != QNetworkConfiguration::UserChoice);
+
+ const QString testIdentifier("abc");
+ //resetting UserChoiceConfigurationIdentifier is ignored (read only property)
+ session.setSessionProperty("UserChoiceConfigurationIdentifier", testIdentifier);
+ QVERIFY(session.sessionProperty("UserChoiceConfigurationIdentifier").toString() != testIdentifier);
+
+ const QString activeIdentifier =
+ session.sessionProperty("ActiveConfigurationIdentifier").toString();
+
+ QVERIFY(!activeIdentifier.isEmpty());
+ QVERIFY(activeIdentifier != configuration.identifier());
+
+ QNetworkConfiguration activeConfiguration =
+ manager.configurationFromIdentifier(activeIdentifier);
+
+ QVERIFY(activeConfiguration.isValid());
+ QVERIFY(activeConfiguration.type() == QNetworkConfiguration::InternetAccessPoint);
+
+ //resetting ActiveConfigurationIdentifier is ignored (read only property)
+ session.setSessionProperty("ActiveConfigurationIdentifier", testIdentifier);
+ QVERIFY(session.sessionProperty("ActiveConfigurationIdentifier").toString() != testIdentifier);
+
+ if (userChoiceConfiguration.type() == QNetworkConfiguration::InternetAccessPoint) {
+ QVERIFY(userChoiceConfiguration == activeConfiguration);
+ } else {
+ QVERIFY(userChoiceConfiguration.type() == QNetworkConfiguration::ServiceNetwork);
+ QVERIFY(userChoiceConfiguration.children().contains(activeConfiguration));
+ }
+ } else {
+ QFAIL("Timeout waiting for session to open.");
+ }
+ }
+}
+
+void tst_QNetworkSession::sessionOpenCloseStop_data()
+{
+ QTest::addColumn<QNetworkConfiguration>("configuration");
+ QTest::addColumn<bool>("forceSessionStop");
+
+ foreach (const QNetworkConfiguration &config, manager.allConfigurations()) {
+ const QString name = config.name().isEmpty() ? QString("<Hidden>") : config.name();
+ QTest::newRow((name + QLatin1String(" close")).toLocal8Bit().constData())
+ << config << false;
+ QTest::newRow((name + QLatin1String(" stop")).toLocal8Bit().constData())
+ << config << true;
+ }
+}
+
+void tst_QNetworkSession::sessionOpenCloseStop()
+{
+ QFETCH(QNetworkConfiguration, configuration);
+ QFETCH(bool, forceSessionStop);
+
+ QNetworkSession session(configuration);
+
+ // Test initial state of the session.
+ {
+ QVERIFY(session.configuration() == configuration);
+ QVERIFY(!session.isActive());
+ // session may be invalid if configuration is removed between when
+ // sessionOpenCloseStop_data() is called and here.
+ QVERIFY((configuration.isValid() && (session.state() != QNetworkSession::Invalid)) ||
+ (!configuration.isValid() && (session.state() == QNetworkSession::Invalid)));
+ QVERIFY(session.error() == QNetworkSession::UnknownSessionError);
+ }
+
+ // The remaining tests require the session to be not NotAvailable.
+ if (session.state() == QNetworkSession::NotAvailable)
+ QSKIP("Network is not available.", SkipSingle);
+
+ QSignalSpy sessionOpenedSpy(&session, SIGNAL(opened()));
+ QSignalSpy sessionClosedSpy(&session, SIGNAL(closed()));
+ QSignalSpy stateChangedSpy(&session, SIGNAL(stateChanged(QNetworkSession::State)));
+ QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError)));
+
+ // Test opening the session.
+ {
+ QNetworkSession::State previousState = session.state();
+ bool expectStateChange = previousState != QNetworkSession::Connected;
+
+ session.open();
+
+ session.waitForOpened();
+
+ if (session.isActive())
+ QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty());
+ if (!errorSpy.isEmpty()) {
+ QNetworkSession::SessionError error =
+ qvariant_cast<QNetworkSession::SessionError>(errorSpy.first().at(0));
+
+ QVERIFY(session.state() == previousState);
+
+ if (error == QNetworkSession::OperationNotSupportedError) {
+ // The session needed to bring up the interface,
+ // but the operation is not supported.
+ QSKIP("Configuration does not support open().", SkipSingle);
+ } else if (error == QNetworkSession::InvalidConfigurationError) {
+ // The session needed to bring up the interface, but it is not possible for the
+ // specified configuration.
+ if ((session.configuration().state() & QNetworkConfiguration::Discovered) ==
+ QNetworkConfiguration::Discovered) {
+ QFAIL("Failed to open session for Discovered configuration.");
+ } else {
+ QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle);
+ }
+ } else if (error == QNetworkSession::UnknownSessionError) {
+ QSKIP("Unknown Session error.", SkipSingle);
+ } else {
+ QFAIL("Error opening session.");
+ }
+ } else if (!sessionOpenedSpy.isEmpty()) {
+ QCOMPARE(sessionOpenedSpy.count(), 1);
+ QVERIFY(sessionClosedSpy.isEmpty());
+ QVERIFY(errorSpy.isEmpty());
+
+ if (expectStateChange) {
+ QTRY_VERIFY(stateChangedSpy.count() >= 2);
+
+ QNetworkSession::State state =
+ qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(0).at(0));
+ QVERIFY(state == QNetworkSession::Connecting);
+
+ state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(1).at(0));
+ QVERIFY(state == QNetworkSession::Connected);
+ }
+
+ QVERIFY(session.state() == QNetworkSession::Connected);
+ QVERIFY(session.interface().isValid());
+ } else {
+ QFAIL("Timeout waiting for session to open.");
+ }
+ }
+
+ sessionOpenedSpy.clear();
+ sessionClosedSpy.clear();
+ stateChangedSpy.clear();
+ errorSpy.clear();
+
+ QNetworkSession session2(configuration);
+
+ QSignalSpy sessionOpenedSpy2(&session2, SIGNAL(opened()));
+ QSignalSpy sessionClosedSpy2(&session2, SIGNAL(closed()));
+ QSignalSpy stateChangedSpy2(&session2, SIGNAL(stateChanged(QNetworkSession::State)));
+ QSignalSpy errorSpy2(&session2, SIGNAL(error(QNetworkSession::SessionError)));
+
+ // Test opening a second session.
+ {
+ QVERIFY(session2.configuration() == configuration);
+ QVERIFY(!session2.isActive());
+ QVERIFY(session2.state() == QNetworkSession::Connected);
+ QVERIFY(session.error() == QNetworkSession::UnknownSessionError);
+
+ session2.open();
+
+ QTRY_VERIFY(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty());
+
+ QVERIFY(session.isActive());
+ QVERIFY(session2.isActive());
+ QVERIFY(session.state() == QNetworkSession::Connected);
+ QVERIFY(session2.state() == QNetworkSession::Connected);
+ QVERIFY(session.interface().isValid());
+ QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress());
+ QCOMPARE(session.interface().index(), session2.interface().index());
+ }
+
+ sessionOpenedSpy2.clear();
+
+ if (forceSessionStop) {
+ // Test forcing the second session to stop the interface.
+ QNetworkSession::State previousState = session.state();
+#ifdef Q_CC_NOKIAX86
+ // For S60 emulator builds: RConnection::Stop does not work on all Emulators
+ bool expectStateChange = false;
+#else
+ bool expectStateChange = previousState != QNetworkSession::Disconnected;
+#endif
+
+ session2.stop();
+
+ QTRY_VERIFY(!sessionClosedSpy2.isEmpty() || !errorSpy2.isEmpty());
+
+ QVERIFY(!session2.isActive());
+
+ if (!errorSpy2.isEmpty()) {
+ QVERIFY(!errorSpy.isEmpty());
+
+ // check for SessionAbortedError
+ QNetworkSession::SessionError error =
+ qvariant_cast<QNetworkSession::SessionError>(errorSpy.first().at(0));
+ QNetworkSession::SessionError error2 =
+ qvariant_cast<QNetworkSession::SessionError>(errorSpy2.first().at(0));
+
+ QVERIFY(error == QNetworkSession::SessionAbortedError);
+ QVERIFY(error2 == QNetworkSession::SessionAbortedError);
+
+ QCOMPARE(errorSpy.count(), 1);
+ QCOMPARE(errorSpy2.count(), 1);
+
+ errorSpy.clear();
+ errorSpy2.clear();
+ }
+
+ QVERIFY(errorSpy.isEmpty());
+ QVERIFY(errorSpy2.isEmpty());
+
+ if (expectStateChange)
+ QTRY_VERIFY(stateChangedSpy2.count() >= 2 || !errorSpy2.isEmpty());
+
+ if (!errorSpy2.isEmpty()) {
+ QVERIFY(session2.state() == previousState);
+ QVERIFY(session.state() == previousState);
+
+ QNetworkSession::SessionError error =
+ qvariant_cast<QNetworkSession::SessionError>(errorSpy2.first().at(0));
+ if (error == QNetworkSession::OperationNotSupportedError) {
+ // The session needed to bring down the interface,
+ // but the operation is not supported.
+ QSKIP("Configuration does not support stop().", SkipSingle);
+ } else if (error == QNetworkSession::InvalidConfigurationError) {
+ // The session needed to bring down the interface, but it is not possible for the
+ // specified configuration.
+ if ((session.configuration().state() & QNetworkConfiguration::Discovered) ==
+ QNetworkConfiguration::Discovered) {
+ QFAIL("Failed to stop session for Discovered configuration.");
+ } else {
+ QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle);
+ }
+ } else {
+ QFAIL("Error stopping session.");
+ }
+ } else if (!sessionClosedSpy2.isEmpty()) {
+ if (expectStateChange) {
+ if (configuration.type() == QNetworkConfiguration::ServiceNetwork) {
+ bool roamedSuccessfully = false;
+
+ QCOMPARE(stateChangedSpy2.count(), 4);
+
+ QNetworkSession::State state =
+ qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(0).at(0));
+ QVERIFY(state == QNetworkSession::Connecting);
+
+ state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(1).at(0));
+ QVERIFY(state == QNetworkSession::Connected);
+
+ state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(2).at(0));
+ QVERIFY(state == QNetworkSession::Closing);
+
+ state = qvariant_cast<QNetworkSession::State>(stateChangedSpy2.at(3).at(0));
+ QVERIFY(state == QNetworkSession::Disconnected);
+
+ QTRY_VERIFY(stateChangedSpy.count() > 0);
+ state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(0).at(0));
+ if (state == QNetworkSession::Roaming) {
+ QTRY_VERIFY(!errorSpy.isEmpty() || stateChangedSpy.count() > 1);
+ if (stateChangedSpy.count() > 1) {
+ state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(1).at(0));
+ if (state == QNetworkSession::Connected) {
+ roamedSuccessfully = true;
+ QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected);
+ }
+ }
+ }
+ if (roamedSuccessfully) {
+ QString configId = session.sessionProperty("ActiveConfigurationIdentifier").toString();
+ QNetworkConfiguration config = manager.configurationFromIdentifier(configId);
+ QNetworkSession session3(config);
+ QSignalSpy errorSpy3(&session3, SIGNAL(error(QNetworkSession::SessionError)));
+ QSignalSpy sessionOpenedSpy3(&session3, SIGNAL(opened()));
+
+ session3.open();
+ session3.waitForOpened();
+
+ if (session.isActive())
+ 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);
+ }
+
+ QTRY_VERIFY(!sessionClosedSpy.isEmpty());
+ QVERIFY(session.state() == QNetworkSession::Disconnected);
+ QVERIFY(session2.state() == QNetworkSession::Disconnected);
+ }
+
+ QVERIFY(errorSpy2.isEmpty());
+
+ ++inProcessSessionManagementCount;
+ } else {
+ QFAIL("Timeout waiting for session to stop.");
+ }
+
+#ifndef Q_CC_NOKIAX86
+ QVERIFY(!sessionClosedSpy.isEmpty());
+#endif
+ QVERIFY(!sessionClosedSpy2.isEmpty());
+
+#ifndef Q_CC_NOKIAX86
+ QVERIFY(!session.isActive());
+#endif
+ QVERIFY(!session2.isActive());
+ } else {
+ // Test closing the second session.
+ {
+ int stateChangedCountBeforeClose = stateChangedSpy2.count();
+ session2.close();
+
+ QTRY_VERIFY(!sessionClosedSpy2.isEmpty());
+#ifndef Q_CC_NOKIAX86
+ QVERIFY(stateChangedSpy2.count() == stateChangedCountBeforeClose);
+#endif
+
+ QVERIFY(sessionClosedSpy.isEmpty());
+
+ QVERIFY(session.isActive());
+ QVERIFY(!session2.isActive());
+ QVERIFY(session.state() == QNetworkSession::Connected);
+ QVERIFY(session2.state() == QNetworkSession::Connected);
+ QVERIFY(session.interface().isValid());
+ QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress());
+ QCOMPARE(session.interface().index(), session2.interface().index());
+ }
+
+ sessionClosedSpy2.clear();
+
+ // Test closing the first session.
+ {
+#ifdef Q_CC_NOKIAX86
+ // For S60 emulator builds: RConnection::Close does not actually
+ // close network connection on all Emulators
+ bool expectStateChange = false;
+#else
+ bool expectStateChange = session.state() != QNetworkSession::Disconnected &&
+ manager.capabilities() & QNetworkConfigurationManager::SystemSessionSupport;
+#endif
+
+ session.close();
+
+ QTRY_VERIFY(!sessionClosedSpy.isEmpty() || !errorSpy.isEmpty());
+
+ QVERIFY(!session.isActive());
+
+ if (expectStateChange)
+ QTRY_VERIFY(!stateChangedSpy.isEmpty() || !errorSpy.isEmpty());
+
+ if (!errorSpy.isEmpty()) {
+ QNetworkSession::SessionError error =
+ qvariant_cast<QNetworkSession::SessionError>(errorSpy.first().at(0));
+ if (error == QNetworkSession::OperationNotSupportedError) {
+ // The session needed to bring down the interface,
+ // but the operation is not supported.
+ QSKIP("Configuration does not support close().", SkipSingle);
+ } else if (error == QNetworkSession::InvalidConfigurationError) {
+ // The session needed to bring down the interface, but it is not possible for the
+ // specified configuration.
+ if ((session.configuration().state() & QNetworkConfiguration::Discovered) ==
+ QNetworkConfiguration::Discovered) {
+ QFAIL("Failed to close session for Discovered configuration.");
+ } else {
+ QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle);
+ }
+ } else {
+ QFAIL("Error closing session.");
+ }
+ } else if (!sessionClosedSpy.isEmpty()) {
+ QVERIFY(sessionOpenedSpy.isEmpty());
+ QCOMPARE(sessionClosedSpy.count(), 1);
+ if (expectStateChange)
+ QVERIFY(!stateChangedSpy.isEmpty());
+ QVERIFY(errorSpy.isEmpty());
+
+ if (expectStateChange)
+ QTRY_VERIFY(session.state() == QNetworkSession::Disconnected);
+
+ ++inProcessSessionManagementCount;
+ } else {
+ QFAIL("Timeout waiting for session to close.");
+ }
+ }
+ }
+}
+
+QDebug operator<<(QDebug debug, const QList<QNetworkConfiguration> &list)
+{
+ debug.nospace() << "( ";
+ foreach (const QNetworkConfiguration &config, list)
+ debug.nospace() << config.identifier() << ", ";
+ debug.nospace() << ")\n";
+ return debug;
+}
+
+void tst_QNetworkSession::outOfProcessSession()
+{
+ QNetworkConfigurationManager manager;
+
+ QList<QNetworkConfiguration> before = manager.allConfigurations(QNetworkConfiguration::Active);
+
+ QSignalSpy spy(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)));
+
+ // Cannot read/write to processes on WinCE or Symbian.
+ // Easiest alternative is to use sockets for IPC.
+
+ QLocalServer oopServer;
+ oopServer.listen("tst_qnetworksession");
+
+ QProcess lackey;
+ lackey.start("qnetworksessionlackey");
+ QVERIFY(lackey.waitForStarted());
+
+ QVERIFY(oopServer.waitForNewConnection(-1));
+ QLocalSocket *oopSocket = oopServer.nextPendingConnection();
+
+ do {
+ QByteArray output;
+
+ if(oopSocket->waitForReadyRead())
+ output = oopSocket->readLine().trimmed();
+
+ if (output.startsWith("Started session ")) {
+ QString identifier = QString::fromLocal8Bit(output.mid(16).constData());
+
+ QNetworkConfiguration changed;
+
+ do {
+ QTRY_VERIFY(!spy.isEmpty());
+
+ changed = qvariant_cast<QNetworkConfiguration>(spy.takeFirst().at(0));
+
+ } while (changed.identifier() != identifier);
+
+ QVERIFY((changed.state() & QNetworkConfiguration::Active) ==
+ QNetworkConfiguration::Active);
+
+ QVERIFY(!before.contains(changed));
+
+ QList<QNetworkConfiguration> after =
+ manager.allConfigurations(QNetworkConfiguration::Active);
+
+ QVERIFY(after.contains(changed));
+
+ spy.clear();
+
+ oopSocket->write("stop\n");
+ oopSocket->waitForBytesWritten();
+
+ do {
+ QTRY_VERIFY(!spy.isEmpty());
+
+ changed = qvariant_cast<QNetworkConfiguration>(spy.takeFirst().at(0));
+ } while (changed.identifier() != identifier);
+
+ QVERIFY((changed.state() & QNetworkConfiguration::Active) !=
+ QNetworkConfiguration::Active);
+
+ QList<QNetworkConfiguration> afterStop =
+ manager.allConfigurations(QNetworkConfiguration::Active);
+
+ QVERIFY(!afterStop.contains(changed));
+
+ oopSocket->disconnectFromServer();
+ oopSocket->waitForDisconnected(-1);
+
+ lackey.waitForFinished();
+ }
+ // This is effected by QTBUG-4903, process will always report as running
+ //} while (lackey.state() == QProcess::Running);
+
+ // Workaround: the socket in the lackey will disconnect on exit
+ } while (oopSocket->state() == QLocalSocket::ConnectedState);
+
+ switch (lackey.exitCode()) {
+ case 0:
+ break;
+ case 1:
+ QSKIP("No discovered configurations found.", SkipAll);
+ break;
+ case 2:
+ QSKIP("Lackey could not start session.", SkipAll);
+ default:
+ QSKIP("Lackey failed", SkipAll);
+ }
+}
+
+QTEST_MAIN(tst_QNetworkSession)
+
+#include "tst_qnetworksession.moc"
+
diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro
new file mode 100644
index 0000000..1410601
--- /dev/null
+++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro
@@ -0,0 +1,21 @@
+SOURCES += tst_qnetworksession.cpp
+HEADERS += ../../qbearertestcommon.h
+TARGET = tst_qnetworksession
+CONFIG += testcase
+
+QT = core network
+
+INCLUDEPATH += ../../../../src/bearer
+
+include(../../../../common.pri)
+qtAddLibrary(QtBearer)
+
+wince* {
+ LACKEY.sources = $$OUTPUT_DIR/build/tests/bin/qnetworksessionlackey.exe
+ LACKEY.path = .
+ DEPLOYMENT += LACKEY
+}
+
+symbian {
+ TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData
+}