MCPcopy Create free account
hub / github.com/KDE/labplot / testTextMessage

Method testTextMessage

tests/import_export/MQTT/MQTTTest.cpp:393–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

391}
392
393void MQTTTest::testTextMessage() {
394 QSKIP("Unstable", QTest::SkipSingle);
395
396 auto* filter = new AsciiFilter();
397
398 auto properties = filter->properties();
399 properties.automaticSeparatorDetection = false;
400 properties.headerEnabled = false;
401 properties.columnModesString = QStringLiteral("Text");
402 properties.intAsDouble = false;
403 properties.commentCharacter = QStringLiteral("#");
404 QCOMPARE(filter->initialize(properties), AsciiFilter::Status::Success); // Livedata must be initialized!
405
406 Project* project = new Project();
407
408 auto* mqttClient = new MQTTClient(QStringLiteral("test"));
409 project->addChild(mqttClient);
410 mqttClient->setFilter(filter);
411 mqttClient->setReadingType(MQTTClient::ReadingType::TillEnd);
412 mqttClient->setKeepNValues(100); // At least 8!
413 mqttClient->setUpdateType(MQTTClient::UpdateType::NewData);
414 mqttClient->setMQTTClientHostPort(mqttHostName, mqttPort);
415 mqttClient->setMQTTUseAuthentication(false);
416 mqttClient->setMQTTUseID(false);
417 QMqttTopicFilter topicFilter{QStringLiteral("labplot/mqttUnitTest")};
418 mqttClient->addInitialMQTTSubscriptions(topicFilter, 0);
419 mqttClient->read();
420 mqttClient->ready();
421
422 auto* client = new QMqttClient();
423 client->setHostname(mqttHostName);
424 client->setPort(mqttPort);
425 client->connectToHost();
426
427 bool wait = QTest::qWaitFor(
428 [&]() {
429 return (client->state() == QMqttClient::Connected);
430 },
431 5000);
432 QCOMPARE(wait, true);
433
434 auto* subscription = client->subscribe(topicFilter, 0);
435 if (subscription) {
436 {
437 const QStringList data = {
438 QStringLiteral("ball"),
439 QStringLiteral("cat"),
440 QStringLiteral("#comment"),
441 QStringLiteral("dog"),
442 QStringLiteral("#comment something"),
443 QStringLiteral("#comment something new"),
444 QStringLiteral("house"),
445 QStringLiteral("Barcelona"),
446 };
447 QString savePath;
448 SAVE_FILE("testfile", data);
449 QFile file(savePath);
450

Callers

nothing calls this directly

Calls 15

setMQTTClientHostPortMethod · 0.80
setMQTTUseIDMethod · 0.80
readyMethod · 0.80
setPortMethod · 0.80
publishMethod · 0.80
execMethod · 0.80
isActiveMethod · 0.80
topicNameMethod · 0.80
propertiesMethod · 0.45
initializeMethod · 0.45

Tested by

no test coverage detected