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
|
||||
Run guhd in the foreground, not as daemon.
|
||||
.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"
|
||||
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
|
||||
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 <http://gnu.org/licenses/gpl.html>.
|
||||
.br
|
||||
This is free software: you are free to change and redistribute it.
|
||||
.br
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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>(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()
|
||||
"<h2>Device Information</h2>"
|
||||
"Name: %1<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("<h2>States</h2>");
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -26,6 +26,9 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QSignalSpy>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
|
||||
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<bool>("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());
|
||||
|
||||
Reference in New Issue
Block a user