add language notification
add configuration tests
This commit is contained in:
parent
d77e122aca
commit
0877e61c2e
@ -316,6 +316,7 @@ void DeviceManager::setLocale(const QLocale &locale)
|
||||
}
|
||||
}
|
||||
|
||||
emit languageUpdated();
|
||||
}
|
||||
|
||||
/*! Returns all the \l{DevicePlugin}{DevicePlugins} loaded in the system. */
|
||||
|
||||
@ -145,6 +145,7 @@ public:
|
||||
|
||||
signals:
|
||||
void loaded();
|
||||
void languageUpdated();
|
||||
void eventTriggered(const Event &event);
|
||||
void deviceStateChanged(Device *device, const QUuid &stateTypeId, const QVariant &value);
|
||||
void deviceRemoved(const DeviceId &deviceId);
|
||||
|
||||
@ -138,12 +138,18 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent):
|
||||
params.insert("port", JsonTypes::basicTypeToString(JsonTypes::Uint));
|
||||
setParams("WebSocketServerConfigurationChanged", params);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
setDescription("LanguageChanged", "Emitted whenever the language of the server changed. The Plugins, Vendors and DeviceClasses have to be reloaded to get the translated data.");
|
||||
params.insert("language", JsonTypes::basicTypeToString(JsonTypes::String));
|
||||
setParams("LanguageChanged", params);
|
||||
|
||||
connect(GuhCore::instance()->configuration(), &GuhConfiguration::serverNameChanged, this, &ConfigurationHandler::onBasicConfigurationChanged);
|
||||
connect(GuhCore::instance()->configuration(), &GuhConfiguration::timeZoneChanged, this, &ConfigurationHandler::onBasicConfigurationChanged);
|
||||
connect(GuhCore::instance()->configuration(), &GuhConfiguration::localeChanged, this, &ConfigurationHandler::onBasicConfigurationChanged);
|
||||
connect(GuhCore::instance()->configuration(), &GuhConfiguration::tcpServerConfigurationChanged, this, &ConfigurationHandler::onTcpServerConfigurationChanged);
|
||||
connect(GuhCore::instance()->configuration(), &GuhConfiguration::webServerConfigurationChanged, this, &ConfigurationHandler::onWebServerConfigurationChanged);
|
||||
connect(GuhCore::instance()->configuration(), &GuhConfiguration::webSocketServerConfigurationChanged, this, &ConfigurationHandler::onWebSocketServerConfigurationChanged);
|
||||
connect(GuhCore::instance()->deviceManager(), &DeviceManager::languageUpdated, this, &ConfigurationHandler::onLanguageChanged);
|
||||
}
|
||||
|
||||
QString ConfigurationHandler::name() const
|
||||
@ -315,4 +321,12 @@ void ConfigurationHandler::onWebSocketServerConfigurationChanged()
|
||||
emit WebSocketServerConfigurationChanged(params);
|
||||
}
|
||||
|
||||
void ConfigurationHandler::onLanguageChanged()
|
||||
{
|
||||
QVariantMap params;
|
||||
qCDebug(dcJsonRpc()) << "Notification: language configuration changed";
|
||||
params.insert("language", GuhCore::instance()->configuration()->locale().name());
|
||||
emit LanguageChanged(params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -50,12 +50,14 @@ signals:
|
||||
void TcpServerConfigurationChanged(const QVariantMap ¶ms);
|
||||
void WebServerConfigurationChanged(const QVariantMap ¶ms);
|
||||
void WebSocketServerConfigurationChanged(const QVariantMap ¶ms);
|
||||
void LanguageChanged(const QVariantMap ¶ms);
|
||||
|
||||
private slots:
|
||||
void onBasicConfigurationChanged();
|
||||
void onTcpServerConfigurationChanged();
|
||||
void onWebServerConfigurationChanged();
|
||||
void onWebSocketServerConfigurationChanged();
|
||||
void onLanguageChanged();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -18,5 +18,5 @@ SUBDIRS = versioning \
|
||||
logging \
|
||||
restlogging \
|
||||
coap \
|
||||
#timemanager \
|
||||
|
||||
timemanager \
|
||||
configurations \
|
||||
|
||||
7
tests/auto/configurations/configurations.pro
Normal file
7
tests/auto/configurations/configurations.pro
Normal file
@ -0,0 +1,7 @@
|
||||
TARGET = testconfigurations
|
||||
|
||||
include(../../../guh.pri)
|
||||
include(../autotests.pri)
|
||||
|
||||
SOURCES += testconfigurations.cpp
|
||||
|
||||
77
tests/auto/configurations/testconfigurations.cpp
Normal file
77
tests/auto/configurations/testconfigurations.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2015 Simon Stürz <simon.stuerz@guh.guru> *
|
||||
* Copyright (C) 2014 Michael Zanetti <michael_zanetti@gmx.net> *
|
||||
* *
|
||||
* This file is part of guh. *
|
||||
* *
|
||||
* Guh is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, version 2 of the License. *
|
||||
* *
|
||||
* Guh is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "guhtestbase.h"
|
||||
#include "guhcore.h"
|
||||
#include "devicemanager.h"
|
||||
#include "mocktcpserver.h"
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <QCoreApplication>
|
||||
#include <QTcpSocket>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QCoreApplication>
|
||||
|
||||
using namespace guhserver;
|
||||
|
||||
class TestConfigurations: public GuhTestBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void getConfigurations();
|
||||
|
||||
void testTimeZones();
|
||||
|
||||
|
||||
};
|
||||
|
||||
void TestConfigurations::getConfigurations()
|
||||
{
|
||||
QVariant response = injectAndWait("Configuration.GetConfigurations");
|
||||
QVariantMap configurations = response.toMap().value("params").toMap();
|
||||
qDebug() << qUtf8Printable(QJsonDocument::fromVariant(configurations).toJson());
|
||||
|
||||
QVERIFY(configurations.contains("basicConfiguration"));
|
||||
QVERIFY(!configurations.value("basicConfiguration").toMap().value("serverUuid").toUuid().isNull());
|
||||
|
||||
QVERIFY(configurations.contains("sslConfiguration"));
|
||||
QVERIFY(configurations.contains("tcpServerConfiguration"));
|
||||
QVERIFY(configurations.contains("webServerConfiguration"));
|
||||
QVERIFY(configurations.contains("webSocketServerConfiguration"));
|
||||
}
|
||||
|
||||
void TestConfigurations::testTimeZones()
|
||||
{
|
||||
QVariantMap configurations = injectAndWait("Configuration.GetConfigurations").toMap().value("params").toMap();
|
||||
QString currentTimeZone = configurations.value("basicConfiguration").toMap().value("timeZone").toString();
|
||||
QString currentTime = configurations.value("basicConfiguration").toMap().value("serverTime").toString();
|
||||
qDebug() << currentTimeZone << QDateTime::fromTime_t(currentTime.toInt());
|
||||
QVariantList timeZones = injectAndWait("Configuration.GetTimeZones").toMap().value("params").toMap().value("timeZones").toList();
|
||||
QVERIFY(timeZones.count() > 0);
|
||||
QVERIFY(timeZones.contains("America/Toronto"));
|
||||
|
||||
}
|
||||
|
||||
#include "testconfigurations.moc"
|
||||
QTEST_MAIN(TestConfigurations)
|
||||
Reference in New Issue
Block a user