Don't read from deleted member variable

QNetworkProxy::setApplicationProxy deletes factory set by
QNetworkProxyFactory::setApplicationProxyFactory.

Change-Id: Iaafd62d1cdb2045d69c7359cacc513056216826c
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
This commit is contained in:
Peter Kümmel 2012-12-01 15:29:43 +01:00 committed by The Qt Project
parent 0cac0796a0
commit 8e3d4f5e87

View File

@ -73,7 +73,8 @@ public:
return returnedList;
}
QList<QNetworkProxy> returnedList;
int requestCounter;
static int requestCounter;
};
private slots:
@ -92,6 +93,8 @@ private:
QDebugProxyFactory *factory;
};
int tst_QNetworkProxyFactory::QDebugProxyFactory::requestCounter = 0;
tst_QNetworkProxyFactory::tst_QNetworkProxyFactory()
{
factory = new QDebugProxyFactory;
@ -204,6 +207,7 @@ void tst_QNetworkProxyFactory::systemProxyForQuery_local()
// set an arbitrary proxy
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, proxyHost, 80));
factory = 0;
// localhost
list = QNetworkProxyFactory::proxyForQuery(QNetworkProxyQuery(QUrl("http://localhost/")));
@ -231,6 +235,7 @@ void tst_QNetworkProxyFactory::systemProxyForQuery_local()
// disable proxy
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::NoProxy));
factory = 0;
// localhost
list = QNetworkProxyFactory::proxyForQuery(QNetworkProxyQuery(QUrl("http://localhost/")));
@ -328,7 +333,7 @@ void tst_QNetworkProxyFactory::inNetworkAccessManager()
QFETCH(QNetworkConfiguration, config);
QFETCH(QList<QNetworkProxy>, proxies);
int count = factory->requestCounter;
int count = QDebugProxyFactory::requestCounter;
QNetworkAccessManager manager;
manager.setConfiguration(config);
@ -340,11 +345,12 @@ void tst_QNetworkProxyFactory::inNetworkAccessManager()
QTestEventLoop::instance().enterLoop(30);
delete reply;
if (count == factory->requestCounter) {
if (count == QDebugProxyFactory::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");
}
QVERIFY(factory);
qDebug() << "testing network configuration for" << config.name();
foreach (QNetworkProxy proxy, factory->returnedList) {