From 592e12eb6412f247da25b91172d8e9adf13f0f87 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Tue, 11 Jan 2022 14:11:39 +0100 Subject: [PATCH] Test for the '+/+' retained messages bug --- FlashMQTests/tst_maintests.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+), 0 deletions(-) diff --git a/FlashMQTests/tst_maintests.cpp b/FlashMQTests/tst_maintests.cpp index db01518..437d107 100644 --- a/FlashMQTests/tst_maintests.cpp +++ b/FlashMQTests/tst_maintests.cpp @@ -77,6 +77,7 @@ private slots: void test_retained(); void test_retained_changed(); void test_retained_removed(); + void test_retained_tree(); void test_packet_bigger_than_one_doubling(); void test_very_big_packet(); @@ -443,6 +444,42 @@ void MainTests::test_retained_removed() QVERIFY2(testContext.receivedMessages.empty(), "We erased the retained message. We shouldn't have received any."); } +/** + * @brief MainTests::test_retained_tree tests a bug I found, where '+/+' yields different results than '#', where it should be the same. + */ +void MainTests::test_retained_tree() +{ + TwoClientTestContext testContext; + + QByteArray payload = "We are testing"; + const QString topic1 = "TopicA/B"; + const QString topic2 = "Topic/C"; + const QString topic3 = "TopicB/C"; + const QStringList topics {topic1, topic2, topic3}; + + testContext.connectSender(); + testContext.publish(topic1, payload, true); + testContext.publish(topic2, payload, true); + testContext.publish(topic3, payload, true); + + testContext.connectReceiver(); + testContext.subscribeReceiver("+/+"); + testContext.waitReceiverReceived(1); + + QCOMPARE(testContext.receivedMessages.count(), topics.count()); + + for (const QString &s : topics) + { + bool r = std::any_of(testContext.receivedMessages.begin(), testContext.receivedMessages.end(), [&](QMQTT::Message &msg) + { + return msg.topic() == s && msg.payload() == payload; + }); + + QVERIFY2(r, formatString("%s not found in retained messages.", s.toStdString().c_str()).c_str()); + } + +} + void MainTests::test_packet_bigger_than_one_doubling() { TwoClientTestContext testContext; -- libgit2 0.21.4