File indexing completed on 2024-04-21 14:49:23
0001 /*************************************************************************** 0002 File : MQTTUnitTest.cpp 0003 Project : LabPlot 0004 Description : Tests for MQTT related features 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2018 Kovacs Ferencz (kferike98@gmail.com) 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 * This program is distributed in the hope that it will be useful, * 0017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0019 * GNU General Public License for more details. * 0020 * * 0021 * You should have received a copy of the GNU General Public License * 0022 * along with this program; if not, write to the Free Software * 0023 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0024 * Boston, MA 02110-1301 USA * 0025 * * 0026 ***************************************************************************/ 0027 0028 #include "MQTTUnitTest.h" 0029 0030 #ifdef HAVE_MQTT 0031 #include "backend/datasources/filters/AsciiFilter.h" 0032 #include "backend/datasources/MQTTClient.h" 0033 #include "backend/datasources/MQTTSubscription.h" 0034 #include "backend/datasources/MQTTTopic.h" 0035 #include "backend/core/Project.h" 0036 #include "kdefrontend/dockwidgets/LiveDataDock.h" 0037 0038 #include <QFile> 0039 #include <QTextStream> 0040 #include <QDebug> 0041 #include <QVector> 0042 #include <QTimer> 0043 #include <QEventLoop> 0044 #include <QTreeWidgetItem> 0045 0046 void MQTTUnitTest::initTestCase() { 0047 const QString currentDir = __FILE__; 0048 m_dataDir = currentDir.left(currentDir.lastIndexOf(QDir::separator())) + QDir::separator() + QLatin1String("data") + QDir::separator(); 0049 0050 // needed in order to have the signals triggered by SignallingUndoCommand, see LabPlot.cpp 0051 //TODO: redesign/remove this 0052 qRegisterMetaType<const AbstractAspect*>("const AbstractAspect*"); 0053 qRegisterMetaType<const AbstractColumn*>("const AbstractColumn*"); 0054 } 0055 0056 //############################################################################## 0057 //################### check superior and inferior relations ################## 0058 //############################################################################## 0059 void MQTTUnitTest::testContainFalse() { 0060 MQTTClient* client = new MQTTClient("test"); 0061 const QString fileName = m_dataDir + "contain_false.txt"; 0062 QFile file(fileName); 0063 0064 if(file.open(QIODevice::ReadOnly)) { 0065 QTextStream in(&file); 0066 0067 while(!in.atEnd()) { 0068 QString line = in.readLine(); 0069 #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) 0070 QStringList topics = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); 0071 #else 0072 QStringList topics = line.split(QLatin1Char(' '), QString::SkipEmptyParts); 0073 #endif 0074 QCOMPARE(client->checkTopicContains(topics[0], topics[1]), false); 0075 } 0076 0077 delete client; 0078 file.close(); 0079 } 0080 } 0081 0082 void MQTTUnitTest::testContainTrue() { 0083 MQTTClient* client = new MQTTClient("test"); 0084 const QString fileName = m_dataDir + "contain_true.txt"; 0085 QFile file(fileName); 0086 0087 if(file.open(QIODevice::ReadOnly)) { 0088 QTextStream in(&file); 0089 0090 while(!in.atEnd()) { 0091 QString line = in.readLine(); 0092 #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) 0093 QStringList topics = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); 0094 #else 0095 QStringList topics = line.split(QLatin1Char(' '), QString::SkipEmptyParts); 0096 #endif 0097 QCOMPARE(client->checkTopicContains(topics[0], topics[1]), true); 0098 } 0099 0100 delete client; 0101 file.close(); 0102 } 0103 } 0104 0105 //############################################################################## 0106 //############################ check common topics ########################### 0107 //############################################################################## 0108 void MQTTUnitTest::testCommonTrue(){ 0109 MQTTClient* client = new MQTTClient("test"); 0110 const QString fileName = m_dataDir + "common_true.txt"; 0111 QFile file(fileName); 0112 0113 if(file.open(QIODevice::ReadOnly)) { 0114 QTextStream in(&file); 0115 0116 while(!in.atEnd()) { 0117 QString line = in.readLine(); 0118 #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) 0119 QStringList topics = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); 0120 #else 0121 QStringList topics = line.split(QLatin1Char(' '), QString::SkipEmptyParts); 0122 #endif 0123 QCOMPARE(client->checkCommonLevel(topics[0], topics[1]), topics[2]); 0124 } 0125 0126 delete client; 0127 file.close(); 0128 } 0129 } 0130 0131 void MQTTUnitTest::testCommonFalse(){ 0132 MQTTClient* client = new MQTTClient("test"); 0133 const QString fileName = m_dataDir + "common_false.txt"; 0134 QFile file(fileName); 0135 0136 if(file.open(QIODevice::ReadOnly)) { 0137 QTextStream in(&file); 0138 0139 while(!in.atEnd()) { 0140 QString line = in.readLine(); 0141 #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) 0142 QStringList topics = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); 0143 #else 0144 QStringList topics = line.split(QLatin1Char(' '), QString::SkipEmptyParts); 0145 #endif 0146 QCOMPARE(client->checkCommonLevel(topics[0], topics[1]), ""); 0147 } 0148 0149 delete client; 0150 file.close(); 0151 } 0152 } 0153 0154 //############################################################################## 0155 //################# test handling of data received by messages ############### 0156 //############################################################################## 0157 void MQTTUnitTest::testIntegerMessage() { 0158 AsciiFilter* filter = new AsciiFilter(); 0159 filter->setAutoModeEnabled(true); 0160 0161 Project* project = new Project(); 0162 0163 MQTTClient* mqttClient = new MQTTClient("test"); 0164 project->addChild(mqttClient); 0165 mqttClient->setFilter(filter); 0166 mqttClient->setReadingType(MQTTClient::ReadingType::TillEnd); 0167 mqttClient->setKeepNValues(0); 0168 mqttClient->setUpdateType(MQTTClient::UpdateType::NewData); 0169 mqttClient->setMQTTClientHostPort("broker.hivemq.com", 1883); 0170 mqttClient->setMQTTUseAuthentication(false); 0171 mqttClient->setMQTTUseID(false); 0172 QMqttTopicFilter topicFilter {"labplot/mqttUnitTest"}; 0173 mqttClient->addInitialMQTTSubscriptions(topicFilter, 0); 0174 mqttClient->read(); 0175 mqttClient->ready(); 0176 0177 QMqttClient* client = new QMqttClient(); 0178 client->setHostname("broker.hivemq.com"); 0179 client->setPort(1883); 0180 client->connectToHost(); 0181 0182 bool wait = QTest::qWaitFor([&]() { 0183 return (client->state() == QMqttClient::Connected); 0184 }, 5000); 0185 QCOMPARE(wait, true); 0186 0187 QMqttSubscription* subscription = client->subscribe(topicFilter, 0); 0188 if(subscription) { 0189 const QString fileName = m_dataDir + "integer_message_1.txt"; 0190 QFile file(fileName); 0191 0192 if(file.open(QIODevice::ReadOnly)) { 0193 QTextStream in(&file); 0194 QString message = in.readAll(); 0195 client->publish(topicFilter.filter(), message.toUtf8(), 0); 0196 } 0197 file.close(); 0198 0199 0200 QTimer timer; 0201 timer.setSingleShot(true); 0202 QEventLoop* loop = new QEventLoop(); 0203 connect(mqttClient, &MQTTClient::MQTTTopicsChanged, loop, &QEventLoop::quit); 0204 connect( (&timer), &QTimer::timeout, loop, &QEventLoop::quit); 0205 timer.start(5000); 0206 loop->exec(); 0207 0208 const MQTTTopic* testTopic = nullptr; 0209 0210 if(timer.isActive()) { 0211 QVector<const MQTTTopic*> topic = mqttClient->children <const MQTTTopic>(AbstractAspect::ChildIndexFlag::Recursive); 0212 for (const auto& top : topic) { 0213 if (top->topicName() == "labplot/mqttUnitTest") { 0214 testTopic = top; 0215 break; 0216 } 0217 } 0218 0219 if (testTopic) { 0220 Column* value = testTopic->column(testTopic->columnCount() - 1); 0221 QCOMPARE(value->columnMode(), Column::ColumnMode::Integer); 0222 QCOMPARE(value->rowCount(), 3); 0223 QCOMPARE(value->valueAt(0), 1); 0224 QCOMPARE(value->valueAt(1), 2); 0225 QCOMPARE(value->valueAt(2), 3); 0226 0227 const QString fileName2 = m_dataDir + "integer_message_2.txt"; 0228 QFile file2(fileName2); 0229 0230 if(file2.open(QIODevice::ReadOnly)) { 0231 QTextStream in2(&file2); 0232 QString message = in2.readAll(); 0233 client->publish(topicFilter.filter(), message.toUtf8(), 0); 0234 } 0235 file2.close(); 0236 0237 QTest::qWait(1000); 0238 0239 QCOMPARE(value->rowCount(), 8); 0240 QCOMPARE(value->valueAt(3), 6); 0241 QCOMPARE(value->valueAt(4), 0); 0242 QCOMPARE(value->valueAt(5), 0); 0243 QCOMPARE(value->valueAt(6), 0); 0244 QCOMPARE(value->valueAt(7), 3); 0245 } 0246 } 0247 } 0248 } 0249 0250 void MQTTUnitTest::testNumericMessage() { 0251 AsciiFilter* filter = new AsciiFilter(); 0252 filter->setAutoModeEnabled(true); 0253 0254 Project* project = new Project(); 0255 0256 MQTTClient* mqttClient = new MQTTClient("test"); 0257 project->addChild(mqttClient); 0258 mqttClient->setFilter(filter); 0259 mqttClient->setReadingType(MQTTClient::ReadingType::TillEnd); 0260 mqttClient->setKeepNValues(0); 0261 mqttClient->setUpdateType(MQTTClient::UpdateType::NewData); 0262 mqttClient->setMQTTClientHostPort("broker.hivemq.com", 1883); 0263 mqttClient->setMQTTUseAuthentication(false); 0264 mqttClient->setMQTTUseID(false); 0265 QMqttTopicFilter topicFilter {"labplot/mqttUnitTest"}; 0266 mqttClient->addInitialMQTTSubscriptions(topicFilter, 0); 0267 mqttClient->read(); 0268 mqttClient->ready(); 0269 0270 QMqttClient* client = new QMqttClient(); 0271 client->setHostname("broker.hivemq.com"); 0272 client->setPort(1883); 0273 client->connectToHost(); 0274 0275 bool wait = QTest::qWaitFor([&]() { 0276 return (client->state() == QMqttClient::Connected); 0277 }, 5000); 0278 QCOMPARE(wait, true); 0279 0280 QMqttSubscription* subscription = client->subscribe(topicFilter, 0); 0281 if(subscription) { 0282 const QString fileName = m_dataDir + "numeric_message_1.txt"; 0283 QFile file(fileName); 0284 0285 if(file.open(QIODevice::ReadOnly)) { 0286 QTextStream in(&file); 0287 QString message = in.readAll(); 0288 client->publish(topicFilter.filter(), message.toUtf8(), 0); 0289 } 0290 file.close(); 0291 0292 0293 QTimer timer; 0294 timer.setSingleShot(true); 0295 QEventLoop* loop = new QEventLoop(); 0296 connect(mqttClient, &MQTTClient::MQTTTopicsChanged, loop, &QEventLoop::quit); 0297 connect( (&timer), &QTimer::timeout, loop, &QEventLoop::quit); 0298 timer.start(5000); 0299 loop->exec(); 0300 0301 const MQTTTopic* testTopic = nullptr; 0302 0303 if(timer.isActive()) { 0304 QVector<const MQTTTopic*> topic = mqttClient->children <const MQTTTopic>(AbstractAspect::ChildIndexFlag::Recursive); 0305 for (const auto& top: topic) { 0306 if (top->topicName() == "labplot/mqttUnitTest") { 0307 testTopic = top; 0308 break; 0309 } 0310 } 0311 0312 if (testTopic) { 0313 Column* value = testTopic->column(testTopic->columnCount() - 1); 0314 QCOMPARE(value->columnMode(), Column::ColumnMode::Numeric); 0315 QCOMPARE(value->rowCount(), 3); 0316 QCOMPARE(value->valueAt(0), 1.5); 0317 QCOMPARE(value->valueAt(1), 2.7); 0318 QCOMPARE(value->valueAt(2), 3.9); 0319 0320 const QString fileName2 = m_dataDir + "numeric_message_2.txt"; 0321 QFile file2(fileName2); 0322 0323 if(file2.open(QIODevice::ReadOnly)) { 0324 QTextStream in2(&file2); 0325 QString message = in2.readAll(); 0326 client->publish(topicFilter.filter(), message.toUtf8(), 0); 0327 } 0328 file2.close(); 0329 0330 QTest::qWait(1000); 0331 0332 QCOMPARE(value->rowCount(), 8); 0333 QCOMPARE(value->valueAt(3), 6); 0334 QCOMPARE((bool)std::isnan(value->valueAt(4)), true); 0335 QCOMPARE((bool)std::isnan(value->valueAt(5)), true); 0336 QCOMPARE((bool)std::isnan(value->valueAt(6)), true); 0337 QCOMPARE(value->valueAt(7), 0.0098); 0338 } 0339 } 0340 } 0341 } 0342 0343 void MQTTUnitTest::testTextMessage() { 0344 AsciiFilter* filter = new AsciiFilter(); 0345 filter->setAutoModeEnabled(true); 0346 0347 Project* project = new Project(); 0348 0349 MQTTClient* mqttClient = new MQTTClient("test"); 0350 project->addChild(mqttClient); 0351 mqttClient->setFilter(filter); 0352 mqttClient->setReadingType(MQTTClient::ReadingType::TillEnd); 0353 mqttClient->setKeepNValues(0); 0354 mqttClient->setUpdateType(MQTTClient::UpdateType::NewData); 0355 mqttClient->setMQTTClientHostPort("broker.hivemq.com", 1883); 0356 mqttClient->setMQTTUseAuthentication(false); 0357 mqttClient->setMQTTUseID(false); 0358 QMqttTopicFilter topicFilter {"labplot/mqttUnitTest"}; 0359 mqttClient->addInitialMQTTSubscriptions(topicFilter, 0); 0360 mqttClient->read(); 0361 mqttClient->ready(); 0362 0363 QMqttClient* client = new QMqttClient(); 0364 client->setHostname("broker.hivemq.com"); 0365 client->setPort(1883); 0366 client->connectToHost(); 0367 0368 bool wait = QTest::qWaitFor([&]() { 0369 return (client->state() == QMqttClient::Connected); 0370 }, 5000); 0371 QCOMPARE(wait, true); 0372 0373 QMqttSubscription* subscription = client->subscribe(topicFilter, 0); 0374 if(subscription) { 0375 const QString fileName = m_dataDir + "text_message.txt"; 0376 QFile file(fileName); 0377 0378 if(file.open(QIODevice::ReadOnly)) { 0379 QTextStream in(&file); 0380 QString message = in.readAll(); 0381 client->publish(topicFilter.filter(), message.toUtf8(), 0); 0382 } 0383 file.close(); 0384 0385 0386 QTimer timer; 0387 timer.setSingleShot(true); 0388 QEventLoop* loop = new QEventLoop(); 0389 connect(mqttClient, &MQTTClient::MQTTTopicsChanged, loop, &QEventLoop::quit); 0390 connect( (&timer), &QTimer::timeout, loop, &QEventLoop::quit); 0391 timer.start(5000); 0392 loop->exec(); 0393 0394 const MQTTTopic* testTopic = nullptr; 0395 0396 if(timer.isActive()) { 0397 QVector<const MQTTTopic*> topic = mqttClient->children <const MQTTTopic>(AbstractAspect::ChildIndexFlag::Recursive); 0398 for (const auto& top : topic) { 0399 if (top->topicName() == "labplot/mqttUnitTest") { 0400 testTopic = top; 0401 break; 0402 } 0403 } 0404 0405 if (testTopic) { 0406 Column* value = testTopic->column(testTopic->columnCount() - 1); 0407 QCOMPARE(value->columnMode(), Column::ColumnMode::Text); 0408 QCOMPARE(value->rowCount(), 5); 0409 QCOMPARE(value->textAt(0), "ball"); 0410 QCOMPARE(value->textAt(1), "cat"); 0411 QCOMPARE(value->textAt(2), "dog"); 0412 QCOMPARE(value->textAt(3), "house"); 0413 QCOMPARE(value->textAt(4), "Barcelona"); 0414 } 0415 } 0416 } 0417 } 0418 0419 //############################################################################## 0420 //##################### test subscribing and unsubscribing ################### 0421 //############################################################################## 0422 void MQTTUnitTest::testSubscriptions() { 0423 AsciiFilter* filter = new AsciiFilter(); 0424 filter->setAutoModeEnabled(true); 0425 0426 Project* project = new Project(); 0427 0428 MQTTClient* mqttClient = new MQTTClient("test"); 0429 project->addChild(mqttClient); 0430 mqttClient->setFilter(filter); 0431 mqttClient->setReadingType(MQTTClient::ReadingType::TillEnd); 0432 mqttClient->setKeepNValues(0); 0433 mqttClient->setUpdateType(MQTTClient::UpdateType::NewData); 0434 mqttClient->setMQTTClientHostPort("broker.hivemq.com", 1883); 0435 mqttClient->setMQTTUseAuthentication(false); 0436 mqttClient->setMQTTUseID(false); 0437 mqttClient->setMQTTWillUse(false); 0438 QMqttTopicFilter topicFilter {"labplot/mqttUnitTest"}; 0439 mqttClient->addInitialMQTTSubscriptions(topicFilter, 0); 0440 0441 LiveDataDock* liveDock = new LiveDataDock(); 0442 liveDock->setMQTTClient(mqttClient); 0443 0444 mqttClient->read(); 0445 mqttClient->ready(); 0446 0447 QTimer timer; 0448 timer.setSingleShot(true); 0449 QEventLoop* loop = new QEventLoop(); 0450 connect(mqttClient, &MQTTClient::MQTTSubscribed, loop, &QEventLoop::quit); 0451 connect( (&timer), &QTimer::timeout, loop, &QEventLoop::quit); 0452 timer.start(5000); 0453 loop->exec(); 0454 0455 if(timer.isActive()) { 0456 delete loop; 0457 QMqttClient* client = new QMqttClient(); 0458 client->setHostname("broker.hivemq.com"); 0459 client->setPort(1883); 0460 client->connectToHost(); 0461 0462 bool wait = QTest::qWaitFor([&]() { 0463 return (client->state() == QMqttClient::Connected); 0464 }, 3000); 0465 QCOMPARE(wait, true); 0466 0467 QString fileName = m_dataDir + "subscribe_1.txt"; 0468 QFile* file = new QFile(fileName); 0469 0470 QTest::qWait(1000); 0471 0472 if(file->open(QIODevice::ReadOnly)) { 0473 QTextStream in(file); 0474 0475 while(!in.atEnd()) { 0476 QString line = in.readLine(); 0477 QMqttTopicFilter filter{line}; 0478 client->publish(filter.filter(), QString("test").toUtf8()); 0479 0480 QTimer timer2; 0481 timer2.setSingleShot(true); 0482 loop = new QEventLoop(); 0483 connect( (&timer2), &QTimer::timeout, loop, &QEventLoop::quit); 0484 connect(liveDock, &LiveDataDock::newTopic, this, [line, loop](const QString& topic) { 0485 if(topic == line) { 0486 loop->quit(); 0487 } 0488 }); 0489 timer2.start(5000); 0490 loop->exec(); 0491 0492 disconnect(liveDock, &LiveDataDock::newTopic, this, nullptr); 0493 } 0494 } 0495 0496 liveDock->testUnsubscribe("labplot/mqttUnitTest"); 0497 0498 file->close(); 0499 delete file; 0500 0501 fileName = m_dataDir + "subscribe_2.txt"; 0502 file = new QFile(fileName); 0503 if(file->open(QIODevice::ReadOnly)) { 0504 QTextStream in(file); 0505 while(!in.atEnd()) { 0506 QString topic = in.readLine(); 0507 bool found = liveDock->testSubscribe(topic); 0508 QCOMPARE(found, true); 0509 } 0510 } 0511 file->close(); 0512 delete file; 0513 0514 fileName = m_dataDir + "subscribe_2_result.txt"; 0515 file = new QFile(fileName); 0516 if(file->open(QIODevice::ReadOnly)) { 0517 QTextStream in(file); 0518 int count = in.readLine().simplified().toInt(); 0519 QCOMPARE(mqttClient->MQTTSubscriptions().size(), count); 0520 0521 while(!in.atEnd()) { 0522 QString topic = in.readLine(); 0523 QVector<QString> subscriptions = mqttClient->MQTTSubscriptions(); 0524 QCOMPARE(subscriptions.contains(topic), true); 0525 } 0526 } 0527 file->close(); 0528 delete file; 0529 0530 fileName = m_dataDir + "unsubscribe_1.txt"; 0531 file = new QFile(fileName); 0532 if(file->open(QIODevice::ReadOnly)) { 0533 QTextStream in(file); 0534 while(!in.atEnd()) { 0535 QString topic = in.readLine(); 0536 bool found = liveDock->testUnsubscribe(topic); 0537 QCOMPARE(found, true); 0538 } 0539 } 0540 file->close(); 0541 delete file; 0542 0543 fileName = m_dataDir + "unsubscribe_1_result.txt"; 0544 file = new QFile(fileName); 0545 if(file->open(QIODevice::ReadOnly)) { 0546 QTextStream in(file); 0547 int count = in.readLine().simplified().toInt(); 0548 QCOMPARE(mqttClient->MQTTSubscriptions().size(), count); 0549 0550 while(!in.atEnd()) { 0551 QString topic = in.readLine(); 0552 QVector<QString> subscriptions = mqttClient->MQTTSubscriptions(); 0553 QCOMPARE(subscriptions.contains(topic), true); 0554 } 0555 } 0556 file->close(); 0557 delete file; 0558 0559 fileName = m_dataDir + "subscribe_3.txt"; 0560 file = new QFile(fileName); 0561 if(file->open(QIODevice::ReadOnly)) { 0562 QTextStream in(file); 0563 while(!in.atEnd()) { 0564 QString topic = in.readLine(); 0565 bool found = liveDock->testSubscribe(topic); 0566 QCOMPARE(found, true); 0567 } 0568 } 0569 file->close(); 0570 delete file; 0571 0572 fileName = m_dataDir + "subscribe_3_result.txt"; 0573 file = new QFile(fileName); 0574 if(file->open(QIODevice::ReadOnly)) { 0575 QTextStream in(file); 0576 int count = in.readLine().simplified().toInt(); 0577 QCOMPARE(mqttClient->MQTTSubscriptions().size(), count); 0578 0579 while(!in.atEnd()) { 0580 QString topic = in.readLine(); 0581 QVector<QString> subscriptions = mqttClient->MQTTSubscriptions(); 0582 QCOMPARE(subscriptions.contains(topic), true); 0583 } 0584 } 0585 file->close(); 0586 delete file; 0587 0588 fileName = m_dataDir + "unsubscribe_2.txt"; 0589 file = new QFile(fileName); 0590 if(file->open(QIODevice::ReadOnly)) { 0591 QTextStream in(file); 0592 while(!in.atEnd()) { 0593 QString topic = in.readLine(); 0594 bool found = liveDock->testUnsubscribe(topic); 0595 QCOMPARE(found, true); 0596 } 0597 } 0598 file->close(); 0599 delete file; 0600 0601 fileName = m_dataDir + "unsubscribe_2_result.txt"; 0602 file = new QFile(fileName); 0603 if(file->open(QIODevice::ReadOnly)) { 0604 QTextStream in(file); 0605 int count = in.readLine().simplified().toInt(); 0606 QCOMPARE(mqttClient->MQTTSubscriptions().size(), count); 0607 0608 QVector<QString> subscriptions = mqttClient->MQTTSubscriptions(); 0609 while(!in.atEnd()) { 0610 QString topic = in.readLine(); 0611 QCOMPARE(subscriptions.contains(topic), true); 0612 } 0613 } 0614 file->close(); 0615 delete file; 0616 } 0617 } 0618 0619 QTEST_MAIN(MQTTUnitTest) 0620 0621 #endif //HAVE_MQTT