summaryrefslogtreecommitdiffstats
path: root/tests/auto/qnetworkreply
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2011-04-12 16:58:46 +0200
committerMarkus Goetz <Markus.Goetz@nokia.com>2011-05-03 16:42:55 +0200
commit5b2b0a7b35c9df42a92aa953fe0c58d208130d51 (patch)
tree29bfcbaedfe77a7782c7eb96bee4346e2d131012 /tests/auto/qnetworkreply
parenta5562d345b212c722b3b0a9296b0ab9187959ddf (diff)
QNAM HTTP: Fix upload progress signal
Diffstat (limited to 'tests/auto/qnetworkreply')
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index f509ceaad6..36bb2efdc3 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<QSslError>&)), 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<QSslSocket*>(sender())->bytesAvailable() << static_cast<QSslSocket*>(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<QSslError>&)), reply, SLOT(ignoreSslErrors()));
@@ -4215,26 +4230,17 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress()
QVERIFY(!spy.isEmpty());
QList<QVariant> 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<QVariant> 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<QVariant> 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()));