############################################################################## ################# test handling of data received by messages ############### ##############################################################################
| 141 | // ################# test handling of data received by messages ############### |
| 142 | // ############################################################################## |
| 143 | void MQTTTest::testIntegerMessage() { |
| 144 | QSKIP("Unstable", QTest::SkipSingle); |
| 145 | |
| 146 | auto* filter = new AsciiFilter(); |
| 147 | |
| 148 | auto properties = filter->properties(); |
| 149 | properties.automaticSeparatorDetection = false; |
| 150 | properties.headerEnabled = false; |
| 151 | properties.columnModesString = QStringLiteral("Int"); |
| 152 | properties.intAsDouble = false; |
| 153 | QCOMPARE(filter->initialize(properties), AsciiFilter::Status::Success); // Livedata must be initialized! |
| 154 | |
| 155 | auto* project = new Project(); |
| 156 | |
| 157 | auto* mqttClient = new MQTTClient(QStringLiteral("test")); |
| 158 | project->addChild(mqttClient); |
| 159 | mqttClient->setFilter(filter); |
| 160 | mqttClient->setReadingType(MQTTClient::ReadingType::TillEnd); |
| 161 | mqttClient->setKeepNValues(100); // At least 8! |
| 162 | mqttClient->setUpdateType(MQTTClient::UpdateType::NewData); |
| 163 | mqttClient->setMQTTClientHostPort(mqttHostName, mqttPort); |
| 164 | mqttClient->setMQTTUseAuthentication(false); |
| 165 | mqttClient->setMQTTUseID(false); |
| 166 | QMqttTopicFilter topicFilter{QStringLiteral("labplot/mqttUnitTest")}; |
| 167 | mqttClient->addInitialMQTTSubscriptions(topicFilter, 0); |
| 168 | mqttClient->read(); |
| 169 | mqttClient->ready(); |
| 170 | |
| 171 | auto* client = new QMqttClient(); |
| 172 | client->setHostname(mqttHostName); |
| 173 | client->setPort(mqttPort); |
| 174 | client->connectToHost(); |
| 175 | |
| 176 | bool wait = QTest::qWaitFor( |
| 177 | [&]() { |
| 178 | return (client->state() == QMqttClient::Connected); |
| 179 | }, |
| 180 | 5000); |
| 181 | QCOMPARE(wait, true); |
| 182 | |
| 183 | auto* subscription = client->subscribe(topicFilter, 0); |
| 184 | if (subscription) { |
| 185 | { |
| 186 | const QStringList data = { |
| 187 | QStringLiteral("1"), |
| 188 | QStringLiteral("2"), |
| 189 | QStringLiteral("3"), |
| 190 | }; |
| 191 | QString savePath; |
| 192 | SAVE_FILE("testfile", data); |
| 193 | QFile file(savePath); |
| 194 | |
| 195 | if (file.open(QIODevice::ReadOnly)) { |
| 196 | QTextStream in(&file); |
| 197 | QString message = in.readAll(); |
| 198 | client->publish(topicFilter.filter(), message.toUtf8(), 0); |
| 199 | } |
| 200 | file.close(); |
nothing calls this directly
no test coverage detected