Add test trigger for auto device reconfiguration

pull/146/head
Simon Stürz 2019-04-03 21:55:16 +02:00 committed by Michael Zanetti
parent beb00aa0f1
commit 36778e8eda
2 changed files with 17 additions and 9 deletions

View File

@ -110,6 +110,7 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
connect(daemon, &HttpDaemon::setState, this, &DevicePluginMock::setState);
// Keep this queued or it might happen that the HttpDaemon is deleted before it is able to reply to the caller
connect(daemon, &HttpDaemon::disappear, this, &DevicePluginMock::onDisappear, Qt::QueuedConnection);
connect(daemon, &HttpDaemon::reconfigureAutodevice, this, &DevicePluginMock::onReconfigureAutoDevice, Qt::QueuedConnection);
if (async) {
m_asyncSetupDevices.append(device);

View File

@ -52,6 +52,8 @@ private slots:
void storedDevices();
void reconfigureAutodevice();
void discoverDevices_data();
void discoverDevices();
@ -91,7 +93,6 @@ private slots:
void reconfigureByDiscovery();
void reconfigureByDiscoveryAndPair();
void reconfigureAutodevice();
void removeDevice_data();
void removeDevice();
@ -1278,17 +1279,23 @@ void TestDevices::reconfigureByDiscoveryAndPair()
void TestDevices::reconfigureAutodevice()
{
// Get the current autodevice
qCDebug(dcTests()) << "Reconfigure auto device";
QVariant response = injectAndWait("Devices.GetConfiguredDevices");
QVariantList devices = response.toMap().value("params").toMap().value("devices").toList();
QList<Device *> devices = NymeaCore::instance()->deviceManager()->findConfiguredDevices(mockDeviceAutoClassId);
QVERIFY2(devices.count() > 0, "There needs to be at least one auto-created Mock Device for this test");
Device *device = devices.first();
// Setup connection to mock client
QNetworkAccessManager *nam = new QNetworkAccessManager(this);
QSignalSpy spy(nam, SIGNAL(finished(QNetworkReply*)));
// trigger reconfigure signal in mock device
QNetworkReply *reply = nam->get(QNetworkRequest(QUrl(QString("http://localhost:%1/reconfigureautodevice").arg(device->paramValue(httpportParamTypeId).toInt()))));
spy.wait();
QCOMPARE(spy.count(), 1);
reply->deleteLater();
QVariantMap autoDevice;
foreach (const QVariant &deviceVariant, devices) {
QVariantMap deviceMap = deviceVariant.toMap();
qDebug() << deviceMap;
}
}