From 5b2b0a7b35c9df42a92aa953fe0c58d208130d51 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Tue, 12 Apr 2011 16:58:46 +0200 Subject: [PATCH] QNAM HTTP: Fix upload progress signal --- src/network/access/qnetworkreplyhttpimpl.cpp | 2 +- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 34 +++++++++++++++----------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 1d86058..d240fb8 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -1736,7 +1736,7 @@ QNonContiguousByteDevice* QNetworkReplyHttpImplPrivate::createUploadByteDevice() uploadByteDevice->disableReset(); // We want signal emissions only for normal asynchronous uploads - if (synchronous) + if (!synchronous) QObject::connect(uploadByteDevice.data(), SIGNAL(readProgress(qint64,qint64)), q, SLOT(emitReplyUploadProgress(qint64,qint64))); diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index f509cea..36bb2ef 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -4162,6 +4162,7 @@ public: if (serverSocket->setSocketDescriptor(socketDescriptor)) { connect(serverSocket, SIGNAL(encrypted()), this, SLOT(encryptedSlot())); + connect(serverSocket, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); serverSocket->setProtocol(QSsl::AnyProtocol); connect(serverSocket, SIGNAL(sslErrors(const QList&)), serverSocket, SLOT(ignoreSslErrors())); serverSocket->setLocalCertificate(SRCDIR "/certs/server.pem"); @@ -4178,6 +4179,11 @@ public slots: socket = (QSslSocket*) sender(); emit newEncryptedConnection(); } + void readyReadSlot() { + // for the incoming sockets, not the server socket + //qDebug() << static_cast(sender())->bytesAvailable() << static_cast(sender())->encryptedBytesAvailable(); + } + public: QSslSocket *socket; }; @@ -4185,8 +4191,15 @@ public: // very similar to ioPostToHttpUploadProgress but for SSL void tst_QNetworkReply::ioPostToHttpsUploadProgress() { - QFile sourceFile(SRCDIR "/bigfile"); - QVERIFY(sourceFile.open(QIODevice::ReadOnly)); + //QFile sourceFile(SRCDIR "/bigfile"); + //QVERIFY(sourceFile.open(QIODevice::ReadOnly)); + qint64 wantedSize = 2*1024*1024; // 2 MB + QByteArray sourceFile; + // And in the case of SSL, the compression can fool us and let the + // server send the data much faster than expected. + // So better provide random data that cannot be compressed. + for (int i = 0; i < wantedSize; ++i) + sourceFile += (char)qrand(); // emulate a minimal https server SslServer server; @@ -4195,8 +4208,10 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress() // create the request QUrl url = QUrl(QString("https://127.0.0.1:%1/").arg(server.serverPort())); QNetworkRequest request(url); + request.setRawHeader("Content-Type", "application/octet-stream"); - QNetworkReplyPtr reply = manager.post(request, &sourceFile); + QNetworkReplyPtr reply = manager.post(request, sourceFile); + QSignalSpy spy(reply, SIGNAL(uploadProgress(qint64,qint64))); connect(&server, SIGNAL(newEncryptedConnection()), &QTestEventLoop::instance(), SLOT(exitLoop())); connect(reply, SIGNAL(sslErrors(const QList&)), reply, SLOT(ignoreSslErrors())); @@ -4215,26 +4230,17 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress() QVERIFY(!spy.isEmpty()); QList args = spy.last(); QVERIFY(args.at(0).toLongLong() > 0); - + // but not everything! QVERIFY(args.at(0).toLongLong() != sourceFile.size()); - incomingSocket->setReadBufferSize(32*1024); - incomingSocket->read(16*1024); - QTestEventLoop::instance().enterLoop(2); - // some more progress than before - QVERIFY(!spy.isEmpty()); - QList args2 = spy.last(); - QVERIFY(args2.at(0).toLongLong() > args.at(0).toLongLong()); - // set the read buffer to unlimited incomingSocket->setReadBufferSize(0); QTestEventLoop::instance().enterLoop(10); // progress should be finished QVERIFY(!spy.isEmpty()); QList args3 = spy.last(); - QVERIFY(args3.at(0).toLongLong() > args2.at(0).toLongLong()); QCOMPARE(args3.at(0).toLongLong(), args3.at(1).toLongLong()); - QCOMPARE(args3.at(0).toLongLong(), sourceFile.size()); + QCOMPARE(args3.at(0).toLongLong(), qint64(sourceFile.size())); // after sending this, the QNAM should emit finished() connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); -- 2.7.4