Commit a6d7395ea2d1a9949fc8833f083d96fc7660c0e3
1 parent
e1043748
Repurpose packet copy test
Showing
1 changed file
with
16 additions
and
35 deletions
FlashMQTests/tst_maintests.cpp
| @@ -57,6 +57,8 @@ class MainTests : public QObject | @@ -57,6 +57,8 @@ class MainTests : public QObject | ||
| 57 | 57 | ||
| 58 | QScopedPointer<MainAppThread> mainApp; | 58 | QScopedPointer<MainAppThread> mainApp; |
| 59 | 59 | ||
| 60 | + void testParsePacketHelper(const std::string &topic, char from_qos, bool retain); | ||
| 61 | + | ||
| 60 | public: | 62 | public: |
| 61 | MainTests(); | 63 | MainTests(); |
| 62 | ~MainTests(); | 64 | ~MainTests(); |
| @@ -102,7 +104,7 @@ private slots: | @@ -102,7 +104,7 @@ private slots: | ||
| 102 | 104 | ||
| 103 | void testSavingSessions(); | 105 | void testSavingSessions(); |
| 104 | 106 | ||
| 105 | - void testCopyPacket(); | 107 | + void testParsePacket(); |
| 106 | 108 | ||
| 107 | void testDowngradeQoSOnSubscribeQos2to2(); | 109 | void testDowngradeQoSOnSubscribeQos2to2(); |
| 108 | void testDowngradeQoSOnSubscribeQos2to1(); | 110 | void testDowngradeQoSOnSubscribeQos2to1(); |
| @@ -1104,10 +1106,8 @@ void MainTests::testSavingSessions() | @@ -1104,10 +1106,8 @@ void MainTests::testSavingSessions() | ||
| 1104 | } | 1106 | } |
| 1105 | } | 1107 | } |
| 1106 | 1108 | ||
| 1107 | -void testCopyPacketHelper(const std::string &topic, char from_qos, char to_qos, bool retain) | 1109 | +void MainTests::testParsePacketHelper(const std::string &topic, char from_qos, bool retain) |
| 1108 | { | 1110 | { |
| 1109 | - assert(to_qos <= from_qos); | ||
| 1110 | - | ||
| 1111 | Logger::getInstance()->setFlags(false, false, true); | 1111 | Logger::getInstance()->setFlags(false, false, true); |
| 1112 | 1112 | ||
| 1113 | std::shared_ptr<Settings> settings(new Settings()); | 1113 | std::shared_ptr<Settings> settings(new Settings()); |
| @@ -1145,48 +1145,29 @@ void testCopyPacketHelper(const std::string &topic, char from_qos, char to_qos, | @@ -1145,48 +1145,29 @@ void testCopyPacketHelper(const std::string &topic, char from_qos, char to_qos, | ||
| 1145 | parsedPacketOne.handlePublish(); | 1145 | parsedPacketOne.handlePublish(); |
| 1146 | if (retain) // A normal handled packet always has retain=0, so I force setting it here. | 1146 | if (retain) // A normal handled packet always has retain=0, so I force setting it here. |
| 1147 | parsedPacketOne.setRetain(); | 1147 | parsedPacketOne.setRetain(); |
| 1148 | + | ||
| 1148 | QCOMPARE(stagingPacketOne.getTopic(), parsedPacketOne.getTopic()); | 1149 | QCOMPARE(stagingPacketOne.getTopic(), parsedPacketOne.getTopic()); |
| 1149 | QCOMPARE(stagingPacketOne.getPayloadCopy(), parsedPacketOne.getPayloadCopy()); | 1150 | QCOMPARE(stagingPacketOne.getPayloadCopy(), parsedPacketOne.getPayloadCopy()); |
| 1150 | - | ||
| 1151 | - /* | ||
| 1152 | - std::shared_ptr<MqttPacket> copiedPacketOne = parsedPacketOne.getCopy(to_qos); | ||
| 1153 | - | ||
| 1154 | - QCOMPARE(payloadOne, copiedPacketOne->getPayloadCopy()); | ||
| 1155 | - | ||
| 1156 | - // Now compare the written buffer of our copied packet to one that was written with our known good reference packet. | ||
| 1157 | - | ||
| 1158 | - Publish pubReference(topic, payloadOne, to_qos); | ||
| 1159 | - pubReference.retain = retain; | ||
| 1160 | - MqttPacket packetReference(ProtocolVersion::Mqtt311, pubReference); | ||
| 1161 | - QCOMPARE(packetReference.getQos(), copiedPacketOne->getQos()); | ||
| 1162 | - if (to_qos > 0) | ||
| 1163 | - packetReference.setPacketId(pack_id); | ||
| 1164 | - CirBuf bufOfReference(1024); | ||
| 1165 | - CirBuf bufOfCopied(1024); | ||
| 1166 | - packetReference.readIntoBuf(bufOfReference); | ||
| 1167 | - copiedPacketOne->readIntoBuf(bufOfCopied); | ||
| 1168 | - QVERIFY2(bufOfCopied == bufOfReference, formatString("Failure on length %d for topic %s, from qos %d to qos %d, retain: %d.", | ||
| 1169 | - len, topic.c_str(), from_qos, to_qos, retain).c_str()); | ||
| 1170 | - */ | 1151 | + QCOMPARE(stagingPacketOne.getRetain(), parsedPacketOne.getRetain()); |
| 1152 | + QCOMPARE(stagingPacketOne.getQos(), parsedPacketOne.getQos()); | ||
| 1153 | + QCOMPARE(stagingPacketOne.first_byte, parsedPacketOne.first_byte); | ||
| 1171 | } | 1154 | } |
| 1172 | } | 1155 | } |
| 1173 | 1156 | ||
| 1174 | /** | 1157 | /** |
| 1175 | - * @brief MainTests::testCopyPacket tests the actual bytes of a copied that would be written to a client. | ||
| 1176 | - * | ||
| 1177 | - * This is specifically to test the optimiziations in getCopy(). It indirectly also tests packet parsing. | 1158 | + * @brief MainTests::testCopyPacket tests the actual bytes of a published packet that would be written to a client. |
| 1178 | */ | 1159 | */ |
| 1179 | -void MainTests::testCopyPacket() | 1160 | +void MainTests::testParsePacket() |
| 1180 | { | 1161 | { |
| 1181 | for (int retain = 0; retain < 2; retain++) | 1162 | for (int retain = 0; retain < 2; retain++) |
| 1182 | { | 1163 | { |
| 1183 | - testCopyPacketHelper("John/McLane", 0, 0, retain); | ||
| 1184 | - testCopyPacketHelper("Ben/Sisko", 1, 1, retain); | ||
| 1185 | - testCopyPacketHelper("Rebecca/Bunch", 2, 2, retain); | 1164 | + testParsePacketHelper("John/McLane", 0, retain); |
| 1165 | + testParsePacketHelper("Ben/Sisko", 1, retain); | ||
| 1166 | + testParsePacketHelper("Rebecca/Bunch", 2, retain); | ||
| 1186 | 1167 | ||
| 1187 | - testCopyPacketHelper("Buffy/Slayer", 1, 0, retain); | ||
| 1188 | - testCopyPacketHelper("Sarah/Connor", 2, 0, retain); | ||
| 1189 | - testCopyPacketHelper("Susan/Mayer", 2, 1, retain); | 1168 | + testParsePacketHelper("Buffy/Slayer", 1, retain); |
| 1169 | + testParsePacketHelper("Sarah/Connor", 2, retain); | ||
| 1170 | + testParsePacketHelper("Susan/Mayer", 2, retain); | ||
| 1190 | } | 1171 | } |
| 1191 | } | 1172 | } |
| 1192 | 1173 |