summaryrefslogtreecommitdiffstats
path: root/tests/auto/qnetworkreply
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-11-17 12:22:50 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-11-17 12:38:37 (GMT)
commit62d1149357736a0dd9b8a439edb73c30f6d407ad (patch)
tree134d7768bf70e06d5810fb5dd83ccbf01254de6c /tests/auto/qnetworkreply
parent1f475f97bfaef06967c2325c4ecf7fb076e5a1fc (diff)
downloadQt-62d1149357736a0dd9b8a439edb73c30f6d407ad.zip
Qt-62d1149357736a0dd9b8a439edb73c30f6d407ad.tar.gz
Qt-62d1149357736a0dd9b8a439edb73c30f6d407ad.tar.bz2
tst_qnetworkreply: Fix ugly test
Properly use the event loop. Signals have to be connected directly after using the get() method of QNetworkAccessManager. Else they might have already been emitted while the event loop was spinning. Reviewed-by: Peter Hartmann
Diffstat (limited to 'tests/auto/qnetworkreply')
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 41b3e0a..ddb7687 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -4130,8 +4130,23 @@ void tst_QNetworkReply::httpProxyCommands()
QCOMPARE(receivedHeader, expectedCommand);
}
+class ProxyChangeHelper : public QObject {
+ Q_OBJECT
+public:
+ ProxyChangeHelper() : QObject(), signalCount(0) {};
+public slots:
+ void finishedSlot() {
+ signalCount++;
+ if (signalCount == 2)
+ QMetaObject::invokeMethod(&QTestEventLoop::instance(), "exitLoop", Qt::QueuedConnection);
+ }
+private:
+ int signalCount;
+};
+
void tst_QNetworkReply::proxyChange()
{
+ ProxyChangeHelper helper;
MiniHttpServer proxyServer(
"HTTP/1.0 200 OK\r\nProxy-Connection: keep-alive\r\n"
"Content-Length: 1\r\n\r\n1");
@@ -4141,30 +4156,15 @@ void tst_QNetworkReply::proxyChange()
manager.setProxy(dummyProxy);
QNetworkReplyPtr reply1 = manager.get(req);
- QSignalSpy finishedspy(reply1, SIGNAL(finished()));
+ connect(reply1, SIGNAL(finished()), &helper, SLOT(finishedSlot()));
manager.setProxy(QNetworkProxy());
QNetworkReplyPtr reply2 = manager.get(req);
+ connect(reply2, SIGNAL(finished()), &helper, SLOT(finishedSlot()));
- connect(reply2, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
-#ifdef Q_OS_SYMBIAN
- // we need more time as:
- // 1. running from the emulator
- // 2. not perfect POSIX implementation
- // 3. embedded device
QTestEventLoop::instance().enterLoop(20);
-#else
- QTestEventLoop::instance().enterLoop(10);
-#endif
QVERIFY(!QTestEventLoop::instance().timeout());
- if (finishedspy.count() == 0) {
- // wait for the second reply as well
- connect(reply1, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
- QTestEventLoop::instance().enterLoop(1);
- QVERIFY(!QTestEventLoop::instance().timeout());
- }
-
// verify that the replies succeeded
QCOMPARE(reply1->error(), QNetworkReply::NoError);
QCOMPARE(reply1->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200);