Commit e3a794e482f3a083c8c7a045782ce0e946913a6f
1 parent
0cc6610a
Fix incorrect assert about QoS on wrong object
Fixes assertion error in debug only.
Showing
2 changed files
with
35 additions
and
3 deletions
FlashMQTests/tst_maintests.cpp
| ... | ... | @@ -131,6 +131,8 @@ private slots: |
| 131 | 131 | void testIncomingTopicAlias(); |
| 132 | 132 | void testOutgoingTopicAlias(); |
| 133 | 133 | |
| 134 | + void testReceivingRetainedMessageWithQoS(); | |
| 135 | + | |
| 134 | 136 | }; |
| 135 | 137 | |
| 136 | 138 | MainTests::MainTests() |
| ... | ... | @@ -1706,6 +1708,34 @@ void MainTests::testOutgoingTopicAlias() |
| 1706 | 1708 | }); |
| 1707 | 1709 | } |
| 1708 | 1710 | |
| 1711 | +void MainTests::testReceivingRetainedMessageWithQoS() | |
| 1712 | +{ | |
| 1713 | + FlashMQTestClient sender; | |
| 1714 | + sender.start(); | |
| 1715 | + | |
| 1716 | + const std::string payload = "We are testing"; | |
| 1717 | + | |
| 1718 | + sender.connectClient(ProtocolVersion::Mqtt311); | |
| 1719 | + | |
| 1720 | + Publish p1("topic1/FOOBAR", payload, 1); | |
| 1721 | + p1.retain = true; | |
| 1722 | + sender.publish(p1); | |
| 1723 | + | |
| 1724 | + FlashMQTestClient receiver; | |
| 1725 | + receiver.start(); | |
| 1726 | + receiver.connectClient(ProtocolVersion::Mqtt5); | |
| 1727 | + | |
| 1728 | + receiver.subscribe("+/+", 1); | |
| 1729 | + | |
| 1730 | + receiver.waitForMessageCount(1); | |
| 1731 | + | |
| 1732 | + MYCASTCOMPARE(receiver.receivedPublishes.size(), 1); | |
| 1733 | + MYCASTCOMPARE(receiver.receivedPublishes.front().getQos(), 1); | |
| 1734 | + MYCASTCOMPARE(receiver.receivedPublishes.front().getTopic(), "topic1/FOOBAR"); | |
| 1735 | + MYCASTCOMPARE(receiver.receivedPublishes.front().getPayloadCopy(), payload); | |
| 1736 | + MYCASTCOMPARE(receiver.receivedPublishes.front().getRetain(), true); | |
| 1737 | +} | |
| 1738 | + | |
| 1709 | 1739 | |
| 1710 | 1740 | int main(int argc, char *argv[]) |
| 1711 | 1741 | { | ... | ... |
publishcopyfactory.cpp
| ... | ... | @@ -95,16 +95,18 @@ bool PublishCopyFactory::getRetain() const |
| 95 | 95 | |
| 96 | 96 | Publish PublishCopyFactory::getNewPublish() const |
| 97 | 97 | { |
| 98 | - assert(packet->getQos() > 0); | |
| 99 | - assert(orgQos > 0); // We only need to construct new publishes for QoS. If you're doing it elsewhere, it's a bug. | |
| 100 | - | |
| 101 | 98 | if (packet) |
| 102 | 99 | { |
| 100 | + assert(packet->getQos() > 0); | |
| 101 | + assert(orgQos > 0); // We only need to construct new publishes for QoS. If you're doing it elsewhere, it's a bug. | |
| 102 | + | |
| 103 | 103 | Publish p(packet->getPublishData()); |
| 104 | 104 | p.qos = orgQos; |
| 105 | 105 | return p; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | + assert(publish->qos > 0); // Same check as above, but then for Publish objects. | |
| 109 | + | |
| 108 | 110 | Publish p(*publish); |
| 109 | 111 | p.qos = orgQos; |
| 110 | 112 | return p; | ... | ... |