| 260 | } |
| 261 | |
| 262 | void MQTTTest::testNumericMessage() { |
| 263 | QSKIP("Unstable", QTest::SkipSingle); |
| 264 | |
| 265 | auto* filter = new AsciiFilter(); |
| 266 | |
| 267 | auto properties = filter->properties(); |
| 268 | properties.automaticSeparatorDetection = false; |
| 269 | properties.headerEnabled = false; |
| 270 | properties.columnModesString = QStringLiteral("Double"); |
| 271 | properties.intAsDouble = false; |
| 272 | QCOMPARE(filter->initialize(properties), AsciiFilter::Status::Success); // Livedata must be initialized! |
| 273 | |
| 274 | Project* project = new Project(); |
| 275 | |
| 276 | auto* mqttClient = new MQTTClient(QStringLiteral("test")); |
| 277 | project->addChild(mqttClient); |
| 278 | mqttClient->setFilter(filter); |
| 279 | mqttClient->setReadingType(MQTTClient::ReadingType::TillEnd); |
| 280 | mqttClient->setKeepNValues(100); // At least 8! |
| 281 | mqttClient->setUpdateType(MQTTClient::UpdateType::NewData); |
| 282 | mqttClient->setMQTTClientHostPort(mqttHostName, mqttPort); |
| 283 | mqttClient->setMQTTUseAuthentication(false); |
| 284 | mqttClient->setMQTTUseID(false); |
| 285 | QMqttTopicFilter topicFilter{QStringLiteral("labplot/mqttUnitTest")}; |
| 286 | mqttClient->addInitialMQTTSubscriptions(topicFilter, 0); |
| 287 | mqttClient->read(); |
| 288 | mqttClient->ready(); |
| 289 | |
| 290 | auto* client = new QMqttClient(); |
| 291 | client->setHostname(mqttHostName); |
| 292 | client->setPort(mqttPort); |
| 293 | client->connectToHost(); |
| 294 | |
| 295 | bool wait = QTest::qWaitFor( |
| 296 | [&]() { |
| 297 | return (client->state() == QMqttClient::Connected); |
| 298 | }, |
| 299 | 5000); |
| 300 | QCOMPARE(wait, true); |
| 301 | |
| 302 | auto* subscription = client->subscribe(topicFilter, 0); |
| 303 | if (subscription) { |
| 304 | { |
| 305 | const QStringList data = { |
| 306 | QStringLiteral("1.5"), |
| 307 | QStringLiteral(""), |
| 308 | QStringLiteral(""), |
| 309 | QStringLiteral("2.7"), |
| 310 | QStringLiteral(""), |
| 311 | QStringLiteral(""), |
| 312 | QStringLiteral("3.9"), |
| 313 | }; |
| 314 | QString savePath; |
| 315 | SAVE_FILE("testfile", data); |
| 316 | QFile file(savePath); |
| 317 | |
| 318 | if (file.open(QIODevice::ReadOnly)) { |
| 319 | QTextStream in(&file); |
nothing calls this directly
no test coverage detected