update man page
fix mock device add some more tests
This commit is contained in:
parent
5af2067308
commit
b6e253e5c2
13
debian/guhd.1
vendored
13
debian/guhd.1
vendored
@ -22,15 +22,20 @@ Displays version information.
|
|||||||
\fB\-n\fR, \fB\-\-no\-daemon\fR
|
\fB\-n\fR, \fB\-\-no\-daemon\fR
|
||||||
Run guhd in the foreground, not as daemon.
|
Run guhd in the foreground, not as daemon.
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
Full documentation at: <http://dev.guh.guru>
|
Full developer documentation at: <http://dev.guh.guru>
|
||||||
|
.br
|
||||||
|
Wiki on github: <https://github.com/guh/guh/wiki>
|
||||||
.SH "REPORTING BUGS"
|
.SH "REPORTING BUGS"
|
||||||
Git repository on github: <https://github.com/guh/guh/issues>
|
Issue tracker on github: <https://github.com/guh/guh/issues>
|
||||||
|
.br
|
||||||
|
How to report bugs can: <https://github.com/guh/guh/wiki/Reporting-bugs>
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Written by Simon Stürz and Michael Zanetti
|
Written by Simon Stürz and Michael Zanetti
|
||||||
.SH COPYRIGHT
|
.SH COPYRIGHT
|
||||||
Copyright \(co 2015 guh.
|
Copyright \(co 2013-2015 ARGE guh.
|
||||||
|
.br
|
||||||
License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>.
|
License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>.
|
||||||
.br
|
.br
|
||||||
This is free software: you are free to change and redistribute it.
|
This is free software: you are free to change and redistribute it.
|
||||||
|
.br
|
||||||
There is NO WARRANTY, to the extent permitted by law.
|
There is NO WARRANTY, to the extent permitted by law.
|
||||||
|
|
||||||
|
|||||||
@ -97,8 +97,21 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::editDevice(Device *device)
|
|||||||
return DeviceManager::DeviceSetupStatusFailure;
|
return DeviceManager::DeviceSetupStatusFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpDaemon *daemon = m_daemons.take(device);
|
// delete the old daemon...
|
||||||
daemon->updateDevice(device);
|
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()) {
|
if (device->paramValue("async").toBool()) {
|
||||||
m_asyncSetupDevices.append(device);
|
m_asyncSetupDevices.append(device);
|
||||||
|
|||||||
@ -39,6 +39,11 @@ HttpDaemon::HttpDaemon(Device *device, DevicePlugin *parent):
|
|||||||
listen(QHostAddress::Any, device->paramValue("httpport").toInt());
|
listen(QHostAddress::Any, device->paramValue("httpport").toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HttpDaemon::~HttpDaemon()
|
||||||
|
{
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
void HttpDaemon::incomingConnection(qintptr socket)
|
void HttpDaemon::incomingConnection(qintptr socket)
|
||||||
{
|
{
|
||||||
if (disabled)
|
if (disabled)
|
||||||
@ -60,17 +65,6 @@ void HttpDaemon::actionExecuted(const ActionTypeId &actionTypeId)
|
|||||||
m_actionList.append(qMakePair<ActionTypeId, QDateTime>(actionTypeId, QDateTime::currentDateTime()));
|
m_actionList.append(qMakePair<ActionTypeId, QDateTime>(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()
|
void HttpDaemon::readClient()
|
||||||
{
|
{
|
||||||
if (disabled)
|
if (disabled)
|
||||||
@ -144,7 +138,7 @@ QString HttpDaemon::generateWebPage()
|
|||||||
"<h2>Device Information</h2>"
|
"<h2>Device Information</h2>"
|
||||||
"Name: %1<br>"
|
"Name: %1<br>"
|
||||||
"ID: %2<br>"
|
"ID: %2<br>"
|
||||||
"DeviceClass ID: %3<br>").arg(m_device->name()).arg(m_device->id().toString()).arg(deviceClass.id().toString());
|
"DeviceClass ID: %3<br>").arg(m_device->paramValue("name").toString()).arg(m_device->id().toString()).arg(deviceClass.id().toString());
|
||||||
|
|
||||||
body.append("<hr>");
|
body.append("<hr>");
|
||||||
body.append("<h2>States</h2>");
|
body.append("<h2>States</h2>");
|
||||||
|
|||||||
@ -36,13 +36,11 @@ class HttpDaemon : public QTcpServer
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
HttpDaemon(Device *device, DevicePlugin* parent = 0);
|
HttpDaemon(Device *device, DevicePlugin* parent = 0);
|
||||||
|
~HttpDaemon();
|
||||||
void incomingConnection(qintptr socket) override;
|
void incomingConnection(qintptr socket) override;
|
||||||
|
|
||||||
void actionExecuted(const ActionTypeId &actionTypeId);
|
void actionExecuted(const ActionTypeId &actionTypeId);
|
||||||
|
|
||||||
void updateDevice(Device *device);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void setState(const StateTypeId &stateTypeId, const QVariant &value);
|
void setState(const StateTypeId &stateTypeId, const QVariant &value);
|
||||||
void triggerEvent(const EventTypeId &eventTypeId);
|
void triggerEvent(const EventTypeId &eventTypeId);
|
||||||
|
|||||||
@ -26,6 +26,9 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSignalSpy>
|
#include <QSignalSpy>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
class TestDevices : public GuhTestBase
|
class TestDevices : public GuhTestBase
|
||||||
{
|
{
|
||||||
@ -532,7 +535,7 @@ void TestDevices::editDevices_data()
|
|||||||
QVariantList httpportChangeDeviceParams;
|
QVariantList httpportChangeDeviceParams;
|
||||||
QVariantMap httpportParamDifferent;
|
QVariantMap httpportParamDifferent;
|
||||||
httpportParamDifferent.insert("name", "httpport");
|
httpportParamDifferent.insert("name", "httpport");
|
||||||
httpportParamDifferent.insert("value", 666);
|
httpportParamDifferent.insert("value", 8893); // if change -> change also newPort in editDevices()
|
||||||
httpportChangeDeviceParams.append(httpportParamDifferent);
|
httpportChangeDeviceParams.append(httpportParamDifferent);
|
||||||
|
|
||||||
QVariantList brokenChangedDeviceParams;
|
QVariantList brokenChangedDeviceParams;
|
||||||
@ -557,7 +560,6 @@ void TestDevices::editDevices_data()
|
|||||||
changeAllEditableDeviceParams.append(nameParam);
|
changeAllEditableDeviceParams.append(nameParam);
|
||||||
changeAllEditableDeviceParams.append(asyncParamDifferent);
|
changeAllEditableDeviceParams.append(asyncParamDifferent);
|
||||||
changeAllEditableDeviceParams.append(httpportParamDifferent);
|
changeAllEditableDeviceParams.append(httpportParamDifferent);
|
||||||
//changeAllEditableDeviceParams.append(brokenParamDifferent);
|
|
||||||
|
|
||||||
|
|
||||||
QTest::addColumn<bool>("broken");
|
QTest::addColumn<bool>("broken");
|
||||||
@ -595,9 +597,11 @@ void TestDevices::editDevices()
|
|||||||
deviceParams.append(brokenParam);
|
deviceParams.append(brokenParam);
|
||||||
QVariantMap httpportParam;
|
QVariantMap httpportParam;
|
||||||
httpportParam.insert("name", "httpport");
|
httpportParam.insert("name", "httpport");
|
||||||
httpportParam.insert("value", 8890);
|
httpportParam.insert("value", 8892);
|
||||||
deviceParams.append(httpportParam);
|
deviceParams.append(httpportParam);
|
||||||
params.insert("deviceParams", deviceParams);
|
params.insert("deviceParams", deviceParams);
|
||||||
|
|
||||||
|
// add a mockdevice
|
||||||
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
|
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||||
verifyDeviceError(response);
|
verifyDeviceError(response);
|
||||||
|
|
||||||
@ -605,20 +609,15 @@ void TestDevices::editDevices()
|
|||||||
QVERIFY(!deviceId.isNull());
|
QVERIFY(!deviceId.isNull());
|
||||||
|
|
||||||
// now EDIT the added device
|
// now EDIT the added device
|
||||||
response = injectAndWait("Devices.GetConfiguredDevices", QVariantMap());
|
response.clear();
|
||||||
|
|
||||||
// edit the added and verified device
|
|
||||||
QVariantMap editParams;
|
QVariantMap editParams;
|
||||||
editParams.insert("deviceId", deviceId);
|
editParams.insert("deviceId", deviceId);
|
||||||
editParams.insert("deviceParams", newDeviceParams);
|
editParams.insert("deviceParams", newDeviceParams);
|
||||||
|
|
||||||
response.clear();
|
|
||||||
response = injectAndWait("Devices.EditDevice", editParams);
|
response = injectAndWait("Devices.EditDevice", editParams);
|
||||||
verifyDeviceError(response, deviceError);
|
verifyDeviceError(response, deviceError);
|
||||||
|
|
||||||
// if the edit should have been successfull
|
// if the edit should have been successfull
|
||||||
if (deviceError == DeviceManager::DeviceErrorNoError) {
|
if (deviceError == DeviceManager::DeviceErrorNoError) {
|
||||||
|
|
||||||
response = injectAndWait("Devices.GetConfiguredDevices", QVariantMap());
|
response = injectAndWait("Devices.GetConfiguredDevices", QVariantMap());
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
@ -809,8 +808,6 @@ void TestDevices::editByDiscovery()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printJson(deviceMap);
|
|
||||||
|
|
||||||
QVERIFY2(found, "Device missing in config!");
|
QVERIFY2(found, "Device missing in config!");
|
||||||
QCOMPARE(deviceMap.value("id").toString(), deviceId.toString());
|
QCOMPARE(deviceMap.value("id").toString(), deviceId.toString());
|
||||||
if (deviceMap.contains("setupComplete")) {
|
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.clear();
|
||||||
params.insert("deviceId", deviceId.toString());
|
params.insert("deviceId", deviceId.toString());
|
||||||
|
|||||||
Reference in New Issue
Block a user