From b6e253e5c26159c4ad671f38a048fcbe7358faa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Wed, 6 May 2015 16:39:59 +0200 Subject: [PATCH] update man page fix mock device add some more tests --- debian/guhd.1 | 13 ++++--- .../deviceplugins/mock/devicepluginmock.cpp | 17 +++++++-- plugins/deviceplugins/mock/httpdaemon.cpp | 18 ++++------ plugins/deviceplugins/mock/httpdaemon.h | 4 +-- tests/auto/devices/testdevices.cpp | 36 +++++++++++++------ 5 files changed, 56 insertions(+), 32 deletions(-) diff --git a/debian/guhd.1 b/debian/guhd.1 index 4b261b7b..29c6a2de 100644 --- a/debian/guhd.1 +++ b/debian/guhd.1 @@ -22,15 +22,20 @@ Displays version information. \fB\-n\fR, \fB\-\-no\-daemon\fR Run guhd in the foreground, not as daemon. .SH SEE ALSO -Full documentation at: +Full developer documentation at: +.br +Wiki on github: .SH "REPORTING BUGS" -Git repository on github: +Issue tracker on github: +.br +How to report bugs can: .SH AUTHOR Written by Simon Stürz and Michael Zanetti .SH COPYRIGHT -Copyright \(co 2015 guh. +Copyright \(co 2013-2015 ARGE guh. +.br License GPLv2: GNU GPL version 2 . .br This is free software: you are free to change and redistribute it. +.br There is NO WARRANTY, to the extent permitted by law. - diff --git a/plugins/deviceplugins/mock/devicepluginmock.cpp b/plugins/deviceplugins/mock/devicepluginmock.cpp index 38dbe092..2d7320c7 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.cpp +++ b/plugins/deviceplugins/mock/devicepluginmock.cpp @@ -97,8 +97,21 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::editDevice(Device *device) return DeviceManager::DeviceSetupStatusFailure; } - HttpDaemon *daemon = m_daemons.take(device); - daemon->updateDevice(device); + // delete the old daemon... + foreach (Device *d, m_daemons.keys()) { + if (d->id() == device->id()) { + delete m_daemons.take(d); + } + } + + // ...and create/start a new one + HttpDaemon *daemon = new HttpDaemon(device, this); + m_daemons.insert(device, daemon); + + if (!daemon->isListening()) { + qWarning() << "HTTP port opening failed."; + return DeviceManager::DeviceSetupStatusFailure; + } if (device->paramValue("async").toBool()) { m_asyncSetupDevices.append(device); diff --git a/plugins/deviceplugins/mock/httpdaemon.cpp b/plugins/deviceplugins/mock/httpdaemon.cpp index 5094a6b5..96618bca 100644 --- a/plugins/deviceplugins/mock/httpdaemon.cpp +++ b/plugins/deviceplugins/mock/httpdaemon.cpp @@ -39,6 +39,11 @@ HttpDaemon::HttpDaemon(Device *device, DevicePlugin *parent): listen(QHostAddress::Any, device->paramValue("httpport").toInt()); } +HttpDaemon::~HttpDaemon() +{ + close(); +} + void HttpDaemon::incomingConnection(qintptr socket) { if (disabled) @@ -60,17 +65,6 @@ void HttpDaemon::actionExecuted(const ActionTypeId &actionTypeId) m_actionList.append(qMakePair(actionTypeId, QDateTime::currentDateTime())); } -void HttpDaemon::updateDevice(Device *device) -{ - if (device->paramValue("httpport").toInt() != m_device->paramValue("httpport").toInt()) { - close(); - listen(QHostAddress::Any, device->paramValue("httpport").toInt()); - qDebug() << "Mockdevice httpport updated and listening now on" << device->paramValue("httpport").toInt(); - } - - m_device = device; -} - void HttpDaemon::readClient() { if (disabled) @@ -144,7 +138,7 @@ QString HttpDaemon::generateWebPage() "

Device Information

" "Name: %1
" "ID: %2
" - "DeviceClass ID: %3
").arg(m_device->name()).arg(m_device->id().toString()).arg(deviceClass.id().toString()); + "DeviceClass ID: %3
").arg(m_device->paramValue("name").toString()).arg(m_device->id().toString()).arg(deviceClass.id().toString()); body.append("
"); body.append("

States

"); diff --git a/plugins/deviceplugins/mock/httpdaemon.h b/plugins/deviceplugins/mock/httpdaemon.h index 078f3302..d20e0e61 100644 --- a/plugins/deviceplugins/mock/httpdaemon.h +++ b/plugins/deviceplugins/mock/httpdaemon.h @@ -36,13 +36,11 @@ class HttpDaemon : public QTcpServer Q_OBJECT public: HttpDaemon(Device *device, DevicePlugin* parent = 0); - + ~HttpDaemon(); void incomingConnection(qintptr socket) override; void actionExecuted(const ActionTypeId &actionTypeId); - void updateDevice(Device *device); - signals: void setState(const StateTypeId &stateTypeId, const QVariant &value); void triggerEvent(const EventTypeId &eventTypeId); diff --git a/tests/auto/devices/testdevices.cpp b/tests/auto/devices/testdevices.cpp index 9d18d1f1..0f9e6626 100644 --- a/tests/auto/devices/testdevices.cpp +++ b/tests/auto/devices/testdevices.cpp @@ -26,6 +26,9 @@ #include #include +#include +#include +#include class TestDevices : public GuhTestBase { @@ -532,7 +535,7 @@ void TestDevices::editDevices_data() QVariantList httpportChangeDeviceParams; QVariantMap httpportParamDifferent; httpportParamDifferent.insert("name", "httpport"); - httpportParamDifferent.insert("value", 666); + httpportParamDifferent.insert("value", 8893); // if change -> change also newPort in editDevices() httpportChangeDeviceParams.append(httpportParamDifferent); QVariantList brokenChangedDeviceParams; @@ -557,7 +560,6 @@ void TestDevices::editDevices_data() changeAllEditableDeviceParams.append(nameParam); changeAllEditableDeviceParams.append(asyncParamDifferent); changeAllEditableDeviceParams.append(httpportParamDifferent); - //changeAllEditableDeviceParams.append(brokenParamDifferent); QTest::addColumn("broken"); @@ -595,9 +597,11 @@ void TestDevices::editDevices() deviceParams.append(brokenParam); QVariantMap httpportParam; httpportParam.insert("name", "httpport"); - httpportParam.insert("value", 8890); + httpportParam.insert("value", 8892); deviceParams.append(httpportParam); params.insert("deviceParams", deviceParams); + + // add a mockdevice QVariant response = injectAndWait("Devices.AddConfiguredDevice", params); verifyDeviceError(response); @@ -605,20 +609,15 @@ void TestDevices::editDevices() QVERIFY(!deviceId.isNull()); // now EDIT the added device - response = injectAndWait("Devices.GetConfiguredDevices", QVariantMap()); - - // edit the added and verified device + response.clear(); QVariantMap editParams; editParams.insert("deviceId", deviceId); editParams.insert("deviceParams", newDeviceParams); - - response.clear(); response = injectAndWait("Devices.EditDevice", editParams); verifyDeviceError(response, deviceError); // if the edit should have been successfull if (deviceError == DeviceManager::DeviceErrorNoError) { - response = injectAndWait("Devices.GetConfiguredDevices", QVariantMap()); bool found = false; @@ -809,8 +808,6 @@ void TestDevices::editByDiscovery() } } - printJson(deviceMap); - QVERIFY2(found, "Device missing in config!"); QCOMPARE(deviceMap.value("id").toString(), deviceId.toString()); if (deviceMap.contains("setupComplete")) { @@ -827,6 +824,23 @@ void TestDevices::editByDiscovery() } } + // check if the daemons are running + QNetworkAccessManager nam; + QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); + + // check if old daemon is still running (should not) + QNetworkRequest request(QUrl(QString("http://localhost:%1").arg(55555))); + QNetworkReply *reply = nam.get(request); + spy.wait(); + QVERIFY2(reply->error(), "The old daemon is still running"); + reply->deleteLater(); + + // check if the daemon is realy running on the new port + request = QNetworkRequest(QUrl(QString("http://localhost:%1").arg(55556))); + reply = nam.get(request); + spy.wait(); + QVERIFY2(reply->error() == QNetworkReply::NoError, "The new daemon is not running"); + reply->deleteLater(); params.clear(); params.insert("deviceId", deviceId.toString());