aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2021-06-25 16:41:12 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2021-06-30 16:55:22 +0200
commite40563354fdbda99783a53c34defedc93550a066 (patch)
treef07f4fbe8b24bd5149a40c626e96d98db173923b /tests
parent0d856879e87ea9ec390f76aa840cfcc3da016329 (diff)
Remove the trailing token from empty acknowledgment packets
When sending Acknowledgment packets with code 0.00, the message should be empty (RFC-7252 section 12.1). An empty message should have no token (token length is 0), and no bytes should appear after the message ID (RFC-7252 section 4.1, section 3). Since Reset packets have the same structure (only the packet type differs), unified the packet creation for both cases in one method. Fixes: QTBUG-94763 Pick-to: 6.2 6.1 5.15 Change-Id: If2619ad6f4f5dba500e04ab10dbbbf08e4887aef Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp b/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp
index b88c22b..9e4342c 100644
--- a/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp
+++ b/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp
@@ -54,6 +54,8 @@ private Q_SLOTS:
void parseBlockOption();
void createBlockOption_data();
void createBlockOption();
+ void initEmptyMessage_data();
+ void initEmptyMessage();
};
void tst_QCoapInternalRequest::requestToFrame_data()
@@ -451,6 +453,35 @@ void tst_QCoapInternalRequest::createBlockOption()
QCOMPARE(option.opaqueValue(), expectedOption.opaqueValue());
}
+void tst_QCoapInternalRequest::initEmptyMessage_data()
+{
+ QTest::addColumn<QCoapMessage::Type>("type");
+ QTest::addColumn<QByteArray>("messageHeader");
+ QTest::newRow("acknowledge") << QCoapMessage::Type::Acknowledgment << QByteArray("6000002a");
+ QTest::newRow("reset") << QCoapMessage::Type::Reset << QByteArray("7000002a");
+
+}
+
+void tst_QCoapInternalRequest::initEmptyMessage()
+{
+ QFETCH(QCoapMessage::Type, type);
+ QFETCH(QByteArray, messageHeader);
+
+ // Populate the request with random data
+ QCoapRequest request = QCoapRequestPrivate::createRequest(QCoapRequest("coap://test"),
+ QtCoap::Method::Get);
+ request.setVersion(1);
+ request.setType(QCoapMessage::Type::Confirmable);
+ request.setMessageId(111);
+ request.setToken("token");
+ request.addOption(QCoapOption::ProxyUri);
+ request.setPayload("payload");
+
+ QCoapInternalRequest emptyMessageRequest(request);
+ emptyMessageRequest.initEmptyMessage(42, type);
+ QCOMPARE(emptyMessageRequest.toQByteArray().toHex(), messageHeader);
+}
+
QTEST_APPLESS_MAIN(tst_QCoapInternalRequest)
#include "tst_qcoapinternalrequest.moc"