mirror of
https://github.com/qt/qtmqtt.git
synced 2026-10-25 16:16:26 +00:00
Allow empty will messages
A will message is allowed to be empty. Hence, check whether a will topic exists to identify incorporating the last will to the connect message. Task-number: QTBUG-76783 Change-Id: Ifb7f5467e8e7e70c6d9c050b36a35df2419f4171 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
parent
23febf5517
commit
d25a0abe78
@ -253,7 +253,7 @@ bool QMqttConnection::sendControlConnect()
|
||||
if (m_clientPrivate->m_cleanSession)
|
||||
flags |= 1 << 1;
|
||||
|
||||
if (!m_clientPrivate->m_willMessage.isEmpty()) {
|
||||
if (!m_clientPrivate->m_willTopic.isEmpty()) {
|
||||
flags |= 1 << 2;
|
||||
if (m_clientPrivate->m_willQoS > 2) {
|
||||
qCDebug(lcMqttConnection) << "Invalid Will QoS specified.";
|
||||
@ -290,7 +290,7 @@ bool QMqttConnection::sendControlConnect()
|
||||
packet.append(char(0));
|
||||
}
|
||||
|
||||
if (!m_clientPrivate->m_willMessage.isEmpty()) {
|
||||
if (!m_clientPrivate->m_willTopic.isEmpty()) {
|
||||
if (m_clientPrivate->m_protocolVersion == QMqttClient::MQTT_5_0)
|
||||
packet.appendRaw(writeLastWillProperties());
|
||||
|
||||
|
||||
@ -263,14 +263,25 @@ void Tst_QMqttClient::retainMessage()
|
||||
publisher.disconnect();
|
||||
}
|
||||
|
||||
DefaultVersionTestData(Tst_QMqttClient::willMessage_data)
|
||||
void Tst_QMqttClient::willMessage_data()
|
||||
{
|
||||
QTest::addColumn<QMqttClient::ProtocolVersion>("mqttVersion");
|
||||
QTest::addColumn<QByteArray>("willMessage");
|
||||
|
||||
QList<QMqttClient::ProtocolVersion> versions{QMqttClient::MQTT_3_1_1, QMqttClient::MQTT_5_0};
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
QTest::newRow(qPrintable(QString::number(versions[i]) + ":simple")) << versions[i] << QByteArray("The client connection is gone.");
|
||||
QTest::newRow(qPrintable(QString::number(versions[i]) + ":empty")) << versions[i] << QByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
void Tst_QMqttClient::willMessage()
|
||||
{
|
||||
QFETCH(QMqttClient::ProtocolVersion, mqttVersion);
|
||||
QFETCH(QByteArray, willMessage);
|
||||
|
||||
const QString willTopic = QLatin1String("Qt/QMqttClient/will/topic");
|
||||
const QByteArray willMessage("The client died....");
|
||||
|
||||
// Client A connects
|
||||
VersionClient(mqttVersion, client1);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user