summaryrefslogtreecommitdiffstats
path: root/tests/auto/qnetworkproxyfactory
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2011-04-18 15:46:19 +0100
committerMarkus Goetz <Markus.Goetz@nokia.com>2011-05-09 13:15:47 +0200
commit724671feca39e6eebaf4d8005bb89d5c14e96386 (patch)
tree1dd1f680ae1a11b7dcc6d3ce1eefbaf1be371115 /tests/auto/qnetworkproxyfactory
parenta342ba933a433070a8cd5a350c358a4766aebc96 (diff)
Add autotests for configuration dependent network proxies
1. test that systemProxyForQuery returns something for all configs 2. test that QNetworkAccessManager uses the settings for the configuration it was started with. Task-number: QTBUG-18618 Reviewed-by: Peter Hartmann
Diffstat (limited to 'tests/auto/qnetworkproxyfactory')
-rw-r--r--tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro2
-rw-r--r--tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp144
2 files changed, 145 insertions, 1 deletions
diff --git a/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro b/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro
index f05c423087..17ad403ba7 100644
--- a/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro
+++ b/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro
@@ -7,5 +7,5 @@ QT = core network
SOURCES += tst_qnetworkproxyfactory.cpp
-symbian: TARGET.CAPABILITY = NetworkServices
+symbian: TARGET.CAPABILITY = NetworkServices ReadUserData
diff --git a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
index 2baee27d5f..82a4193e9d 100644
--- a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
+++ b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
@@ -41,20 +41,60 @@
#include <QtTest/QTest>
+#include <QtTest/QTestEventLoop>
#include <qcoreapplication.h>
#include <qdebug.h>
#include <qnetworkproxy.h>
+#include <QNetworkConfiguration>
+#include <QNetworkConfigurationManager>
+#include <QNetworkSession>
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+#include <QNetworkRequest>
+#include <QList>
+
+Q_DECLARE_METATYPE(QNetworkConfiguration);
+Q_DECLARE_METATYPE(QList<QNetworkProxy>);
class tst_QNetworkProxyFactory : public QObject {
Q_OBJECT
+
+public:
+ tst_QNetworkProxyFactory();
+
+ class QDebugProxyFactory : public QNetworkProxyFactory
+ {
+ public:
+ virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery())
+ {
+ returnedList = QNetworkProxyFactory::systemProxyForQuery(query);
+ requestCounter++;
+ return returnedList;
+ }
+ QList<QNetworkProxy> returnedList;
+ int requestCounter;
+ };
+
private slots:
void systemProxyForQuery() const;
+#ifndef QT_NO_BEARERMANAGEMENT
+ void fromConfigurations();
+ void inNetworkAccessManager_data();
+ void inNetworkAccessManager();
+#endif
private:
QString formatProxyName(const QNetworkProxy & proxy) const;
+ QDebugProxyFactory *factory;
};
+tst_QNetworkProxyFactory::tst_QNetworkProxyFactory()
+{
+ factory = new QDebugProxyFactory;
+ QNetworkProxyFactory::setApplicationProxyFactory(factory);
+}
+
QString tst_QNetworkProxyFactory::formatProxyName(const QNetworkProxy & proxy) const
{
QString proxyName;
@@ -96,5 +136,109 @@ void tst_QNetworkProxyFactory::systemProxyForQuery() const
QFAIL("One or more system proxy lookup failures occurred.");
}
+#ifndef QT_NO_BEARERMANAGEMENT
+
+//Purpose of this test is just to check systemProxyForQuery doesn't hang or crash
+//with any given configuration including no configuration.
+//We can't test it returns the right proxies without implementing the native proxy code
+//again here, which would be testing our implementation against itself.
+//Therefore it's just testing that something valid is returned (at least a NoProxy entry)
+void tst_QNetworkProxyFactory::fromConfigurations()
+{
+ QNetworkConfigurationManager manager;
+ QList<QNetworkProxy> proxies;
+ QUrl url(QLatin1String("http://qt.nokia.com"));
+ //get from known configurations
+ foreach (QNetworkConfiguration config, manager.allConfigurations()) {
+ QNetworkProxyQuery query(config, url, QNetworkProxyQuery::UrlRequest);
+ proxies = QNetworkProxyFactory::systemProxyForQuery(query);
+ QVERIFY(!proxies.isEmpty());
+ foreach (QNetworkProxy proxy, proxies) {
+ qDebug() << config.name() << " - " << config.identifier() << " - " << formatProxyName(proxy);
+ }
+ }
+
+ //get from default configuration
+ QNetworkProxyQuery defaultquery(url, QNetworkProxyQuery::UrlRequest);
+ proxies = QNetworkProxyFactory::systemProxyForQuery(defaultquery);
+ QVERIFY(!proxies.isEmpty());
+ foreach (QNetworkProxy proxy, proxies) {
+ qDebug() << "default - " << formatProxyName(proxy);
+ }
+
+ //get from active configuration
+ QNetworkSession session(manager.defaultConfiguration());
+ session.open();
+ QVERIFY(session.waitForOpened(30000));
+ proxies = QNetworkProxyFactory::systemProxyForQuery(defaultquery);
+ QVERIFY(!proxies.isEmpty());
+ foreach (QNetworkProxy proxy, proxies) {
+ qDebug() << "active - " << formatProxyName(proxy);
+ }
+
+ //get from known configurations while there is one active
+ foreach (QNetworkConfiguration config, manager.allConfigurations()) {
+ QNetworkProxyQuery query(config, url, QNetworkProxyQuery::UrlRequest);
+ proxies = QNetworkProxyFactory::systemProxyForQuery(query);
+ QVERIFY(!proxies.isEmpty());
+ foreach (QNetworkProxy proxy, proxies) {
+ qDebug() << config.name() << " - " << config.identifier() << " - " << formatProxyName(proxy);
+ }
+ }
+}
+
+void tst_QNetworkProxyFactory::inNetworkAccessManager_data()
+{
+ QTest::addColumn<QNetworkConfiguration>("config");
+ QTest::addColumn<QList<QNetworkProxy> >("proxies");
+ QNetworkConfigurationManager manager;
+ //get from known configurations
+ foreach (QNetworkConfiguration config, manager.allConfigurations()) {
+ QNetworkProxyQuery query(config, QUrl(QString("http://qt.nokia.com")), QNetworkProxyQuery::UrlRequest);
+ QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(query);
+ QTest::newRow(config.name().toUtf8()) << config << proxies;
+ }
+}
+
+//Purpose of this test is to check that QNetworkAccessManager uses the proxy from the configuration it
+//has been given. Needs two or more working configurations to be a good test.
+void tst_QNetworkProxyFactory::inNetworkAccessManager()
+{
+ QFETCH(QNetworkConfiguration, config);
+ QFETCH(QList<QNetworkProxy>, proxies);
+
+ int count = factory->requestCounter;
+
+ QNetworkAccessManager manager;
+ manager.setConfiguration(config);
+
+ //using an internet server, because cellular APs won't have a route to the test server.
+ QNetworkRequest req(QUrl(QString("http://qt.nokia.com")));
+ QNetworkReply *reply = manager.get(req);
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(30);
+ delete reply;
+
+ if (count == factory->requestCounter) {
+ //RND phones are preconfigured with several test access points which won't work without a matching SIM
+ //If the network fails to start, QNAM won't ask the factory for proxies so we can't test.
+ QSKIP("network configuration didn't start", SkipSingle);
+ }
+
+ qDebug() << "testing network configuration for" << config.name();
+ foreach (QNetworkProxy proxy, factory->returnedList) {
+ qDebug() << formatProxyName(proxy);
+ }
+ qDebug() << " <vs> ";
+ foreach (QNetworkProxy proxy, proxies) {
+ qDebug() << formatProxyName(proxy);
+ }
+ if (config.type() != QNetworkConfiguration::InternetAccessPoint)
+ QEXPECT_FAIL("","QNetworkProxyFactory::systemProxyForQuery doesn't work for service networks yet", Continue);
+ QCOMPARE(factory->returnedList, proxies);
+}
+
+#endif //QT_NO_BEARERMANAGEMENT
+
QTEST_MAIN(tst_QNetworkProxyFactory)
#include "tst_qnetworkproxyfactory.moc"