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

Method testIntegerMessage

tests/import_export/MQTT/MQTTTest.cpp:143–260  ·  view source on GitHub ↗

############################################################################## ################# test handling of data received by messages ############### ##############################################################################

Source from the content-addressed store, hash-verified

141// ################# test handling of data received by messages ###############
142// ##############################################################################
143void 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();

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