Commit 08a352db329c277a88c9bf45ceeba56d473f02fb

Authored by Wiebe Cazemier
1 parent 227a4b3a

Convert testDowngradeQoSOnSubscribeHelper to native test client

And make it test accross protocol versions.
Showing 1 changed file with 27 additions and 15 deletions
FlashMQTests/tst_maintests.cpp
@@ -1229,27 +1229,39 @@ void MainTests::testParsePacket() @@ -1229,27 +1229,39 @@ void MainTests::testParsePacket()
1229 1229
1230 void testDowngradeQoSOnSubscribeHelper(const char pub_qos, const char sub_qos) 1230 void testDowngradeQoSOnSubscribeHelper(const char pub_qos, const char sub_qos)
1231 { 1231 {
1232 - TwoClientTestContext testContext; 1232 + std::vector<ProtocolVersion> protocols {ProtocolVersion::Mqtt311, ProtocolVersion::Mqtt5};
1233 1233
1234 - const QString topic("Star/Trek");  
1235 - const QByteArray payload("Captain Kirk"); 1234 + for (const ProtocolVersion senderVersion : protocols)
  1235 + {
  1236 + for (const ProtocolVersion receiverVersion : protocols)
  1237 + {
  1238 + FlashMQTestClient sender;
  1239 + FlashMQTestClient receiver;
1236 1240
1237 - testContext.connectSender();  
1238 - testContext.connectReceiver(); 1241 + sender.start();
  1242 + receiver.start();
1239 1243
1240 - testContext.subscribeReceiver(topic, sub_qos);  
1241 - testContext.publish(topic, payload, pub_qos, false); 1244 + const std::string topic("Star/Trek");
  1245 + const std::string payload("Captain Kirk");
1242 1246
1243 - testContext.waitReceiverReceived(1); 1247 + sender.connectClient(senderVersion);
  1248 + receiver.connectClient(receiverVersion);
1244 1249
1245 - QCOMPARE(testContext.receivedMessages.length(), 1);  
1246 - QMQTT::Message &recv = testContext.receivedMessages.first(); 1250 + receiver.subscribe(topic, sub_qos);
  1251 + sender.publish(topic, payload, pub_qos);
  1252 +
  1253 + receiver.waitForMessageCount(1);
1247 1254
1248 - const char expected_qos = std::min<const char>(pub_qos, sub_qos);  
1249 - QVERIFY2(recv.qos() == expected_qos, formatString("Failure: received QoS is %d. Published is %d. Subscribed as %d. Expected QoS is %d",  
1250 - recv.qos(), pub_qos, sub_qos, expected_qos).c_str());  
1251 - QVERIFY(recv.topic() == topic);  
1252 - QVERIFY(recv.payload() == payload); 1255 + MYCASTCOMPARE(receiver.receivedPublishes.size(), 1);
  1256 + MqttPacket &recv = receiver.receivedPublishes.front();
  1257 +
  1258 + const char expected_qos = std::min<const char>(pub_qos, sub_qos);
  1259 + QVERIFY2(recv.getQos() == expected_qos, formatString("Failure: received QoS is %d. Published is %d. Subscribed as %d. Expected QoS is %d",
  1260 + recv.getQos(), pub_qos, sub_qos, expected_qos).c_str());
  1261 + QVERIFY(recv.getTopic() == topic);
  1262 + QVERIFY(recv.getPayloadCopy() == payload);
  1263 + }
  1264 + }
1253 } 1265 }
1254 1266
1255 void MainTests::testDowngradeQoSOnSubscribeQos2to2() 1267 void MainTests::testDowngradeQoSOnSubscribeQos2to2()