Add uploadProgress signal for QRestReply
Task-number: QTBUG-114717 Change-Id: I2052e4cc4da90962483f5f1931dc20552e484e34 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
e9f703ed3b
commit
298d5a4bbd
@ -57,7 +57,24 @@ Q_DECLARE_LOGGING_CATEGORY(lcQrest)
|
||||
|
||||
See \l QNetworkReply::downloadProgress() documentation for more details.
|
||||
|
||||
\sa bytesAvailable(), readyRead()
|
||||
\sa bytesAvailable(), readyRead(), uploadProgress()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QRestReply::uploadProgress(qint64 bytesSent, qint64 bytesTotal,
|
||||
QRestReply* reply)
|
||||
|
||||
This signal is emitted to indicate the progress of the upload part of
|
||||
\a reply.
|
||||
|
||||
The \a bytesSent parameter indicates the number of bytes already uploaded,
|
||||
while \a bytesTotal indicates the total number of bytes still to upload.
|
||||
|
||||
If the number of bytes to upload is not known, \a bytesTotal will be -1.
|
||||
|
||||
See \l QNetworkReply::uploadProgress() documentation for more details.
|
||||
|
||||
\sa QNetworkReply::uploadProgress(), downloadProgress()
|
||||
*/
|
||||
|
||||
/*!
|
||||
@ -98,6 +115,10 @@ QRestReply::QRestReply(QNetworkReply *reply, QObject *parent)
|
||||
[this](qint64 bytesReceived, qint64 bytesTotal) {
|
||||
emit downloadProgress(bytesReceived, bytesTotal, this);
|
||||
});
|
||||
QObject::connect(reply, &QNetworkReply::uploadProgress, this,
|
||||
[this] (qint64 bytesSent, qint64 bytesTotal) {
|
||||
emit uploadProgress(bytesSent, bytesTotal, this);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -45,6 +45,7 @@ Q_SIGNALS:
|
||||
void errorOccurred(QRestReply *reply);
|
||||
void readyRead(QRestReply *reply);
|
||||
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal, QRestReply *reply);
|
||||
void uploadProgress(qint64 bytesSent, qint64 bytesTotal, QRestReply* reply);
|
||||
|
||||
private:
|
||||
friend class QRestAccessManagerPrivate;
|
||||
|
@ -39,6 +39,7 @@ private slots:
|
||||
void json();
|
||||
void text();
|
||||
void download();
|
||||
void upload();
|
||||
|
||||
private:
|
||||
void memberHandler(QRestReply *reply);
|
||||
@ -862,5 +863,35 @@ void tst_QRestAccessManager::download()
|
||||
QCOMPARE(receivedBytes, expectedData.size());
|
||||
}
|
||||
|
||||
void tst_QRestAccessManager::upload()
|
||||
{
|
||||
// This test tests uploadProgress signal
|
||||
QRestAccessManager manager;
|
||||
manager.setDeletesRepliesOnFinished(false);
|
||||
HttpTestServer server;
|
||||
QTRY_VERIFY(server.isListening());
|
||||
QNetworkRequest request(server.url());
|
||||
request.setRawHeader("Content-Type"_ba, "text/plain"); // To silence missing content-type warn
|
||||
QByteArray expectedData{1 * 1024 * 1024, 0}; // 1 MB
|
||||
server.setHandler([&](HttpData, HttpData &, ResponseControl &) {});
|
||||
|
||||
QRestReply* reply = manager.post(request, expectedData);
|
||||
QSignalSpy uploadProgressSpy(reply, &QRestReply::uploadProgress);
|
||||
QTRY_VERIFY(reply->isFinished());
|
||||
QVERIFY(!uploadProgressSpy.isEmpty());
|
||||
reply->deleteLater();
|
||||
|
||||
// Check that bytesTotal is correct already in the first signal
|
||||
const QList<QVariant> first = uploadProgressSpy.first();
|
||||
QCOMPARE(first.size(), 3);
|
||||
QCOMPARE(first.at(1).toLongLong(), expectedData.size());
|
||||
|
||||
// Check that we sent all bytes
|
||||
const QList<QVariant> last = uploadProgressSpy.last();
|
||||
QCOMPARE(last.size(), 3);
|
||||
QEXPECT_FAIL("", "Fails due to QTBUG-44782", Continue);
|
||||
QCOMPARE(last.at(0).toLongLong(), expectedData.size());
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QRestAccessManager)
|
||||
#include "tst_qrestaccessmanager.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user