mirror of https://github.com/qt/qtcoap.git
QCoapReply: add test for a chunked read
QCoapReply is a QIODevice, but it was not obvious if readData() is implemented properly, or if it also needed to update pos(). This patch adds a unit test that checks a chunked read from the reply. The test passes, so nothing needs to be fixed in the implementation. Pick-to: 6.10 6.9 6.8 6.5 Change-Id: I0642718f21a31cf978a733bc3bc742ad1eb47b3a Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
a292490ba6
commit
f310b4a5a2
|
@ -18,6 +18,7 @@ private Q_SLOTS:
|
||||||
void updateReply();
|
void updateReply();
|
||||||
void requestData();
|
void requestData();
|
||||||
void abortRequest();
|
void abortRequest();
|
||||||
|
void readReplyChunked();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QCoapReply::updateReply_data()
|
void tst_QCoapReply::updateReply_data()
|
||||||
|
@ -117,6 +118,39 @@ void tst_QCoapReply::abortRequest()
|
||||||
QVERIFY(arguments.at(0).toByteArray() == "token");
|
QVERIFY(arguments.at(0).toByteArray() == "token");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QCoapReply::readReplyChunked()
|
||||||
|
{
|
||||||
|
const QByteArray token = "\xAF\x01\xC2";
|
||||||
|
const quint16 id = 645;
|
||||||
|
const QByteArray payload = "this is some payload";
|
||||||
|
|
||||||
|
QScopedPointer<QCoapReply> reply(QCoapReplyPrivate::createCoapReply(QCoapRequest()));
|
||||||
|
QCoapMessage message;
|
||||||
|
message.setToken(token);
|
||||||
|
message.setMessageId(id);
|
||||||
|
message.setPayload(payload);
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(reply.data(), "_q_setContent",
|
||||||
|
Q_ARG(QHostAddress, QHostAddress()),
|
||||||
|
Q_ARG(QCoapMessage, message),
|
||||||
|
Q_ARG(QtCoap::ResponseCode, QtCoap::ResponseCode::Content));
|
||||||
|
QMetaObject::invokeMethod(reply.data(), "_q_setFinished",
|
||||||
|
Q_ARG(QtCoap::Error, QtCoap::Error::Ok));
|
||||||
|
|
||||||
|
QCOMPARE_EQ(reply->pos(), 0);
|
||||||
|
const qsizetype startBytes = 7;
|
||||||
|
const QByteArray start = reply->read(startBytes);
|
||||||
|
QCOMPARE_EQ(start, payload.first(startBytes));
|
||||||
|
QCOMPARE_EQ(reply->pos(), startBytes);
|
||||||
|
|
||||||
|
QByteArray last(100, Qt::Uninitialized);
|
||||||
|
const qint64 read = reply->read(last.data(), last.size());
|
||||||
|
QCOMPARE_EQ(read, payload.size() - startBytes);
|
||||||
|
QCOMPARE_EQ(reply->pos(), payload.size());
|
||||||
|
last.resize(read);
|
||||||
|
QCOMPARE_EQ(start + last, payload);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QCoapReply)
|
QTEST_MAIN(tst_QCoapReply)
|
||||||
|
|
||||||
#include "tst_qcoapreply.moc"
|
#include "tst_qcoapreply.moc"
|
||||||
|
|
Loading…
Reference in New Issue