mirror of https://github.com/nymea/nymea.git
Finish test implementation and verify auto device reconfiguration does work.
parent
36778e8eda
commit
695914f497
|
|
@ -386,18 +386,24 @@ void DevicePluginMock::onDisappear()
|
|||
|
||||
void DevicePluginMock::onReconfigureAutoDevice()
|
||||
{
|
||||
HttpDaemon *daemon = qobject_cast<HttpDaemon*>(sender());
|
||||
if (!daemon) {
|
||||
HttpDaemon *daemon = qobject_cast<HttpDaemon *>(sender());
|
||||
if (!daemon)
|
||||
return;
|
||||
}
|
||||
|
||||
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.setTitle(device->name() + " (reconfigured)");
|
||||
deviceDescriptor.setDescription("This auto device was reconfigured");
|
||||
deviceDescriptor.setDeviceId(device->id());
|
||||
deviceDescriptor.setParams(device->params());
|
||||
deviceDescriptor.setParams(params);
|
||||
|
||||
emit autoDevicesAppeared(mockDeviceAutoDeviceClassId, { deviceDescriptor });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,8 +52,6 @@ private slots:
|
|||
|
||||
void storedDevices();
|
||||
|
||||
void reconfigureAutodevice();
|
||||
|
||||
void discoverDevices_data();
|
||||
void discoverDevices();
|
||||
|
||||
|
|
@ -93,6 +91,7 @@ private slots:
|
|||
void reconfigureByDiscovery();
|
||||
|
||||
void reconfigureByDiscoveryAndPair();
|
||||
void reconfigureAutodevice();
|
||||
|
||||
void removeDevice_data();
|
||||
void removeDevice();
|
||||
|
|
@ -1281,22 +1280,28 @@ void TestDevices::reconfigureAutodevice()
|
|||
{
|
||||
qCDebug(dcTests()) << "Reconfigure auto device";
|
||||
|
||||
// Get the autodevice
|
||||
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
|
||||
// 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);
|
||||
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()))));
|
||||
QNetworkReply *reply = nam->get(QNetworkRequest(QUrl(QString("http://localhost:%1/reconfigureautodevice").arg(currentPort))));
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue