summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 3a752c0748..9fa54597f1 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -622,7 +622,7 @@ protected:
Q_ASSERT(!client.isNull());
// we need to emulate the bytesWrittenSlot call if the data is empty.
if (dataToTransmit.size() == 0) {
- QMetaObject::invokeMethod(this, "bytesWrittenSlot", Qt::QueuedConnection);
+ emit client->bytesWritten(0);
} else {
client->write(dataToTransmit);
// FIXME: For SSL connections, if we don't flush the socket, the
@@ -659,22 +659,26 @@ private slots:
#ifndef QT_NO_SSL
void slotSslErrors(const QList<QSslError>& errors)
{
- Q_ASSERT(!client.isNull());
- qDebug() << "slotSslErrors" << client->errorString() << errors;
+ QTcpSocket *currentClient = qobject_cast<QTcpSocket *>(sender());
+ Q_ASSERT(currentClient);
+ qDebug() << "slotSslErrors" << currentClient->errorString() << errors;
}
#endif
void slotError(QAbstractSocket::SocketError err)
{
- if (client.isNull())
- qDebug() << "slotError" << err;
- else
- qDebug() << "slotError" << err << client->errorString();
+ QTcpSocket *currentClient = qobject_cast<QTcpSocket *>(sender());
+ Q_ASSERT(currentClient);
+ qDebug() << "slotError" << err << currentClient->errorString();
}
public slots:
void readyReadSlot()
{
- Q_ASSERT(!client.isNull());
+ QTcpSocket *currentClient = qobject_cast<QTcpSocket *>(sender());
+ Q_ASSERT(currentClient);
+ if (currentClient != client)
+ client = currentClient;
+
receivedData += client->readAll();
const int doubleEndlPos = receivedData.indexOf("\r\n\r\n");
@@ -8290,11 +8294,23 @@ void tst_QNetworkReply::ioHttpRedirectErrors()
QNetworkReplyPtr reply(manager.get(request));
if (localhost.scheme() == "https")
reply.data()->ignoreSslErrors();
- QSignalSpy spy(reply.data(), SIGNAL(error(QNetworkReply::NetworkError)));
- QCOMPARE(waitForFinish(reply), int(Failure));
+ QEventLoop eventLoop;
+ QTimer watchDog;
+ watchDog.setSingleShot(true);
- QCOMPARE(spy.count(), 1);
+ reply->connect(reply.data(), QOverload<QNetworkReply::NetworkError>().of(&QNetworkReply::error),
+ [&eventLoop](QNetworkReply::NetworkError){
+ eventLoop.exit(Failure);
+ });
+
+ watchDog.connect(&watchDog, &QTimer::timeout, [&eventLoop](){
+ eventLoop.exit(Timeout);
+ });
+
+ watchDog.start(5000);
+
+ QCOMPARE(eventLoop.exec(), int(Failure));
QCOMPARE(reply->error(), error);
}