Commit 8cabbca0c54e8731a00862f5e683402dccdfe8a7
1 parent
08a352db
Convert test_retained to native test client
Showing
1 changed file
with
34 additions
and
21 deletions
FlashMQTests/tst_maintests.cpp
| @@ -408,35 +408,48 @@ void MainTests::test_validSubscribePath() | @@ -408,35 +408,48 @@ void MainTests::test_validSubscribePath() | ||
| 408 | 408 | ||
| 409 | void MainTests::test_retained() | 409 | void MainTests::test_retained() |
| 410 | { | 410 | { |
| 411 | - TwoClientTestContext testContext; | 411 | + FlashMQTestClient sender; |
| 412 | + FlashMQTestClient receiver; | ||
| 412 | 413 | ||
| 413 | - QByteArray payload = "We are testing"; | ||
| 414 | - QString topic = "retaintopic"; | 414 | + sender.start(); |
| 415 | + receiver.start(); | ||
| 415 | 416 | ||
| 416 | - testContext.connectSender(); | ||
| 417 | - testContext.publish(topic, payload, true); | ||
| 418 | - testContext.publish("dummy2", "Nobody sees this", true); | 417 | + const std::string payload = "We are testing"; |
| 418 | + const std::string topic = "retaintopic"; | ||
| 419 | 419 | ||
| 420 | - testContext.connectReceiver(); | ||
| 421 | - testContext.subscribeReceiver("dummy"); | ||
| 422 | - testContext.subscribeReceiver(topic); | ||
| 423 | - testContext.waitReceiverReceived(1); | 420 | + sender.connectClient(ProtocolVersion::Mqtt311); |
| 424 | 421 | ||
| 425 | - QCOMPARE(testContext.receivedMessages.count(), 1); | 422 | + Publish pub1(topic, payload, 0); |
| 423 | + pub1.retain = true; | ||
| 424 | + sender.publish(pub1); | ||
| 426 | 425 | ||
| 427 | - QMQTT::Message msg = testContext.receivedMessages.first(); | ||
| 428 | - QCOMPARE(msg.payload(), payload); | ||
| 429 | - QVERIFY(msg.retain()); | 426 | + Publish pub2("dummy2", "Nobody sees this", 0); |
| 427 | + pub2.retain = true; | ||
| 428 | + sender.publish(pub2); | ||
| 430 | 429 | ||
| 431 | - testContext.receivedMessages.clear(); | 430 | + receiver.connectClient(ProtocolVersion::Mqtt311); |
| 431 | + receiver.subscribe("dummy", 0); | ||
| 432 | + receiver.subscribe(topic, 0); | ||
| 432 | 433 | ||
| 433 | - testContext.publish(topic, payload, true); | ||
| 434 | - testContext.waitReceiverReceived(1); | 434 | + receiver.waitForMessageCount(1); |
| 435 | + | ||
| 436 | + MYCASTCOMPARE(receiver.receivedPublishes.size(), 1); | ||
| 437 | + | ||
| 438 | + MqttPacket &msg = receiver.receivedPublishes.front(); | ||
| 439 | + QCOMPARE(msg.getPayloadCopy(), payload); | ||
| 440 | + QCOMPARE(msg.getTopic(), topic); | ||
| 441 | + QVERIFY(msg.getRetain()); | ||
| 442 | + | ||
| 443 | + receiver.clearReceivedLists(); | ||
| 444 | + | ||
| 445 | + sender.publish(pub1); | ||
| 446 | + receiver.waitForMessageCount(1); | ||
| 435 | 447 | ||
| 436 | - QVERIFY2(testContext.receivedMessages.count() == 1, "There must be one message in the received list"); | ||
| 437 | - QMQTT::Message msg2 = testContext.receivedMessages.first(); | ||
| 438 | - QCOMPARE(msg2.payload(), payload); | ||
| 439 | - QVERIFY2(!msg2.retain(), "Getting a retained message while already being subscribed must be marked as normal, not retain."); | 448 | + QVERIFY2(receiver.receivedPublishes.size() == 1, "There must be one message in the received list"); |
| 449 | + MqttPacket &msg2 = receiver.receivedPublishes.front(); | ||
| 450 | + QCOMPARE(msg2.getPayloadCopy(), payload); | ||
| 451 | + QCOMPARE(msg2.getTopic(), topic); | ||
| 452 | + QVERIFY2(!msg2.getRetain(), "Getting a retained message while already being subscribed must be marked as normal, not retain."); | ||
| 440 | } | 453 | } |
| 441 | 454 | ||
| 442 | void MainTests::test_retained_changed() | 455 | void MainTests::test_retained_changed() |