diff options
author | Thomas McGuire <thomas.mcguire@kdab.com> | 2013-04-23 09:37:29 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-23 21:02:50 +0200 |
commit | e0cf3fcd8f8680e9c8b0fe1f1f18c1dda89eca80 (patch) | |
tree | a97bed01f0d41ab5a2b74e38fce5b8e63f6272dc /tests | |
parent | 1ea1abeb91f544b4cf595d229249ee859090bee5 (diff) |
Fix retrieving of the generic system proxy via environment variables
ignoreProxyFor() always returned true if the no_proxy was not set,
which resulted in the first token being an empty QByteArray, causing
the endsWith() check to always evaluate to true.
Add a unit test that is enabled for those platforms that use the generic
system proxy.
Change-Id: I6081ad5e0b8e2c3fee1568835907c32bde5b7772
Reviewed-by: Peter Hartmann <phartmann@blackberry.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp index d57a99a758..e06285dc67 100644 --- a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp +++ b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp @@ -87,6 +87,8 @@ private slots: void inNetworkAccessManager_data(); void inNetworkAccessManager(); #endif + void genericSystemProxy(); + void genericSystemProxy_data(); private: QString formatProxyName(const QNetworkProxy & proxy) const; @@ -367,6 +369,45 @@ void tst_QNetworkProxyFactory::inNetworkAccessManager() #endif //QT_NO_BEARERMANAGEMENT +Q_DECLARE_METATYPE(QNetworkProxy::ProxyType) + +void tst_QNetworkProxyFactory::genericSystemProxy() +{ + QFETCH(QByteArray, envVar); + QFETCH(QByteArray, url); + QFETCH(QNetworkProxy::ProxyType, proxyType); + QFETCH(QString, hostName); + QFETCH(int, port); + +// The generic system proxy is only available on the following platforms +#if (!defined Q_OS_BLACKBERRY) && (!defined Q_OS_WIN) && ((!defined Q_OS_MAC) || defined Q_OS_IOS) + qputenv(envVar, url); + const QList<QNetworkProxy> systemProxy = QNetworkProxyFactory::systemProxyForQuery(); + QCOMPARE(systemProxy.size(), 1); + QCOMPARE(systemProxy.first().type(), proxyType); + QCOMPARE(systemProxy.first().hostName(), hostName); + QCOMPARE(systemProxy.first().port(), static_cast<quint16>(port)); + qunsetenv(envVar); +#else + QSKIP("Generic system proxy not available on this platform."); +#endif +} + +void tst_QNetworkProxyFactory::genericSystemProxy_data() +{ + QTest::addColumn<QByteArray>("envVar"); + QTest::addColumn<QByteArray>("url"); + QTest::addColumn<QNetworkProxy::ProxyType>("proxyType"); + QTest::addColumn<QString>("hostName"); + QTest::addColumn<int>("port"); + + QTest::newRow("no proxy") << QByteArray("http_proxy") << QByteArray() << QNetworkProxy::NoProxy + << QString() << 0; + QTest::newRow("socks5") << QByteArray("http_proxy") << QByteArray("socks5://127.0.0.1:4242") + << QNetworkProxy::Socks5Proxy << QString("127.0.0.1") << 4242; + QTest::newRow("http") << QByteArray("http_proxy") << QByteArray("http://example.com:666") + << QNetworkProxy::HttpProxy << QString("example.com") << 666; +} class QSPFQThread : public QThread { |