diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-21 22:07:50 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-21 22:07:50 (GMT) |
commit | 949bb292c8ec1db36c5515378d8edd39762eadbb (patch) | |
tree | 5fdc90fd34ac4e49ba05bef47a86427e4df71917 /tests | |
parent | 0a83a6c571fadb454cb8711aed84258b061d44b5 (diff) | |
parent | 32955e230ed7983d29af05515263771d04c5e2da (diff) | |
download | Qt-949bb292c8ec1db36c5515378d8edd39762eadbb.zip Qt-949bb292c8ec1db36c5515378d8edd39762eadbb.tar.gz Qt-949bb292c8ec1db36c5515378d8edd39762eadbb.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/mobility-staging into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/mobility-staging: (114 commits)
Create unit-test in parent directory.
Allow QNAM to be created as a global variable.
Don't load NetworkManager plugin in NetworkManager is not available.
Disable NLA plugin, build generic on win32 and mac.
Fix QNetworkSession unit test.
Fix segfault.
Remove debug output.
Make this a warning.
Don't block forever if no bearer plugins are loaded.
Always build generic plugin when building NetworkManager plugin.
Add QT_MODULE headers.
Change docs: "phone" -> "device".
Remove unused code.
Simplify.
Optimise iterations over QHash.
Use snippets.
Reorder members to remove hole.
Expand documentation for QNAM::setConfiguration() and friends.
Fix build on Windows, typo.
Fix build on Windows.
...
Diffstat (limited to 'tests')
28 files changed, 4850 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 7ba6243..3034f30 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -454,7 +454,10 @@ SUBDIRS += \ qmargins \ qnetworkaddressentry \ qnetworkcachemetadata \ + qnetworkconfigmanager \ + qnetworkconfiguration \ qnetworkdiskcache \ + qnetworksession \ qobjectperformance \ qpainterpathstroker \ qplugin \ diff --git a/tests/auto/qbearertestcommon.h b/tests/auto/qbearertestcommon.h new file mode 100644 index 0000000..0bfe622 --- /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 test suite of the Qt Toolkit. +** +** $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..30eb5f0 --- /dev/null +++ b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro @@ -0,0 +1,15 @@ +load(qttest_p4) +SOURCES += tst_qnetworkconfigmanager.cpp +HEADERS += ../qbearertestcommon.h + +QT = core network + +symbian { + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData +} + +maemo6 { + CONFIG += link_pkgconfig + + PKGCONFIG += conninet +} diff --git a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp new file mode 100644 index 0000000..3052330 --- /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 test suite of the Qt Toolkit. +** +** $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 Q_WS_MAEMO_6 +#include <stdio.h> +#include <iapconf.h> +#endif + +QT_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 Q_WS_MAEMO_6 + 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 Q_WS_MAEMO_6 + 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 Q_WS_MAEMO_6 + 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..df2d2d9 --- /dev/null +++ b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro @@ -0,0 +1,15 @@ +load(qttest_p4) +SOURCES += tst_qnetworkconfiguration.cpp +HEADERS += ../qbearertestcommon.h + +QT = core network + +symbian { + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData +} + +maemo6 { + CONFIG += link_pkgconfig + + PKGCONFIG += conninet +} diff --git a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp new file mode 100644 index 0000000..70f4447 --- /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 test suite of the Qt Toolkit. +** +** $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 Q_WS_MAEMO_6 +#include <stdio.h> +#include <iapconf.h> +#endif + +QT_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 Q_WS_MAEMO_6 + 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 Q_WS_MAEMO_6 + 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 Q_WS_MAEMO_6 + 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..8fbdd58 --- /dev/null +++ b/tests/auto/qnetworksession/lackey/lackey.pro @@ -0,0 +1,14 @@ +SOURCES += main.cpp +TARGET = lackey + +QT = core network + +DESTDIR = ./ + +win32:CONFIG += console + +symbian { + # Needed for interprocess communication and opening QNetworkSession + TARGET.CAPABILITY = NetworkControl NetworkServices +} + diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp new file mode 100644 index 0000000..41e935a --- /dev/null +++ b/tests/auto/qnetworksession/lackey/main.cpp @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $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> + +QT_USE_NAMESPACE + + +#define NO_DISCOVERED_CONFIGURATIONS_ERROR 1 +#define SESSION_OPEN_ERROR 2 + + +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); + + QNetworkConfigurationManager manager; + QList<QNetworkConfiguration> discovered = +#if defined (Q_OS_SYMBIAN) + // On Symbian, on the first query (before updateConfigurations() call + // the discovered-states are not correct, so defined-state will do. + manager.allConfigurations(QNetworkConfiguration::Defined); +#else + manager.allConfigurations(QNetworkConfiguration::Discovered); +#endif + if (discovered.isEmpty()) { + return NO_DISCOVERED_CONFIGURATIONS_ERROR; + } + + qDebug() << "Lackey started"; + + QNetworkSession *session = 0; + do { + if (session) { + delete session; + session = 0; + } + + qDebug() << "Discovered configurations:" << discovered.count(); + + if (discovered.isEmpty()) { + qDebug() << "No more discovered configurations"; + break; + } + + qDebug() << "Taking first configuration"; + + QNetworkConfiguration config = discovered.takeFirst(); + + if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + qDebug() << config.name() << "is active, therefore skipping it (looking for configs in 'discovered' state)."; + 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->isOpen())); + + qDebug() << "lackey: 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..a85925b --- /dev/null +++ b/tests/auto/qnetworksession/qnetworksession.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = lackey test diff --git a/tests/auto/qnetworksession/test/test.pro b/tests/auto/qnetworksession/test/test.pro new file mode 100644 index 0000000..d248b10 --- /dev/null +++ b/tests/auto/qnetworksession/test/test.pro @@ -0,0 +1,26 @@ +load(qttest_p4) +SOURCES += tst_qnetworksession.cpp +HEADERS += ../../qbearertestcommon.h + +QT = core network + +TARGET = tst_qnetworksession +CONFIG(debug_and_release) { + CONFIG(debug, debug|release) { + DESTDIR = ../debug + } else { + DESTDIR = ../release + } +} else { + DESTDIR = .. +} + +symbian { + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData PowerMgmt +} + +maemo6 { + CONFIG += link_pkgconfig + + PKGCONFIG += conninet +} diff --git a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp new file mode 100644 index 0000000..4ef3a4f --- /dev/null +++ b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp @@ -0,0 +1,919 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $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 Q_WS_MAEMO_6 +#include <stdio.h> +#include <iapconf.h> +#endif + +QT_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 outOfProcessSession(); + void invalidSession(); + + void sessionProperties_data(); + void sessionProperties(); + + void userChoiceSession_data(); + void userChoiceSession(); + + void sessionOpenCloseStop_data(); + void sessionOpenCloseStop(); + +private: + QNetworkConfigurationManager manager; + + int inProcessSessionManagementCount; + +#ifdef Q_WS_MAEMO_6 + 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 Q_WS_MAEMO_6 + 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 = -1; + + 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) { + qWarning("No usable configurations found to complete all possible tests in " + "inProcessSessionManagement()"); + } + +#ifdef Q_WS_MAEMO_6 + 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.isOpen()); + 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() << QLatin1String("Unknown") + << QLatin1String("Ethernet") + << QLatin1String("WLAN") + << QLatin1String("2G") + << QLatin1String("CDMA2000") + << QLatin1String("WCDMA") + << QLatin1String("HSPA") + << QLatin1String("Bluetooth") + << QLatin1String("WiMAX"); + + if (!configuration.isValid()) { + QVERIFY(configuration.bearerName().isEmpty()); + } else { + qDebug() << "Type:" << configuration.type() + << "Bearer:" << configuration.bearerName(); + + switch (configuration.type()) + { + case QNetworkConfiguration::ServiceNetwork: + case QNetworkConfiguration::UserChoice: + default: + QVERIFY(configuration.bearerName().isEmpty()); + break; + case QNetworkConfiguration::InternetAccessPoint: + QVERIFY(validBearerNames.contains(configuration.bearerName())); + break; + } + } + + // QNetworkSession::interface() should return an invalid interface unless + // session is in the connected state. + qDebug() << "Session state:" << session.state(); + 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()); +#endif + + 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); + + // Check that configuration was really set + QVERIFY(session.configuration() == configuration); + + QVERIFY(!session.isOpen()); + + // Check that session is not active + QVERIFY(session.sessionProperty("ActiveConfiguration").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.isOpen()) + 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); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QVERIFY(session.interface().isValid()); +#endif + + const QString userChoiceIdentifier = + session.sessionProperty("UserChoiceConfiguration").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 UserChoiceConfiguration is ignored (read only property) + session.setSessionProperty("UserChoiceConfiguration", testIdentifier); + QVERIFY(session.sessionProperty("UserChoiceConfiguration").toString() != testIdentifier); + + const QString activeIdentifier = + session.sessionProperty("ActiveConfiguration").toString(); + + QVERIFY(!activeIdentifier.isEmpty()); + QVERIFY(activeIdentifier != configuration.identifier()); + + QNetworkConfiguration activeConfiguration = + manager.configurationFromIdentifier(activeIdentifier); + + QVERIFY(activeConfiguration.isValid()); + QVERIFY(activeConfiguration.type() == QNetworkConfiguration::InternetAccessPoint); + + //resetting ActiveConfiguration is ignored (read only property) + session.setSessionProperty("ActiveConfiguration", testIdentifier); + QVERIFY(session.sessionProperty("ActiveConfiguration").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; + } + + inProcessSessionManagementCount = 0; +} + +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.isOpen()); + // 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.isOpen()) + 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); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QVERIFY(session.interface().isValid()); +#endif + } 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.isOpen()); + QVERIFY(session2.state() == QNetworkSession::Connected); + QVERIFY(session.error() == QNetworkSession::UnknownSessionError); + + session2.open(); + + QTRY_VERIFY(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty()); + + QVERIFY(session.isOpen()); + QVERIFY(session2.isOpen()); + QVERIFY(session.state() == QNetworkSession::Connected); + QVERIFY(session2.state() == QNetworkSession::Connected); +#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()); + } + + 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.isOpen()); + + 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("ActiveConfiguration").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.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); + } + + 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.isOpen()); +#endif + QVERIFY(!session2.isOpen()); + } 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.isOpen()); + QVERIFY(!session2.isOpen()); + QVERIFY(session.state() == QNetworkSession::Connected); + QVERIFY(session2.state() == QNetworkSession::Connected); +#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()); + } + + 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.isOpen()); + + 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; +} + +// Note: outOfProcessSession requires that at least one configuration is +// at Discovered -state (Defined is ok for symbian as well, as long as it is possible to open). +void tst_QNetworkSession::outOfProcessSession() +{ + qDebug() << "START"; + +#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 + 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 + // regardless of process boundaries. The interprocess communication is more like a way to get + // this test-case act correctly and timely. + 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; + // First remove possible earlier listening address which would cause listen to fail + // (e.g. previously abruptly ended unit test might cause this) + 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; + + if (oopSocket->waitForReadyRead()) + output = oopSocket->readLine().trimmed(); + + if (output.startsWith("Started session ")) { + QString identifier = QString::fromLocal8Bit(output.mid(20).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: + qDebug("Lackey returned exit success (0)"); + break; + case 1: + QSKIP("No discovered configurations found.", SkipAll); + case 2: + QSKIP("Lackey could not start session.", SkipAll); + default: + QSKIP("Lackey failed", SkipAll); + } + qDebug("STOP"); +} + +QTEST_MAIN(tst_QNetworkSession) + +#include "tst_qnetworksession.moc" + diff --git a/tests/manual/bearerex/bearerex.cpp b/tests/manual/bearerex/bearerex.cpp new file mode 100644 index 0000000..19246a2 --- /dev/null +++ b/tests/manual/bearerex/bearerex.cpp @@ -0,0 +1,561 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $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 "bearerex.h" + +#include <QtNetwork> + +Q_DECLARE_METATYPE(QNetworkConfiguration) + +BearerEx::BearerEx(QWidget* parent) + : QMainWindow(parent) +{ + setupUi(this); + + createMenus(); + + connect(&m_NetworkConfigurationManager, SIGNAL(updateCompleted()), this, SLOT(configurationsUpdateCompleted())); + connect(&m_NetworkConfigurationManager, SIGNAL(configurationAdded(const QNetworkConfiguration&)), + this, SLOT(configurationAdded(const QNetworkConfiguration&))); + connect(&m_NetworkConfigurationManager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)), + this, SLOT(configurationRemoved(const QNetworkConfiguration&))); + connect(&m_NetworkConfigurationManager, SIGNAL(onlineStateChanged(bool)), + this, SLOT(onlineStateChanged(bool))); + connect(&m_NetworkConfigurationManager, SIGNAL(configurationChanged(const QNetworkConfiguration&)), + this, SLOT(configurationChanged(const QNetworkConfiguration&))); + showConfigurations(); +} + +void BearerEx::createMenus() +{ + QAction* act1 = new QAction(tr("Show Details"), this); + menuBar()->addAction(act1); + connect(act1, SIGNAL(triggered()), this, SLOT(on_showDetailsButton_clicked())); + + QAction* exitAct = new QAction(tr("Exit"), this); + menuBar()->addAction(exitAct); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); +} + +void BearerEx::showConfigurations() +{ + listWidget->clear(); + QListWidgetItem* listItem; + + QNetworkConfiguration defaultConfig = m_NetworkConfigurationManager.defaultConfiguration(); + if (defaultConfig.type() == QNetworkConfiguration::UserChoice) { + listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + font.setUnderline(true); + listItem->setFont(font); + listItem->setText(" UserChoice"); + listItem->setData(Qt::UserRole, qVariantFromValue(defaultConfig)); + listWidget->addItem(listItem); + } + + QList<QNetworkConfiguration> configurations = m_NetworkConfigurationManager.allConfigurations(); + for (int i=0; i<configurations.count(); i++) + { + listItem = new QListWidgetItem(); + QString text; + if (configurations[i].type() == QNetworkConfiguration::InternetAccessPoint) { + text.append("(IAP,"); + } else if (configurations[i].type() == QNetworkConfiguration::ServiceNetwork) { + text.append("(SNAP,"); + } + + if ((configurations[i].state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + text.append("Act) "); + } else if ((configurations[i].state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { + text.append("Disc) "); + } else { + text.append("Def) "); + } + text.append(configurations[i].name()); + + if (defaultConfig.isValid() && defaultConfig == configurations[i]) { + QFont font = listItem->font(); + font.setBold(true); + font.setUnderline(true); + listItem->setFont(font); + } + listItem->setText(text); + listItem->setData(Qt::UserRole, qVariantFromValue(configurations[i])); + listWidget->addItem(listItem); + } +} + +void BearerEx::on_updateConfigurationsButton_clicked() +{ + m_NetworkConfigurationManager.updateConfigurations(); +} + +void BearerEx::on_updateListButton_clicked() +{ + showConfigurations(); +} + +void BearerEx::on_showDetailsButton_clicked() +{ + QListWidgetItem* item = listWidget->currentItem(); + if (!item) { + return; + } + + QNetworkConfiguration networkConfiguration = qVariantValue<QNetworkConfiguration>(item->data(Qt::UserRole)); + DetailedInfoDialog infoDialog(&networkConfiguration,this); + infoDialog.exec(); +} + +void BearerEx::on_createSessionButton_clicked() +{ + QListWidgetItem* item = listWidget->currentItem(); + if (!item) { + return; + } + QNetworkConfiguration networkConfiguration = qVariantValue<QNetworkConfiguration>(item->data(Qt::UserRole)); + int newTabIndex = mainTabWidget->count(); + SessionTab* newTab = new SessionTab(&networkConfiguration,&m_NetworkConfigurationManager,eventListWidget,newTabIndex-1); + QString label = QString("S")+QString::number(newTabIndex-1); + mainTabWidget->insertTab(newTabIndex,newTab,label); + mainTabWidget->setCurrentIndex(newTabIndex); +} + +void BearerEx::on_clearEventListButton_clicked() +{ + eventListWidget->clear(); +} + +void BearerEx::configurationAdded(const QNetworkConfiguration& config) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + listItem->setText(QString("Added: ")+config.name()); + eventListWidget->addItem(listItem); +} + +void BearerEx::configurationRemoved(const QNetworkConfiguration& config) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + listItem->setText(QString("Removed: ")+config.name()); + eventListWidget->addItem(listItem); +} + +void BearerEx::onlineStateChanged(bool isOnline) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + listItem->setFont(font); + if (isOnline) { + listItem->setText(QString("> Online")); + } else { + listItem->setText(QString("< Offline")); + } + eventListWidget->addItem(listItem); +} + +void BearerEx::configurationChanged(const QNetworkConfiguration & config) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QString state; + switch (config.state()) + { + case QNetworkConfiguration::Undefined: + state = "Undef : "; + break; + case QNetworkConfiguration::Defined: + state = "Def : "; + break; + case QNetworkConfiguration::Discovered: + state = "Disc : "; + break; + case QNetworkConfiguration::Active: + state = "Act : "; + break; + } + listItem->setText(state+config.name()); + eventListWidget->addItem(listItem); +} + +void BearerEx::configurationsUpdateCompleted() +{ + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + msgBox.setText("Configurations update completed."); + msgBox.exec(); +} + +DetailedInfoDialog::DetailedInfoDialog(QNetworkConfiguration* apNetworkConfiguration, QWidget * parent) + : QDialog(parent) +{ + setupUi(this); + + tableWidget->setColumnCount(2); + int rowCount = 2; + + if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) { + rowCount = rowCount + apNetworkConfiguration->children().count(); + } + + tableWidget->setRowCount(rowCount); + tableWidget->setColumnWidth(1,250); + tableWidget->setItem(0, 0, new QTableWidgetItem(tr("Name"))); + tableWidget->setItem(0, 1, new QTableWidgetItem(apNetworkConfiguration->name())); + tableWidget->setItem(1, 0, new QTableWidgetItem(tr("Id"))); + tableWidget->setItem(1, 1, new QTableWidgetItem(apNetworkConfiguration->identifier())); + if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) { + for (int i=0; i<apNetworkConfiguration->children().count(); i++) { + tableWidget->setItem(i+2, 0, new QTableWidgetItem(QString("IAP")+QString::number(i+1))); + tableWidget->setItem(i+2, 1, new QTableWidgetItem(apNetworkConfiguration->children()[i].name())); + } + } + + tableWidget->setFocusPolicy(Qt::NoFocus); + +#ifdef Q_OS_SYMBIAN + this->showMaximized(); +#endif +} + +SessionTab::SessionTab(QNetworkConfiguration* apNetworkConfiguration, + QNetworkConfigurationManager* configManager, + QListWidget* eventListWidget, + int index, + BearerEx * parent) + : QWidget(parent), m_http(0), m_eventListWidget(eventListWidget), + m_index(index), m_httpRequestOngoing(false), m_alrEnabled (false) +{ + setupUi(this); + + m_ConfigManager = configManager; + m_NetworkSession = new QNetworkSession(*apNetworkConfiguration); + + // Update initial Session state to UI + newState(m_NetworkSession->state()); + + connect(m_NetworkSession, SIGNAL(newConfigurationActivated()), this, SLOT(newConfigurationActivated())); + connect(m_NetworkSession, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + connect(m_NetworkSession, SIGNAL(opened()), this, SLOT(opened())); + connect(m_NetworkSession, SIGNAL(closed()), this, SLOT(closed())); + connect(m_NetworkSession, SIGNAL(error(QNetworkSession::SessionError)), this, SLOT(error(QNetworkSession::SessionError))); + + if (apNetworkConfiguration->type() == QNetworkConfiguration::InternetAccessPoint) { + snapLabel->hide(); + snapLineEdit->hide(); + alrButton->hide(); + iapLineEdit->setText(apNetworkConfiguration->name()+" ("+apNetworkConfiguration->identifier()+")"); + } else if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) { + snapLineEdit->setText(apNetworkConfiguration->name()+" ("+apNetworkConfiguration->identifier()+")"); + } + bearerLineEdit->setText(apNetworkConfiguration->bearerName()); + sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+ + QString(" / ")+ + QString::number(m_NetworkSession->bytesReceived())); + snapLineEdit->setFocusPolicy(Qt::NoFocus); + iapLineEdit->setFocusPolicy(Qt::NoFocus); + bearerLineEdit->setFocusPolicy(Qt::NoFocus); + sentRecDataLineEdit->setFocusPolicy(Qt::NoFocus); + stateLineEdit->setFocusPolicy(Qt::NoFocus); +} + +SessionTab::~SessionTab() +{ + delete m_NetworkSession; + delete m_http; +} + +void SessionTab::on_createQHttpButton_clicked() +{ + if (m_httpRequestOngoing) { + return; + } + + if (m_http) { + disconnect(m_http, 0, 0, 0); + delete m_http; + } + m_http = new QHttp(this); + createQHttpButton->setText("Recreate QHttp"); + connect(m_http, SIGNAL(done(bool)), this, SLOT(done(bool))); +} + +void SessionTab::on_sendRequestButton_clicked() +{ + if (m_http) { + QString urlstring("http://www.google.com"); + QUrl url(urlstring); + m_http->setHost(url.host(), QHttp::ConnectionModeHttp, url.port() == -1 ? 0 : url.port()); + m_http->get(urlstring); + m_httpRequestOngoing = true; + } else { + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + msgBox.setText("QHttp not created.\nCreate QHttp First."); + msgBox.exec(); + } +} + +void SessionTab::on_openSessionButton_clicked() +{ + m_NetworkSession->open(); + if (m_NetworkSession->isOpen()) { + newState(m_NetworkSession->state()); + } +} + +void SessionTab::on_closeSessionButton_clicked() +{ + m_NetworkSession->close(); + if (!m_NetworkSession->isOpen()) { + newState(m_NetworkSession->state()); + } +} + +void SessionTab::on_stopConnectionButton_clicked() +{ + m_NetworkSession->stop(); +} + +void SessionTab::on_alrButton_clicked() +{ + if (!m_alrEnabled) { + connect(m_NetworkSession, SIGNAL(preferredConfigurationChanged(const QNetworkConfiguration&, bool)), + this, SLOT(preferredConfigurationChanged(const QNetworkConfiguration&, bool))); + alrButton->setText("Disable ALR"); + m_alrEnabled = true; + } else { + disconnect(m_NetworkSession, SIGNAL(preferredConfigurationChanged(const QNetworkConfiguration&, bool)), 0, 0); + alrButton->setText("Enable ALR"); + m_alrEnabled = false; + } +} + +void SessionTab::on_deleteSessionButton_clicked() +{ + setWindowTitle("Bearer Example"); + delete this; +} + +void SessionTab::newConfigurationActivated() +{ + QMessageBox msgBox; + msgBox.setText("New configuration activated."); + msgBox.setInformativeText("Do you want to accept new configuration?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + if (msgBox.exec() == QMessageBox::Yes) { + m_NetworkSession->accept(); + iapLineEdit->setText(m_config.name()+" ("+m_config.identifier()+")"); + } else { + m_NetworkSession->reject(); + } +} + +void SessionTab::preferredConfigurationChanged(const QNetworkConfiguration& config, bool /*isSeamless*/) +{ + m_config = config; + QMessageBox msgBox; + msgBox.setText("Roaming to new configuration."); + msgBox.setInformativeText("Do you want to migrate to "+config.name()+"?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + if (msgBox.exec() == QMessageBox::Yes) { + m_NetworkSession->migrate(); + } else { + m_NetworkSession->ignore(); + } +} + +void SessionTab::opened() +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + listItem->setFont(font); + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+QString("Opened")); + m_eventListWidget->addItem(listItem); + + QVariant identifier = m_NetworkSession->property("ActiveConfiguration"); + if (!identifier.isNull()) { + QString configId = identifier.toString(); + QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); + if (config.isValid()) { + iapLineEdit->setText(config.name()+" ("+config.identifier()+")"); + } + } + + if (m_NetworkSession->configuration().type() == QNetworkConfiguration::UserChoice) { + QVariant identifier = m_NetworkSession->property("UserChoiceConfiguration"); + if (!identifier.isNull()) { + QString configId = identifier.toString(); + QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); + if (config.isValid() && (config.type() == QNetworkConfiguration::ServiceNetwork)) { + snapLineEdit->setText(config.name()); + } + } + } +} + +void SessionTab::closed() +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + listItem->setFont(font); + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+QString("Closed")); + m_eventListWidget->addItem(listItem); +} + +QString SessionTab::stateString(QNetworkSession::State state) +{ + QString stateString; + switch (state) + { + case QNetworkSession::Invalid: + stateString = "Invalid"; + break; + case QNetworkSession::NotAvailable: + stateString = "NotAvailable"; + break; + case QNetworkSession::Connecting: + stateString = "Connecting"; + break; + case QNetworkSession::Connected: + stateString = "Connected"; + break; + case QNetworkSession::Closing: + stateString = "Closing"; + break; + case QNetworkSession::Disconnected: + stateString = "Disconnected"; + break; + case QNetworkSession::Roaming: + stateString = "Roaming"; + break; + } + return stateString; +} + +void SessionTab::stateChanged(QNetworkSession::State state) +{ + newState(state); + + QListWidgetItem* listItem = new QListWidgetItem(); + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+stateString(state)); + m_eventListWidget->addItem(listItem); +} + +void SessionTab::newState(QNetworkSession::State state) +{ + QVariant identifier = m_NetworkSession->property("ActiveConfiguration"); + if (state == QNetworkSession::Connected && !identifier.isNull()) { + QString configId = identifier.toString(); + QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); + if (config.isValid()) { + iapLineEdit->setText(config.name()+" ("+config.identifier()+")"); + bearerLineEdit->setText(config.bearerName()); + } + } else { + bearerLineEdit->setText(m_NetworkSession->configuration().bearerName()); + } + + QString active; + if (m_NetworkSession->isOpen()) { + active = " (O)"; + } + stateLineEdit->setText(stateString(state)+active); +} + +void SessionTab::error(QNetworkSession::SessionError error) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + + QString errorString; + switch (error) + { + case QNetworkSession::UnknownSessionError: + errorString = "UnknownSessionError"; + break; + case QNetworkSession::SessionAbortedError: + errorString = "SessionAbortedError"; + break; + case QNetworkSession::RoamingError: + errorString = "RoamingError"; + break; + case QNetworkSession::OperationNotSupportedError: + errorString = "OperationNotSupportedError"; + break; + case QNetworkSession::InvalidConfigurationError: + errorString = "InvalidConfigurationError"; + break; + } + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+errorString); + m_eventListWidget->addItem(listItem); + + msgBox.setText(errorString); + msgBox.exec(); +} + +void SessionTab::done(bool error) +{ + m_httpRequestOngoing = false; + + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + if (error) { + msgBox.setText("HTTP request failed."); + } else { + QString result(m_http->readAll()); + 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())); +} + +// End of file + diff --git a/tests/manual/bearerex/bearerex.h b/tests/manual/bearerex/bearerex.h new file mode 100644 index 0000000..2875d6a --- /dev/null +++ b/tests/manual/bearerex/bearerex.h @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $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 ACCESSPOINTMANAGEREX_H +#define ACCESSPOINTMANAGEREX_H + +#include <QtGui> + +#include "ui_bearerex.h" +#include "ui_detailedinfodialog.h" +#include "ui_sessiondialog.h" + +#include "qnetworkconfigmanager.h" +#include "qnetworksession.h" +#include "xqlistwidget.h" + +QT_BEGIN_NAMESPACE +class QHttp; +QT_END_NAMESPACE + +class SessionTab; + +QT_USE_NAMESPACE + +class BearerEx : public QMainWindow, public Ui::BearerExMainWindow +{ + Q_OBJECT + +public: + BearerEx(QWidget* parent = 0); + void createMenus(); + void showConfigurations(); + +private Q_SLOTS: + void on_updateConfigurationsButton_clicked(); + void on_updateListButton_clicked(); + void on_showDetailsButton_clicked(); + void on_createSessionButton_clicked(); + void on_clearEventListButton_clicked(); + + void configurationsUpdateCompleted(); + void configurationAdded(const QNetworkConfiguration& config); + void configurationRemoved(const QNetworkConfiguration& config); + void onlineStateChanged(bool isOnline); + void configurationChanged(const QNetworkConfiguration & config); + +private: + QNetworkConfigurationManager m_NetworkConfigurationManager; + QAction* m_openAction; +}; + +class DetailedInfoDialog : public QDialog, public Ui::DetailedInfoDialog +{ + Q_OBJECT + +public: + DetailedInfoDialog(QNetworkConfiguration* apNetworkConfiguration = 0, QWidget* parent = 0); +}; + + +class SessionTab : public QWidget, public Ui::SessionTab +{ + Q_OBJECT + +public: + SessionTab(QNetworkConfiguration* apNetworkConfiguration = 0, QNetworkConfigurationManager* configManager = 0, + QListWidget* eventListWidget = 0, int index = 0, BearerEx* parent = 0); + ~SessionTab(); + + QString stateString(QNetworkSession::State state); + +private Q_SLOTS: + void on_createQHttpButton_clicked(); + void on_sendRequestButton_clicked(); + void on_openSessionButton_clicked(); + void on_closeSessionButton_clicked(); + void on_stopConnectionButton_clicked(); + void on_deleteSessionButton_clicked(); + void on_alrButton_clicked(); + void done(bool error); + + void newConfigurationActivated(); + void preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless); + void stateChanged(QNetworkSession::State state); + void newState(QNetworkSession::State state); + void opened(); + void closed(); + void error(QNetworkSession::SessionError error); + +private: //data + QHttp* m_http; + QNetworkSession* m_NetworkSession; + QNetworkConfigurationManager* m_ConfigManager; + QListWidget* m_eventListWidget; + QNetworkConfiguration m_config; + int m_index; + bool m_httpRequestOngoing; + bool m_alrEnabled; +}; + +#endif // ACCESSPOINTMANAGEREX_H + +// End of file + diff --git a/tests/manual/bearerex/bearerex.pro b/tests/manual/bearerex/bearerex.pro new file mode 100644 index 0000000..927f982 --- /dev/null +++ b/tests/manual/bearerex/bearerex.pro @@ -0,0 +1,20 @@ +TEMPLATE = app +TARGET = BearerEx + +QT += core \ + gui \ + network + +FORMS += sessiondialog.ui \ + bearerex.ui \ + detailedinfodialog.ui + +# Example headers and sources +HEADERS += bearerex.h \ + xqlistwidget.h + +SOURCES += bearerex.cpp \ + main.cpp \ + xqlistwidget.cpp + +symbian:TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData
\ No newline at end of file diff --git a/tests/manual/bearerex/bearerex.ui b/tests/manual/bearerex/bearerex.ui new file mode 100644 index 0000000..e5ab62f --- /dev/null +++ b/tests/manual/bearerex/bearerex.ui @@ -0,0 +1,95 @@ +<ui version="4.0" > + <class>BearerExMainWindow</class> + <widget class="QMainWindow" name="BearerExMainWindow" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>360</width> + <height>640</height> + </rect> + </property> + <property name="windowTitle" > + <string>Bearer Example</string> + </property> + <widget class="QWidget" name="centralwidget" > + <layout class="QVBoxLayout" name="verticalLayout" > + <item> + <widget class="QTabWidget" name="mainTabWidget" > + <widget class="QWidget" name="tab" > + <attribute name="title" > + <string>Main</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_2" > + <item> + <widget class="QLabel" name="label" > + <property name="text" > + <string>Network Configurations</string> + </property> + <property name="alignment" > + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QListWidget" name="listWidget" /> + </item> + <item> + <layout class="QGridLayout" name="gridLayout" > + <item row="0" column="0" > + <widget class="QPushButton" name="updateConfigurationsButton" > + <property name="text" > + <string>Update Configs</string> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QPushButton" name="updateListButton" > + <property name="text" > + <string>Update List</string> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QPushButton" name="createSessionButton" > + <property name="text" > + <string>Create Session</string> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QPushButton" name="showDetailsButton" > + <property name="text" > + <string>Show Details</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <widget class="QWidget" name="tab_2" > + <attribute name="title" > + <string>Events</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_3" > + <item> + <widget class="QListWidget" name="eventListWidget" /> + </item> + <item> + <widget class="QPushButton" name="clearEventListButton" > + <property name="text" > + <string>Clear</string> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/manual/bearerex/detailedinfodialog.ui b/tests/manual/bearerex/detailedinfodialog.ui new file mode 100644 index 0000000..c4a21fa --- /dev/null +++ b/tests/manual/bearerex/detailedinfodialog.ui @@ -0,0 +1,54 @@ +<ui version="4.0" > + <class>DetailedInfoDialog</class> + <widget class="QDialog" name="DetailedInfoDialog" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>308</width> + <height>396</height> + </rect> + </property> + <property name="windowTitle" > + <string>Bearer Example</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout" > + <item> + <widget class="QLabel" name="label" > + <property name="text" > + <string>Detailed information</string> + </property> + </widget> + </item> + <item> + <widget class="QTableWidget" name="tableWidget" /> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox" > + <property name="standardButtons" > + <set>QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>DetailedInfoDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel" > + <x>205</x> + <y>371</y> + </hint> + <hint type="destinationlabel" > + <x>223</x> + <y>8</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/tests/manual/bearerex/main.cpp b/tests/manual/bearerex/main.cpp new file mode 100644 index 0000000..20b167e --- /dev/null +++ b/tests/manual/bearerex/main.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $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 <QApplication> + +#include "bearerex.h" + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + BearerEx bearerEx; +#ifdef Q_OS_SYMBIAN + bearerEx.showMaximized(); +#else + bearerEx.show(); +#endif + return app.exec(); +} + +// End of file + diff --git a/tests/manual/bearerex/sessiondialog.ui b/tests/manual/bearerex/sessiondialog.ui new file mode 100644 index 0000000..fcf2136 --- /dev/null +++ b/tests/manual/bearerex/sessiondialog.ui @@ -0,0 +1,139 @@ +<ui version="4.0" > + <class>SessionTab</class> + <widget class="QWidget" name="SessionTab" > + <layout class="QVBoxLayout" name="verticalLayout" > + <item> + <layout class="QFormLayout" name="formLayout" > + <item row="0" column="0" > + <widget class="QLabel" name="snapLabel" > + <property name="text" > + <string>SNAP</string> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QLineEdit" name="snapLineEdit" > + <property name="readOnly" > + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="iapLabel" > + <property name="text" > + <string>IAP</string> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QLineEdit" name="iapLineEdit" > + <property name="enabled" > + <bool>true</bool> + </property> + <property name="readOnly" > + <bool>true</bool> + </property> + </widget> + </item> + <item row="2" column="0" > + <widget class="QLabel" name="bearerLabel" > + <property name="text" > + <string>Bearer</string> + </property> + </widget> + </item> + <item row="2" column="1" > + <widget class="QLineEdit" name="bearerLineEdit" > + <property name="readOnly" > + <bool>true</bool> + </property> + </widget> + </item> + <item row="3" column="0" > + <widget class="QLabel" name="sentRecDataLabel" > + <property name="text" > + <string>Sent/Rec.</string> + </property> + </widget> + </item> + <item row="3" column="1" > + <widget class="QLineEdit" name="sentRecDataLineEdit" > + <property name="readOnly" > + <bool>true</bool> + </property> + </widget> + </item> + <item row="4" column="0" > + <widget class="QLabel" name="stateLabel" > + <property name="text" > + <string>State</string> + </property> + </widget> + </item> + <item row="4" column="1" > + <widget class="QLineEdit" name="stateLineEdit" > + <property name="readOnly" > + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QGridLayout" name="gridLayout" > + <item row="0" column="0" > + <widget class="QPushButton" name="openSessionButton" > + <property name="text" > + <string>Open Session</string> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QPushButton" name="closeSessionButton" > + <property name="text" > + <string>Close Session</string> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QPushButton" name="stopConnectionButton" > + <property name="text" > + <string>Stop Conn.</string> + </property> + </widget> + </item> + <item row="2" column="0" > + <widget class="QPushButton" name="createQHttpButton" > + <property name="text" > + <string>Create QHttp</string> + </property> + </widget> + </item> + <item row="2" column="1" > + <widget class="QPushButton" name="sendRequestButton" > + <property name="text" > + <string>Send Test Req.</string> + </property> + </widget> + </item> + <item row="3" column="0" > + <widget class="QPushButton" name="alrButton" > + <property name="text" > + <string>Enable ALR</string> + </property> + </widget> + </item> + <item row="3" column="1" > + <widget class="QPushButton" name="deleteSessionButton" > + <property name="text" > + <string>Delete Session</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/manual/bearerex/xqlistwidget.cpp b/tests/manual/bearerex/xqlistwidget.cpp new file mode 100644 index 0000000..8104779 --- /dev/null +++ b/tests/manual/bearerex/xqlistwidget.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $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 "xqlistwidget.h" + +XQListWidget::XQListWidget(QWidget* parent) : QListWidget(parent) +{ +} + +void XQListWidget::keyPressEvent(QKeyEvent* event) +{ + switch (event->key()) + { + case Qt::Key_Left: + { + focusPreviousChild(); + break; + } + case Qt::Key_Right: + { + focusNextChild(); + break; + } + default: + { + QListWidget::keyPressEvent(event); + } + } +} diff --git a/tests/manual/bearerex/xqlistwidget.h b/tests/manual/bearerex/xqlistwidget.h new file mode 100644 index 0000000..0649c2b --- /dev/null +++ b/tests/manual/bearerex/xqlistwidget.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $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 XQLISTWIDGET_H +#define XQLISTWIDGET_H + +#include <QListWidget> +#include <QKeyEvent> + +class XQListWidget: public QListWidget +{ +public: + XQListWidget(QWidget* parent = 0); + +protected: + void keyPressEvent(QKeyEvent* event); +}; + +#endif // XQLISTWIDGET_H + + diff --git a/tests/manual/networkmanager/README b/tests/manual/networkmanager/README new file mode 100644 index 0000000..4bc7171 --- /dev/null +++ b/tests/manual/networkmanager/README @@ -0,0 +1,2 @@ +This application serves as prototype/test-bed for NetworkManager development. The excellent (non-existing) documentation +for the various NetworkManager interfaces makes this harder than it should be. diff --git a/tests/manual/networkmanager/dialog.ui b/tests/manual/networkmanager/dialog.ui new file mode 100644 index 0000000..1301908 --- /dev/null +++ b/tests/manual/networkmanager/dialog.ui @@ -0,0 +1,213 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Dialog</class> + <widget class="QDialog" name="Dialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>919</width> + <height>657</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Connections</string> + </property> + </widget> + </item> + <item> + <widget class="QTreeWidget" name="cons"> + <column> + <property name="text"> + <string>Path</string> + </property> + </column> + <column> + <property name="text"> + <string>State</string> + </property> + </column> + <column> + <property name="text"> + <string>Id</string> + </property> + </column> + <column> + <property name="text"> + <string>Settings</string> + </property> + </column> + </widget> + </item> + </layout> + </item> + <item row="1" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Devices:</string> + </property> + </widget> + </item> + <item> + <widget class="QTreeWidget" name="devicesTreeWidget"> + <column> + <property name="text"> + <string>Path</string> + </property> + </column> + <column> + <property name="text"> + <string>Managed</string> + </property> + </column> + <column> + <property name="text"> + <string>Interface</string> + </property> + </column> + <column> + <property name="text"> + <string>Driver</string> + </property> + </column> + <column> + <property name="text"> + <string>Type</string> + </property> + </column> + <column> + <property name="text"> + <string>State</string> + </property> + </column> + <column> + <property name="text"> + <string>IP4 Address</string> + </property> + </column> + <column> + <property name="text"> + <string>IP4 Config</string> + </property> + </column> + <column> + <property name="text"> + <string>Hostname</string> + </property> + </column> + <column> + <property name="text"> + <string>Domains</string> + </property> + </column> + </widget> + </item> + </layout> + </item> + <item row="2" column="0"> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>908</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="3" column="0"> + <widget class="QTreeWidget" name="accessPointsTreeWidget"> + <property name="sortingEnabled"> + <bool>true</bool> + </property> + <column> + <property name="text"> + <string>SSID</string> + </property> + </column> + <column> + <property name="text"> + <string>Strength</string> + </property> + </column> + <column> + <property name="text"> + <string>Wpa</string> + </property> + </column> + <column> + <property name="text"> + <string>Rsn</string> + </property> + </column> + <column> + <property name="text"> + <string>Freq</string> + </property> + </column> + <column> + <property name="text"> + <string>Hardware Address</string> + </property> + </column> + <column> + <property name="text"> + <string>Mode</string> + </property> + </column> + <column> + <property name="text"> + <string>Max Bitrate</string> + </property> + </column> + </widget> + </item> + <item row="4" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QPushButton" name="startButton"> + <property name="text"> + <string>Start</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="stopButton"> + <property name="text"> + <string>Stop</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="scanButton"> + <property name="text"> + <string>Scan</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="updateButton"> + <property name="text"> + <string>Update</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/manual/networkmanager/networkmanager.pro b/tests/manual/networkmanager/networkmanager.pro new file mode 100644 index 0000000..84289d3 --- /dev/null +++ b/tests/manual/networkmanager/networkmanager.pro @@ -0,0 +1,9 @@ +SOURCES += networkmanagertest.cpp nmview.cpp +HEADERS += nmview.h +TARGET = tst_networkmanagertest + +QT = core network dbus gui + +requires(contains(QT_CONFIG,dbus)) + +FORMS += dialog.ui diff --git a/tests/manual/networkmanager/networkmanagertest.cpp b/tests/manual/networkmanager/networkmanagertest.cpp new file mode 100644 index 0000000..8a6c5fa --- /dev/null +++ b/tests/manual/networkmanager/networkmanagertest.cpp @@ -0,0 +1,287 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $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 <QDBusConnection> +#include <QDBusError> +#include <QDBusInterface> +#include <QDBusMessage> +#include <QDBusReply> +#include <QtDBus> +#include <QHostAddress> +#include <QDebug> +#include <NetworkManager/NetworkManager.h> +#include <QApplication> +#include <QMainWindow> +#include "nmview.h" + +#include <arpa/inet.h> + +typedef QMap< QString, QMap<QString,QVariant> > SettingsMap; +Q_DECLARE_METATYPE(SettingsMap) + +void printConnectionDetails(const QString& service) +{ + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + QDBusInterface allCons(service, NM_DBUS_PATH_SETTINGS, NM_DBUS_IFACE_SETTINGS, dbc); + if (allCons.isValid()) { + QDBusReply<QList<QDBusObjectPath> > reply = allCons.call("ListConnections"); + if ( reply.isValid() ) { + qWarning() << "Known connections:"; + QList<QDBusObjectPath> list = reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() << " " << path.path(); + QDBusInterface sysIface(NM_DBUS_SERVICE_SYSTEM_SETTINGS, path.path(), NM_DBUS_IFACE_SETTINGS_CONNECTION, dbc); + if (sysIface.isValid()) { + QDBusMessage r = sysIface.call("GetSettings"); + QDBusReply< SettingsMap > rep = sysIface.call("GetSettings"); + qWarning() << " GetSettings:" << r.arguments() << r.signature() << rep.isValid() << sysIface.lastError(); + QMap< QString, QMap<QString,QVariant> > map = rep.value(); + QList<QString> list = map.keys(); + foreach (QString key, list) { + QMap<QString,QVariant> innerMap = map[key]; + qWarning() << " Key: " << key; + QMap<QString,QVariant>::const_iterator i = innerMap.constBegin(); + while (i != innerMap.constEnd()) { + QString k = i.key(); + qWarning() << " Key: " << k << " Entry: " << i.value(); + if (k == "addresses" && i.value().canConvert<QDBusArgument>()) { + QDBusArgument arg = i.value().value<QDBusArgument>(); + arg.beginArray(); + while (!arg.atEnd()) { + QDBusVariant addr; + arg >> addr; + uint ip = addr.variant().toUInt(); + qWarning() << ip; + qWarning() << " " << QHostAddress(htonl(ip)).toString(); + } + + } + i++; + } + } + } + } + } + } + + +} + +void readConnectionManagerDetails() +{ + qDBusRegisterMetaType<SettingsMap>(); + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + + QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + + uint state = iface.property("State").toUInt(); + switch(state) { + case NM_STATE_UNKNOWN: + qWarning() << "State: Unknown"; break; + case NM_STATE_ASLEEP: + qWarning() << "State: Asleep"; break; + case NM_STATE_CONNECTING: + qWarning() << "State: Connecting"; break; + case NM_STATE_CONNECTED: + qWarning() << "State: Connected"; break; + case NM_STATE_DISCONNECTED: + qWarning() << "State: Disconnected"; break; + } + //get list of network devices + QDBusReply<QList<QDBusObjectPath> > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { + qWarning() << "Current devices:"; + QList<QDBusObjectPath> list = reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() << " " << path.path(); + QDBusInterface devIface(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_DEVICE, dbc); + if (devIface.isValid()) { + qWarning() << " Managed: " << devIface.property("Managed").toBool(); + qWarning() << " Interface: " << devIface.property("Interface").toString(); + qWarning() << " HAL UDI: " << devIface.property("Udi").toString(); + qWarning() << " Driver: " << devIface.property("Driver").toString(); + QVariant v = devIface.property("DeviceType"); + switch(v.toUInt()) { + case DEVICE_TYPE_UNKNOWN: + qWarning() << " DeviceType: Unknown" ; + break; + case DEVICE_TYPE_802_3_ETHERNET: + qWarning() << " DeviceType: Ethernet" ; + break; + case DEVICE_TYPE_802_11_WIRELESS: + qWarning() << " DeviceType: Wireless" ; + break; + case DEVICE_TYPE_GSM: + qWarning() << " DeviceType: GSM" ; + break; + case DEVICE_TYPE_CDMA: + qWarning() << " DeviceType: CDMA" ; + break; + + } + v = devIface.property("State"); + switch(v.toUInt()) { + case NM_DEVICE_STATE_UNKNOWN: + qWarning() << " State: Unknown" ; break; + case NM_DEVICE_STATE_UNMANAGED: + qWarning() << " State: Unmanaged" ; break; + case NM_DEVICE_STATE_UNAVAILABLE: + qWarning() << " State: Unavailable" ; break; + case NM_DEVICE_STATE_DISCONNECTED: + qWarning() << " State: Disconnected" ; break; + case NM_DEVICE_STATE_PREPARE: + qWarning() << " State: Preparing" ; break; + case NM_DEVICE_STATE_CONFIG: + qWarning() << " State: Being configured" ; break; + case NM_DEVICE_STATE_NEED_AUTH: + qWarning() << " State: Awaiting secrets" ; break; + case NM_DEVICE_STATE_IP_CONFIG: + qWarning() << " State: IP requested" ; break; + case NM_DEVICE_STATE_ACTIVATED: + qWarning() << " State: Activated" ; break; + case NM_DEVICE_STATE_FAILED: + qWarning() << " State: FAILED" ; break; + } + quint32 ip = devIface.property("Ip4Address").toUInt(); + qWarning() << " IP4Address: " << QHostAddress(htonl(ip)).toString(); + if (v.toUInt() == NM_DEVICE_STATE_ACTIVATED) { + QString path = devIface.property("Ip4Config").value<QDBusObjectPath>().path(); + qWarning() << " IP4Config: " << path; + QDBusInterface ipIface(NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_IP4_CONFIG, dbc); + if (ipIface.isValid()) { + qWarning() << " Hostname: " << ipIface.property("Hostname").toString(); + qWarning() << " Domains: " << ipIface.property("Domains").toStringList(); + qWarning() << " NisDomain: " << ipIface.property("NisDomain").toString(); + QDBusArgument arg= ipIface.property("Addresses").value<QDBusArgument>(); + //qWarning() << " " << arg.currentType(); + qWarning() << " Addresses: " << ipIface.property("Addresses"); + qWarning() << " Nameservers: " << ipIface.property("Nameservers"); + qWarning() << " NisServers: " << ipIface.property("NisServers"); + } + + } + + } + } + } + + //get list of active connections + QVariant prop = iface.property("ActiveConnections"); + QList<QDBusObjectPath> connections = prop.value<QList<QDBusObjectPath> >(); + QString activePath; + if ( connections.count() ) + qWarning() << "Active connections:"; + foreach(QDBusObjectPath path, connections) { + qWarning() << " " << path.path(); + activePath = path.path(); + QString serviceName; + QDBusInterface conIface(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_ACTIVE_CONNECTION, dbc); + if (conIface.isValid()) { + qWarning() << " default connection: " << conIface.property("Default").toBool(); + serviceName = conIface.property("ServiceName").toString(); + qWarning() << " service name: " << serviceName; + qWarning() << " connection path: " << conIface.property("Connection").value<QDBusObjectPath>().path(); + qWarning() << " specific object:" << conIface.property("SpecificObject").value<QDBusObjectPath>().path(); + qWarning() << " sharedServiceName: " << conIface.property("SharedServiceName").toString(); + QList<QDBusObjectPath> devs = conIface.property("Devices").value<QList<QDBusObjectPath> >(); + qWarning() << " devices: "; + foreach(QDBusObjectPath p, devs) + qWarning() << " " << path.path(); + QVariant v = conIface.property("State"); + switch (v.toInt()) { + case NM_ACTIVE_CONNECTION_STATE_UNKNOWN: + qWarning()<< " State: unknown"; break; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATING: + qWarning()<< " State: activating"; break; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATED: + qWarning()<< " State: activated"; break; + } + } else { + qWarning() << conIface.lastError(); + } + + } + + printConnectionDetails(NM_DBUS_SERVICE_SYSTEM_SETTINGS); + printConnectionDetails(NM_DBUS_SERVICE_USER_SETTINGS); + + + //turn active connection off + /*QDBusObjectPath dbop("/org/freedesktop/NetworkManager/ActiveConnection/1"); + QVariant asd = QVariant::fromValue(dbop); + iface.call(QLatin1String("DeactivateConnection"), asd); + qWarning() << iface.lastError();*/ + + /*QDBusObjectPath p1device("/org/freedesktop/Hal/devices/net_00_60_6e_82_02_65"); + QVariant p1v = QVariant::fromValue(p1device); + QDBusObjectPath p1con("/org/freedesktop/NetworkManagerSettings/0"); + QVariant p1c = QVariant::fromValue(p1con); + QDBusObjectPath p1sp(""); + QVariant p1sp1 = QVariant::fromValue(p1sp); + iface.call(QLatin1String("ActivateConnection"), + QString("/org/freedesktop/NetworkManagerSystemSettings"), p1c,p1v, p1v ); + qWarning() << iface.lastError(); + */ +} + +int main( int argc, char** argv) +{ + QApplication app(argc, argv); + //readConnectionManagerDetails(); + QMainWindow main; + NMView view; + main.setCentralWidget(&view); + main.show(); + return app.exec(); + +} diff --git a/tests/manual/networkmanager/nmview.cpp b/tests/manual/networkmanager/nmview.cpp new file mode 100644 index 0000000..9e28ff0 --- /dev/null +++ b/tests/manual/networkmanager/nmview.cpp @@ -0,0 +1,1028 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $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 "nmview.h" + +#include <QLabel> +#include <QLayout> +#include <QListWidget> +#include <QDebug> +#include <QPushButton> + +#include <QtDBus> +#include <QtNetwork> +#include <NetworkManager/NetworkManager.h> +#include <arpa/inet.h> + +#include <QDBusConnection> +#include <QDBusError> +#include <QDBusInterface> +#include <QDBusMessage> +#include <QDBusReply> + +#include <QHostAddress> +#include <QNetworkInterface> +#include <QTreeWidgetItem> +#include <QMessageBox> + +//#include "ui_dialog.h" + +#include <qnetworkconfiguration.h> +#include <qnetworkconfigmanager.h> +#include <qnetworksession.h> +#include <QtNetwork/private/qnetworkmanagerservice_p.h> + +//static QDBusConnection dbc = QDBusConnection::systemBus(); +//typedef QMap< QString, QMap<QString,QVariant> > SettingsMap; +//Q_DECLARE_METATYPE(SettingsMap) + + +NMView::NMView(QDialog* parent) + : QDialog(parent, 0), dbc(QDBusConnection::systemBus()) +{ + init(); + + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + updateConnections(); + getDevices(); +} + +NMView::~NMView() +{ +} +void NMView::init() +{ + setupUi(this); + sess = 0; +// readSettings(); + connect(startButton, SIGNAL(clicked()), this, SLOT(activate())); + connect(stopButton, SIGNAL(clicked()), this, SLOT(deactivate())); + connect(scanButton, SIGNAL(clicked()), this, SLOT(findAccessPoints())); + connect(updateButton, SIGNAL(clicked()), this, SLOT(update())); + + connect(cons, SIGNAL(itemActivated(QTreeWidgetItem*, int)), + this,SLOT(connectionItemActivated(QTreeWidgetItem*, int))); + + + connect(devicesTreeWidget, SIGNAL(itemActivated(QTreeWidgetItem*, int)), + this, SLOT(deviceItemActivated(QTreeWidgetItem*, int))); + + cons->header()->setResizeMode(QHeaderView::ResizeToContents); + devicesTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); + accessPointsTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); +// accessPointsTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); + + manager = new QNetworkConfigurationManager(this); + + connect(manager, SIGNAL(updateCompleted()), this, SLOT(updateCompleted())); + + connect(manager, SIGNAL(configurationAdded(const QNetworkConfiguration &)), + this, SLOT(configurationAdded(const QNetworkConfiguration&))); + + devicesTreeWidget->header()->hideSection(0); + devicesTreeWidget->header()->hideSection(1); + devicesTreeWidget->header()->hideSection(3); + devicesTreeWidget->header()->hideSection(5); + devicesTreeWidget->header()->hideSection(6); + devicesTreeWidget->header()->hideSection(7); + devicesTreeWidget->header()->hideSection(8); + devicesTreeWidget->header()->hideSection(9); +} + +void NMView::updateConnections() +{ + cons->clear(); + manager->updateConfigurations(); + QList<QNetworkConfiguration> configs = manager->allConfigurations(); + foreach(QNetworkConfiguration p, configs) { + QStringList strlist; + strlist << p.name(); + strlist << stateToString(p.state()); + strlist << p.identifier(); + strlist << typeToString(p.type()); + QTreeWidgetItem *item; + item = new QTreeWidgetItem(strlist); + cons->insertTopLevelItem(0, item); + } + cons->sortItems ( 1, Qt::AscendingOrder); +} + +void NMView::getActiveConnections() +{ + QList<QNetworkConfiguration> configs = manager->allConfigurations(QNetworkConfiguration::Active); + foreach(QNetworkConfiguration p, configs) { + qWarning() << __FUNCTION__ << p.name() << p.identifier(); + } + +// QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); +// if (!iface.isValid()) { +// qWarning() << "Could not find NetworkManager"; +// return; +// } + +// QVariant prop = iface.property("ActiveConnections"); +// QList<QDBusObjectPath> connections = prop.value<QList<QDBusObjectPath> >(); +// foreach(QDBusObjectPath path, connections) { +// QDBusInterface conDetails(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_ACTIVE_CONNECTION, dbc); +// if (conDetails.isValid()) { +// QString desc = path.path(); +// conDetails.property("Connection Path").value<QDBusObjectPath>().path(); + +// QList<QDBusObjectPath> devices = conDetails.property("Devices").value<QList<QDBusObjectPath> >(); +// +// foreach(QDBusObjectPath devpath, devices) { +// QDBusInterface devIface(NM_DBUS_SERVICE, devpath.path(), NM_DBUS_INTERFACE_DEVICE, dbc); +// desc += " "+devIface.property("Interface").toString(); +// desc += " "+QHostAddress(htonl(devIface.property("Ip4Address").toUInt())).toString(); + +// } + +// qWarning() << conDetails.property("Connection").value<QDBusObjectPath>().path() << path.path(); + +// QListWidgetItem* item = new QListWidgetItem(desc, activeCons); +// item->setData(Qt::UserRole, path.path()); +// } +// } +} + +void NMView::update() +{ +// QNetworkManagerInterface *dbIface; +// dbIface = new QNetworkManagerInterface; +// QList <QDBusObjectPath> connections = dbIface->activeConnections(); +// +// foreach(QDBusObjectPath conpath, connections) { +// QNetworkManagerConnectionActive *aConn; +// aConn = new QNetworkManagerConnectionActive(conpath.path()); +// // in case of accesspoint, specificObject will hold the accessPOintObjectPath +// qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); +// QList <QDBusObjectPath> devs = aConn->devices(); +// foreach(QDBusObjectPath device, devs) { +// qWarning() << " " << device.path(); +// } +// } + + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + foreach (QString service, connectionServices) { + QDBusInterface allCons(service, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, + dbc); + if (allCons.isValid()) { + QDBusReply<QList<QDBusObjectPath> > reply = allCons.call("ListConnections"); + if ( reply.isValid() ) { + QList<QDBusObjectPath> list = reply.value(); + foreach(QDBusObjectPath path, list) { + QDBusInterface sysIface(service, + path.path(), + NM_DBUS_IFACE_SETTINGS_CONNECTION, + dbc); + if (sysIface.isValid()) { + qWarning() << ""; + qWarning() << path.path(); + + // QDBusMessage r = sysIface.call("GetSettings"); + QDBusReply< QNmSettingsMap > rep = sysIface.call("GetSettings"); + + QMap< QString, QMap<QString,QVariant> > map = rep.value(); + QList<QString> list = map.keys(); + foreach (QString key, list) { + QMap<QString,QVariant> innerMap = map[key]; + qWarning() << " Key: " << key; + QMap<QString,QVariant>::const_iterator i = innerMap.constBegin(); + + while (i != innerMap.constEnd()) { + QString k = i.key(); + qWarning() << " Key: " << k << " Entry: " << i.value(); + i++; + }//end innerMap + }//end foreach key + }//end settings connection + } // foreach path + } //end ListConnections + } //end settingsInterface + }// end services + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); + if (iface.isValid()) { + QVariant prop = iface.property("ActiveConnections"); + QList<QDBusObjectPath> connections = prop.value<QList<QDBusObjectPath> >(); + foreach(QDBusObjectPath conpath, connections) { + qWarning() << "Active connection" << conpath.path(); + QDBusInterface conDetails(NM_DBUS_SERVICE, + conpath.path(), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbc); + if (conDetails.isValid()) { + + QVariant prop = conDetails.property("Connection"); + QDBusObjectPath connection = prop.value<QDBusObjectPath>(); + qWarning() << conDetails.property("Default").toBool() << connection.path(); + +// QVariant Sprop = conDetails.property("Devices"); +// QList<QDBusObjectPath> so = Sprop.value<QList<QDBusObjectPath> >(); +// foreach(QDBusObjectPath device, so) { +// if(device.path() == devicePath) { +// path = connection.path(); +// } +// break; +// } + } + } + } +qWarning() << ""; +} + +void NMView::deactivate() +{ + QList<QNetworkConfiguration> configs = manager->allConfigurations(QNetworkConfiguration::Active); + foreach(QNetworkConfiguration p, configs) { + qWarning() << "Active cons" << p.name(); + if(p.name() == cons->currentItem()->text(0) + && p.identifier() == cons->currentItem()->text(2)) { + qWarning() <<__FUNCTION__<< p.name(); + if(!sess) { + sess = new QNetworkSession(p); + + connect(sess, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + + connect(sess, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(networkSessionError(QNetworkSession::SessionError))); + } + sess->close(); + delete sess; + sess = 0; + } + } +} + +void NMView::activate() +{ + qWarning() << __FUNCTION__ << cons->currentItem()->text(0); + + QList<QNetworkConfiguration> configs = manager->allConfigurations(); + foreach(QNetworkConfiguration p, configs) { + if(p.name() == cons->currentItem()->text(0)) { + + sess = new QNetworkSession(p); + + connect(sess, SIGNAL(newConfigurationActivated()), + this, SLOT(getActiveConnections())); + + connect(sess, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + + connect(sess, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(networkSessionError(QNetworkSession::SessionError))); + + sess->open(); + } + } +} + +void NMView::getDevices() +{ + qWarning() << ""; + qWarning() << __FUNCTION__; + devicesTreeWidget->clear(); + //qDBusRegisterMetaType<SettingsMap>(); + + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); +//NetworkManager interface + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + +// uint state = iface.property("State").toUInt(); +// switch(state) { +// case NM_STATE_UNKNOWN: +// qWarning() << "State: Unknown"; break; +// case NM_STATE_ASLEEP: +// qWarning() << "State: Asleep"; break; +// case NM_STATE_CONNECTING: +// qWarning() << "State: Connecting"; break; +// case NM_STATE_CONNECTED: +// qWarning() << "State: Connected"; break; +// case NM_STATE_DISCONNECTED: +// qWarning() << "State: Disconnected"; break; +// } + + //get list of network devices + QTreeWidgetItem *item; + QDBusReply<QList<QDBusObjectPath> > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { +// qWarning() << "Current devices:"; + QList<QDBusObjectPath> list = reply.value(); + foreach(QDBusObjectPath path, list) { + QStringList devicesList; + qWarning() << " " << path.path(); + devicesList << path.path(); + + QDBusInterface devIface(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_DEVICE, + dbc); + if (devIface.isValid()) { + + + + ////// connect the dbus signal +// /*if(*/dbc.connect(NM_DBUS_SERVICE, +// path.path(), +// NM_DBUS_INTERFACE_DEVICE, +// "StateChanged", +// this,SLOT(deviceStateChanged(quint32))); +// { +// qWarning() << "XXXXXXXXXX dbus connect successful" << path.path(); +// } + + + // qWarning() << " Managed: " << devIface.property("Managed").toBool(); + devicesList << devIface.property("Managed").toString(); + // qWarning() << " Interface: " << devIface.property("Interface").toString(); + devicesList << devIface.property("Interface").toString(); + // qWarning() << " HAL UDI: " << devIface.property("Udi").toString(); + // qWarning() << " Driver: " << devIface.property("Driver").toString(); + devicesList << devIface.property("Driver").toString(); + + QString x = deviceTypeToString(devIface.property("DeviceType").toUInt()); + // qWarning() << " Type:" << x; + devicesList << x; + + if( devIface.property("DeviceType").toUInt() == DEVICE_TYPE_802_11_WIRELESS) { + qWarning() << "Device is WIFI"; + // // findAccessPoints(path.path()); + } + + QVariant v = devIface.property("State"); + x = deviceStateToString(v.toUInt()); +// qWarning() << " State:" << x; + devicesList << x; + + quint32 ip = devIface.property("Ip4Address").toUInt(); +// qWarning() << " IP4Address: " << QHostAddress(htonl(ip)).toString(); + devicesList << QHostAddress(htonl(ip)).toString(); + + + if (v.toUInt() == NM_DEVICE_STATE_ACTIVATED) { + QString path = devIface.property("Ip4Config").value<QDBusObjectPath>().path(); +// qWarning() << " IP4Config: " << path; + devicesList << path; + QDBusInterface ipIface(NM_DBUS_SERVICE, + path, + NM_DBUS_INTERFACE_IP4_CONFIG, + dbc); + if (ipIface.isValid()) { + // qWarning() << " Hostname: " << ipIface.property("Hostname").toString(); + devicesList << ipIface.property("Hostname").toString(); +// qWarning() << " Domains: " << ipIface.property("Domains").toStringList(); + devicesList << ipIface.property("Domains").toStringList().join(", "); +// qWarning() << " NisDomain: " << ipIface.property("NisDomain").toString(); + QDBusArgument arg= ipIface.property("Addresses").value<QDBusArgument>(); +// qWarning() << " Addresses: " << ipIface.property("Addresses"); +// qWarning() << " Nameservers: " << ipIface.property("Nameservers"); +// qWarning() << " NisServers: " << ipIface.property("NisServers"); + } + + } + + } + item = new QTreeWidgetItem(devicesList); + devicesTreeWidget->insertTopLevelItem(0, item); + } + } + + +// netconfig(); + +} + +void NMView::readSettings() +{ + QDBusInterface settingsiface(NM_DBUS_SERVICE_SYSTEM_SETTINGS, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, + dbc); + //NetworkManagerSettings interface + if (settingsiface.isValid()) { + QDBusReply<QList<QDBusObjectPath> > reply = settingsiface.call("ListConnections"); + if ( reply.isValid() ) { + QList<QDBusObjectPath> list = reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() <<__FUNCTION__ << path.path(); + + } + } + } + + QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + + // QStringList list = item->text().split(" -> "); + + QVariant prop = iface.property("ActiveConnections"); + QList<QDBusObjectPath> connections = prop.value<QList<QDBusObjectPath> >(); + foreach(QDBusObjectPath path, connections) { + QDBusInterface conDetails(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbc); + + if (conDetails.isValid()) { + QString desc = path.path(); + qWarning() << desc; + //if ( item->text(0) == conDetails.property("Connection").value<QDBusObjectPath>().path() ) { + // QListWidgetItem* item = new QTreeWidgetItem( desc, + // cons); + // item->setData(Qt::UserRole, desc); + // activeItemActivated( item ); + //} + } + } +} + +void NMView::printConnectionDetails(const QString& service) +{ + Q_UNUSED(service); + +// +// qWarning() << __FUNCTION__ << service; +// +// QDBusConnection dbc = QDBusConnection::systemBus(); +// if (!dbc.isConnected()) { +// qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); +// return; +// } +// QDBusInterface allCons(service, +// NM_DBUS_PATH_SETTINGS, +// NM_DBUS_IFACE_SETTINGS, +// dbc); +// +// if (allCons.isValid()) { +// QDBusReply<QList<QDBusObjectPath> > reply = allCons.call("ListConnections"); +// +// if ( reply.isValid() ) { +// qWarning() << "Known connections:"; +// QList<QDBusObjectPath> list = reply.value(); +// +// foreach(QDBusObjectPath path, list) { +// qWarning() << " " << path.path(); +// +// QDBusInterface sysIface(NM_DBUS_SERVICE_SYSTEM_SETTINGS, +// path.path(), +// NM_DBUS_IFACE_SETTINGS_CONNECTION, +// dbc); +// +// if (sysIface.isValid()) { +// QDBusMessage r = sysIface.call("GetSettings"); +// QDBusReply< QSettingsMap > rep = sysIface.call("GetSettings"); +// +// qWarning() << " GetSettings:" << r.arguments() << r.signature() << rep.isValid() << sysIface.lastError(); +// +// QMap< QString, QMap<QString,QVariant> > map = rep.value(); +// QList<QString> list = map.keys(); +// +// foreach (QString key, list) { +// QMap<QString,QVariant> innerMap = map[key]; +// qWarning() << " Key: " << key; +// QMap<QString,QVariant>::const_iterator i = innerMap.constBegin(); +// +// while (i != innerMap.constEnd()) { +// QString k = i.key(); +// qWarning() << " Key: " << k << " Entry: " << i.value(); +// +// if (k == "addresses" && i.value().canConvert<QDBusArgument>()) { +// QDBusArgument arg = i.value().value<QDBusArgument>(); +// arg.beginArray(); +// +// while (!arg.atEnd()) { +// QDBusVariant addr; +// arg >> addr; +// uint ip = addr.variant().toUInt(); +// qWarning() << ip; +// qWarning() << " " << QHostAddress(htonl(ip)).toString(); +// } +// +// } +// i++; +// } +// } +// } +// } +// } +// } + qWarning() << ""; +} + +void NMView::getNetworkDevices() +{ + +} + +void NMView::connectionItemActivated( QTreeWidgetItem * item, int col ) +{ + Q_UNUSED(col); + + qWarning() <<__FUNCTION__<< item->text(0); + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + QVariant prop = iface.property("ActiveConnections"); + QList<QDBusObjectPath> connections = prop.value<QList<QDBusObjectPath> >(); + foreach(QDBusObjectPath path, connections) { + QDBusInterface conDetails(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbc); + + if (conDetails.isValid()) { + QString desc = path.path(); + qWarning() << desc; + if ( item->text(0) == conDetails.property("Connection").value<QDBusObjectPath>().path() ) { +// QListWidgetItem* item = new QTreeWidgetItem( desc, +// cons); +// item->setData(Qt::UserRole, desc); +// activeItemActivated( item ); + } + } + } +} + + + +void NMView::deviceItemActivated( QTreeWidgetItem * item , int section) +{ + Q_UNUSED(item); + Q_UNUSED(section); + + // qWarning() << item->text(section) << item->text(4); + //if(item->text(4) == "Wireless") findAccessPoints(item->text(0)); +} + + +void NMView::netconfig() +{ +// qWarning() << __FUNCTION__; + +// qDBusRegisterMetaType<SettingsMap>(); + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_IFACE_SETTINGS_CONNECTION, + dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager Settings"; + return; + } else { + QDBusReply<QList<QDBusObjectPath> > reply = iface.call("ListConnections"); + QList<QDBusObjectPath> list = reply.value(); +// qWarning() << reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() << " " << path.path(); + } + } +} + + +void NMView::findAccessPoints() +{ + accessPointsTreeWidget->clear(); + + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); + + QDBusReply<QList<QDBusObjectPath> > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { + QList<QDBusObjectPath> list = reply.value(); + foreach(QDBusObjectPath path, list) { + QDBusInterface devIface(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_DEVICE, + dbc); + if (devIface.isValid()) { + + if( devIface.property("DeviceType").toUInt() == DEVICE_TYPE_802_11_WIRELESS) { + +// qWarning() <<"deviface"<< devIface.path(); + QDBusInterface wififace(NM_DBUS_SERVICE, + devIface.path(), + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + dbc); + if (!wififace.isValid()) { + qWarning() << "Could not find NetworkManager wireless interface"; + return; + } + +///////////////////////// +// if(dbc.connect(NM_DBUS_SERVICE, +// path.path(), +// NM_DBUS_INTERFACE_DEVICE_WIRELESS, +// "PropertiesChanged", +// this,SLOT(aPPropertiesChanged( QMap<QString,QVariant>))) ) { +// qWarning() << "PropertiesChanged connect"; +// } else { +// qWarning() << "NOT connect"; + +// } +///////////////////////// + qWarning() <<"wififace"<< wififace.path(); + QDBusReply<QList<QDBusObjectPath> > reply2 = wififace.call("GetAccessPoints"); + if ( reply2.isValid() ) { + QTreeWidgetItem *item; + QList<QDBusObjectPath> list2 = reply2.value(); + foreach(QDBusObjectPath path2, list2) { + QDBusInterface accessPointIface(NM_DBUS_SERVICE, + path2.path(), + NM_DBUS_INTERFACE_ACCESS_POINT, + dbc); + if (accessPointIface.isValid()) { +//// qWarning() <<"path2" << path2.path(); + +// if(dbc.connect(NM_DBUS_SERVICE, //signal strength +// path2.path(), +// NM_DBUS_INTERFACE_ACCESS_POINT, +// "PropertiesChanged", +// this,SLOT(aPPropertiesChanged( QMap<QString,QVariant>))) ) { +// qWarning() << "PropertiesChanged connect"; +// } else { +// qWarning() << "NOT connect"; +// +// } + + QStringList accessPoints; + accessPoints << accessPointIface.property("Ssid").toString(); + accessPoints << QString::number(accessPointIface.property("Strength").toInt()); + accessPoints << securityCapabilitiesToString(accessPointIface.property("WpaFlags" ).toInt()); + accessPoints << securityCapabilitiesToString(accessPointIface.property("RsnFlags" ).toInt()); + accessPoints << accessPointIface.property("Frequency" ).toString(); + accessPoints << accessPointIface.property("HwAddress" ).toString(); + accessPoints << deviceModeToString(accessPointIface.property("Mode" ).toInt()); + accessPoints << accessPointIface.property("MaxBitrate" ).toString(); + //HwAddress + // if(accessPointIface.property("Flags" ).toInt() == NM_802_11_AP_FLAGS_PRIVACY ) { + // qWarning() << "Secure"; + // } + item = new QTreeWidgetItem(accessPoints); + accessPointsTreeWidget->insertTopLevelItem(0, item); + } + } + } + } + } + } + } +} + +QString NMView::deviceStateToString(int state) +{ + QString ret; + switch(state) { + case NM_DEVICE_STATE_UNKNOWN: + ret = "Unknown"; + break; + case NM_DEVICE_STATE_UNMANAGED: + ret = "Unmanaged"; + break; + case NM_DEVICE_STATE_UNAVAILABLE: + ret = "Unavailable"; + break; + case NM_DEVICE_STATE_DISCONNECTED: + ret = "Disconnected"; + break; + case NM_DEVICE_STATE_PREPARE: + ret = "Preparing to connect"; + break; + case NM_DEVICE_STATE_CONFIG: + ret = "Being configured"; + break; + case NM_DEVICE_STATE_NEED_AUTH: + ret = "Awaiting secrets"; + break; + case NM_DEVICE_STATE_IP_CONFIG: + ret = "IP requested"; + break; + case NM_DEVICE_STATE_ACTIVATED: + ret = "Activated"; + break; + case NM_DEVICE_STATE_FAILED: + ret = "FAILED"; + break; + }; + return ret; +} + +QString NMView::deviceTypeToString(int device) +{ + QString ret; + switch(device) { + case DEVICE_TYPE_UNKNOWN: + ret = "Unknown"; + break; + case DEVICE_TYPE_802_3_ETHERNET: + ret = "Ethernet"; + break; + case DEVICE_TYPE_802_11_WIRELESS: + ret = "Wireless"; + break; + case DEVICE_TYPE_GSM: + ret = "GSM"; + break; + case DEVICE_TYPE_CDMA: + ret = "CDMA"; + break; + }; + return ret; +} + +QString NMView::securityCapabilitiesToString(int caps) +{ + int check = caps; +// qWarning() << __FUNCTION__<< caps; + QString ret; + if( check == 0 ) + ret += "None."; + if( (check & NM_802_11_AP_SEC_PAIR_WEP40)) + ret += " 40-bit WEP encryption. "; + if( (check & NM_802_11_AP_SEC_PAIR_WEP104) ) + ret += " 104-bit WEP encryption. "; + if( (check & NM_802_11_AP_SEC_PAIR_TKIP) ) + ret += " TKIP encryption. "; + if( (check & NM_802_11_AP_SEC_PAIR_CCMP) ) + ret += " CCMP encryption. "; + if( (check & NM_802_11_AP_SEC_GROUP_WEP40)) + ret += " 40-bit WEP cipher. "; + if( (check & NM_802_11_AP_SEC_GROUP_WEP104)) + ret += " 104-bit WEP cipher. "; + if( (check & NM_802_11_AP_SEC_GROUP_TKIP) ) + ret += " TKIP cipher. "; + if( (check & NM_802_11_AP_SEC_GROUP_CCMP) ) + ret += " CCMP cipher. "; + if( (check & NM_802_11_AP_SEC_KEY_MGMT_PSK)) + ret += " PSK key management. "; + if( (check & NM_802_11_AP_SEC_KEY_MGMT_802_1X) ) + ret += " 802.1x key management. "; + return ret; +} + +QString NMView::deviceModeToString(int mode) +{ + QString ret; + switch (mode) { + case NM_802_11_MODE_UNKNOWN: + ret = "Unknown"; + break; + case NM_802_11_MODE_ADHOC: + ret = " (Adhoc)."; + break; + case NM_802_11_MODE_INFRA: + ret = " (Infrastructure)"; + }; + return ret; +} + +void NMView::netManagerState(quint32 state) +{ + qWarning() << __FUNCTION__ << state;// << old << reason; + switch(state) { + case NM_STATE_UNKNOWN: + qWarning() << "The NetworkManager daemon is in an unknown state. "; + break; + case NM_STATE_ASLEEP: + qWarning() << "The NetworkManager daemon is asleep and all interfaces managed by it are inactive. "; + break; + case NM_STATE_CONNECTING: + qWarning() << "The NetworkManager daemon is connecting a device. FIXME: What does this mean when one device is active and another is connecting? "; + break; + case NM_STATE_CONNECTED: + qWarning() <<"The NetworkManager daemon is connected. "; + break; + case NM_STATE_DISCONNECTED: + qWarning() << "The NetworkManager daemon is disconnected."; + break; + + }; +} + +void NMView::deviceStateChanged(quint32 state) +{ + qWarning() << __FUNCTION__ << state; + switch(state) { + case NM_DEVICE_STATE_UNKNOWN : + qWarning() <<"The device is in an unknown state. "; + break; + case NM_DEVICE_STATE_UNMANAGED: + qWarning() <<"The device is not managed by NetworkManager."; + break; + case NM_DEVICE_STATE_UNAVAILABLE: + qWarning() <<"The device cannot be used (carrier off, rfkill, etc)."; + break; + case NM_DEVICE_STATE_DISCONNECTED: + qWarning() <<"The device is not connected."; + break; + case NM_DEVICE_STATE_PREPARE: + qWarning() <<"The device is preparing to connect."; + break; + case NM_DEVICE_STATE_CONFIG: + qWarning() <<"The device is being configured."; + break; + case NM_DEVICE_STATE_NEED_AUTH: + qWarning() <<"The device is awaiting secrets necessary to continue connection."; + break; + case NM_DEVICE_STATE_IP_CONFIG: + qWarning() <<"The IP settings of the device are being requested and configured."; + break; + case NM_DEVICE_STATE_ACTIVATED: + qWarning() <<"The device is active."; + break; + case NM_DEVICE_STATE_FAILED: + qWarning() <<"The device is in a failure state following an attempt to activate it."; + break; + }; +} + +void NMView::updateCompleted() +{ + qWarning() << __FUNCTION__; +} + +void NMView::newConfigurationActivated() +{ + qWarning() << __FUNCTION__; + getActiveConnections(); +} + +void NMView::stateChanged(QNetworkSession::State state) +{ + // QString stateStringstr; + switch (state) { + case QNetworkSession::Invalid: + stateString = "Invalid session"; + break; + case QNetworkSession::NotAvailable: + stateString = "Session is defined but not yet discovered"; + break; + case QNetworkSession::Connecting: + stateString = "Session is being established"; + break; + case QNetworkSession::Connected: + stateString = "Session is active and can be used for socket operations"; + cons->currentItem()->setText(1, "Active"); + break; + case QNetworkSession::Closing: + stateString = "Session is being shutdown"; + break; + case QNetworkSession::Disconnected: + qWarning() << __FUNCTION__; + manager->updateConfigurations(); + stateString = "Session disconnected"; + cons->currentItem()->setText(1,"Discovered") ; + break; + case QNetworkSession::Roaming: + stateString = "session is roaming from one AP to another"; + break; + }; + qWarning() << __FUNCTION__ << state << stateString; +} + +QString NMView::stateToString(int state) +{ + switch (state) { + case QNetworkConfiguration::Undefined: + return "Undefined"; + break; + case QNetworkConfiguration::Defined: + return "Defined"; + break; + case QNetworkConfiguration::Discovered: + return "Discovered"; + break; + case QNetworkConfiguration::Active: + return "Active"; + break; + }; + return ""; +} + +void NMView::configurationAdded(const QNetworkConfiguration &config) +{ + qWarning() << __FUNCTION__<< config.name() << config.identifier(); +} + +QString NMView::typeToString(int type) +{ + switch(type) { + case QNetworkConfiguration::InternetAccessPoint: + return "Internet AccessPoint"; + break; + case QNetworkConfiguration::ServiceNetwork: + return "Service Network"; + break; + }; + return QString(); +} + +void NMView::aPPropertiesChanged( QMap<QString,QVariant> map) +{ + //QMap<QString, QVariant>::const_iterator iterator = d->values.find(type + QLatin1String("Path")) + QMapIterator<QString, QVariant> i(map); + while (i.hasNext()) { + i.next(); + if( i.key() == "State") { + qWarning() << __FUNCTION__ << i.key() << ": " << i.value().toUInt(); +// deviceStateChanged(i.value().toUInt()); + } else if( i.key() == "ActiveAccessPoint") { + qWarning() << __FUNCTION__ << i.key() << ": " << i.value().value<QDBusObjectPath>().path(); + } else if( i.key() == "Strength") + qWarning() << __FUNCTION__ << i.key() << ": " << i.value().toUInt(); + else + qWarning() << __FUNCTION__ << i.key() << ": " << i.value(); + } +} + +void NMView::networkSessionError(QNetworkSession::SessionError error) +{ + QString errorStr; + switch(error) { + case QNetworkSession::RoamingError: + errorStr = "Roaming error"; + break; + case QNetworkSession::SessionAbortedError: + errorStr = "Session aborted by user or system"; + break; + default: + case QNetworkSession::UnknownSessionError: + errorStr = "Unidentified Error"; + break; + }; + + QMessageBox::warning(this, tr("NMView"), errorStr, QMessageBox::Ok); +} diff --git a/tests/manual/networkmanager/nmview.h b/tests/manual/networkmanager/nmview.h new file mode 100644 index 0000000..41ee04f --- /dev/null +++ b/tests/manual/networkmanager/nmview.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $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 <QWidget> +#include <QDBusConnection> +#include <qnetworkconfigmanager.h> +#include <qnetworksession.h> +#include <qnetworkconfiguration.h> + +#include "ui_dialog.h" + +QT_USE_NAMESPACE + +QT_BEGIN_NAMESPACE +class QListWidget; +class QTreeWidget; +class QTreeWidgetItem; +QT_END_NAMESPACE + +class NMView : public QDialog, private Ui::Dialog +{ + Q_OBJECT +public: + NMView(QDialog* parent = 0); + virtual ~NMView(); + +private: + void init(); + QString stateString; + + QDBusConnection dbc; + void printConnectionDetails(const QString&); + + QString deviceStateToString(int state); + QString deviceTypeToString(int device); + QString securityCapabilitiesToString(int caps); + QString deviceModeToString(int mode); +//QDBusInterface getInterface(); + QNetworkConfigurationManager *manager; + QNetworkSession *sess; + QString stateToString(int state); + QString typeToString(int type); + +private slots: + void update(); + void deactivate(); + void activate(); + void getActiveConnections(); + void updateConnections(); + void getDevices(); + // void readConnectionManagerDetails(); + void getNetworkDevices(); + void connectionItemActivated( QTreeWidgetItem *, int); +// void activeItemActivated( QListWidgetItem *); + void deviceItemActivated( QTreeWidgetItem *, int); + void netconfig(); + void findAccessPoints(); + + void netManagerState(quint32); + void readSettings(); + void updateCompleted(); + void newConfigurationActivated(); + + void stateChanged(QNetworkSession::State); + void deviceStateChanged(quint32 state); + + void configurationAdded(const QNetworkConfiguration &config); + void aPPropertiesChanged( QMap<QString,QVariant> map); + void networkSessionError(QNetworkSession::SessionError); + +}; diff --git a/tests/manual/networkmanager/startdlg.cpp b/tests/manual/networkmanager/startdlg.cpp new file mode 100644 index 0000000..e34b5e9 --- /dev/null +++ b/tests/manual/networkmanager/startdlg.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $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 "startdlg.h" +#include <NetworkManager/NetworkManager.h> + + +StartDialog::StartDialog(QWidget * parent) + :QDialog(parent) +{ + QVBoxLayout *layout = new QVBoxLayout(this); + box = new QComboBox(); + layout->addWidget(box); + + QHBoxLayout* hbox = new QHBoxLayout(); + QPushButton* start = new QPushButton("Start"); + connect(start, SIGNAL(clicked()), this, SLOT(accept())); + QPushButton* cancel = new QPushButton("Cancel"); + connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); + + + hbox->addWidget(start); + hbox->addWidget(cancel); + + layout->addLayout(hbox); + + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + QDBusReply<QList<QDBusObjectPath> > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { + QList<QDBusObjectPath> list = reply.value(); + foreach(QDBusObjectPath path, list) { + QDBusInterface devIface(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_DEVICE, dbc); + if ( devIface.isValid() ) { + box->addItem(devIface.property("Interface").toString(), QVariant(path.path())); + } + } + } +} + +QString StartDialog::device() const +{ + return dev; +} + +void StartDialog::accept() +{ + dev = box->itemData(box->currentIndex(), Qt::UserRole).toString(); + QDialog::accept(); +} diff --git a/tests/manual/networkmanager/startdlg.h b/tests/manual/networkmanager/startdlg.h new file mode 100644 index 0000000..32c8557 --- /dev/null +++ b/tests/manual/networkmanager/startdlg.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** 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 test suite of the Qt Toolkit. +** +** $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 <QDialog> +#include <QtDBus> +#include <QtGui> + +class StartDialog : public QDialog +{ + Q_OBJECT +public: + StartDialog(QWidget* parent = 0); + + QString device() const; + +public slots: + void accept(); +private: + QString dev; + QComboBox* box; +}; |