Finish test implementation and verify auto device reconfiguration does work.
This commit is contained in:
parent
36778e8eda
commit
695914f497
@ -386,18 +386,24 @@ void DevicePluginMock::onDisappear()
|
|||||||
|
|
||||||
void DevicePluginMock::onReconfigureAutoDevice()
|
void DevicePluginMock::onReconfigureAutoDevice()
|
||||||
{
|
{
|
||||||
HttpDaemon *daemon = qobject_cast<HttpDaemon*>(sender());
|
HttpDaemon *daemon = qobject_cast<HttpDaemon *>(sender());
|
||||||
if (!daemon) {
|
if (!daemon)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
Device *device = m_daemons.key(daemon);
|
Device *device = m_daemons.key(daemon);
|
||||||
qCDebug(dcMockDevice) << "Reconfigure auto device for" << device;
|
qCDebug(dcMockDevice()) << "Reconfigure auto device for" << device << device->params();
|
||||||
|
|
||||||
|
int currentPort = device->params().paramValue(mockDeviceAutoDeviceHttpportParamTypeId).toInt();
|
||||||
|
|
||||||
|
// Note: the reconfigure makes the http server listen on port + 1
|
||||||
|
ParamList params;
|
||||||
|
params.append(Param(mockDeviceAutoDeviceHttpportParamTypeId, currentPort + 1));
|
||||||
|
|
||||||
DeviceDescriptor deviceDescriptor;
|
DeviceDescriptor deviceDescriptor;
|
||||||
deviceDescriptor.setTitle(device->name() + " (reconfigured)");
|
deviceDescriptor.setTitle(device->name() + " (reconfigured)");
|
||||||
deviceDescriptor.setDescription("This auto device was reconfigured");
|
deviceDescriptor.setDescription("This auto device was reconfigured");
|
||||||
deviceDescriptor.setDeviceId(device->id());
|
deviceDescriptor.setDeviceId(device->id());
|
||||||
deviceDescriptor.setParams(device->params());
|
deviceDescriptor.setParams(params);
|
||||||
|
|
||||||
emit autoDevicesAppeared(mockDeviceAutoDeviceClassId, { deviceDescriptor });
|
emit autoDevicesAppeared(mockDeviceAutoDeviceClassId, { deviceDescriptor });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,8 +52,6 @@ private slots:
|
|||||||
|
|
||||||
void storedDevices();
|
void storedDevices();
|
||||||
|
|
||||||
void reconfigureAutodevice();
|
|
||||||
|
|
||||||
void discoverDevices_data();
|
void discoverDevices_data();
|
||||||
void discoverDevices();
|
void discoverDevices();
|
||||||
|
|
||||||
@ -93,6 +91,7 @@ private slots:
|
|||||||
void reconfigureByDiscovery();
|
void reconfigureByDiscovery();
|
||||||
|
|
||||||
void reconfigureByDiscoveryAndPair();
|
void reconfigureByDiscoveryAndPair();
|
||||||
|
void reconfigureAutodevice();
|
||||||
|
|
||||||
void removeDevice_data();
|
void removeDevice_data();
|
||||||
void removeDevice();
|
void removeDevice();
|
||||||
@ -1281,22 +1280,28 @@ void TestDevices::reconfigureAutodevice()
|
|||||||
{
|
{
|
||||||
qCDebug(dcTests()) << "Reconfigure auto device";
|
qCDebug(dcTests()) << "Reconfigure auto device";
|
||||||
|
|
||||||
|
// Get the autodevice
|
||||||
QList<Device *> devices = NymeaCore::instance()->deviceManager()->findConfiguredDevices(mockDeviceAutoClassId);
|
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");
|
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
|
// Get current auto device infos
|
||||||
|
Device *currentDevice = devices.first();
|
||||||
|
DeviceId deviceId = currentDevice->id();
|
||||||
|
int currentPort = currentDevice->paramValue(httpportParamTypeId).toInt();
|
||||||
|
|
||||||
|
// Trigger reconfigure signal in mock device
|
||||||
QNetworkAccessManager *nam = new QNetworkAccessManager(this);
|
QNetworkAccessManager *nam = new QNetworkAccessManager(this);
|
||||||
QSignalSpy spy(nam, SIGNAL(finished(QNetworkReply*)));
|
QSignalSpy spy(nam, SIGNAL(finished(QNetworkReply*)));
|
||||||
|
QNetworkReply *reply = nam->get(QNetworkRequest(QUrl(QString("http://localhost:%1/reconfigureautodevice").arg(currentPort))));
|
||||||
// trigger reconfigure signal in mock device
|
|
||||||
QNetworkReply *reply = nam->get(QNetworkRequest(QUrl(QString("http://localhost:%1/reconfigureautodevice").arg(device->paramValue(httpportParamTypeId).toInt()))));
|
|
||||||
spy.wait();
|
spy.wait();
|
||||||
QCOMPARE(spy.count(), 1);
|
QCOMPARE(spy.count(), 1);
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
|
Device *device = NymeaCore::instance()->deviceManager()->findConfiguredDevice(deviceId);
|
||||||
|
QVERIFY(device);
|
||||||
|
int newPort = device->paramValue(httpportParamTypeId).toInt();
|
||||||
|
// Note: reconfigure autodevice increases the http port by 1
|
||||||
|
QVERIFY(newPort == currentPort + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user