diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index b8f57661..5310f2ed 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -181,6 +181,7 @@ #include "plugin/devicepairinginfo.h" #include "plugin/deviceplugin.h" +#include "typeutils.h" #include "guhsettings.h" #include @@ -309,23 +310,24 @@ DevicePlugin *DeviceManager::plugin(const PluginId &id) const DeviceManager::DeviceError DeviceManager::setPluginConfig(const PluginId &pluginId, const ParamList &pluginConfig) { DevicePlugin *plugin = m_devicePlugins.value(pluginId); - if (!plugin) + if (!plugin) { + qCWarning(dcDeviceManager()) << "Could not set plugin configuration. There is no plugin with id" << pluginId.toString(); return DeviceErrorPluginNotFound; + } ParamList params = pluginConfig; - DeviceError verify = verifyParams(plugin->configurationDescription(), params); if (verify != DeviceErrorNoError) return verify; - DeviceError result = plugin->setConfiguration(pluginConfig); + DeviceError result = plugin->setConfiguration(params); if (result != DeviceErrorNoError) return result; GuhSettings settings(GuhSettings::SettingsRolePlugins); settings.beginGroup("PluginConfig"); settings.beginGroup(plugin->pluginId().toString()); - foreach (const Param ¶m, pluginConfig) { + foreach (const Param ¶m, params) { settings.setValue(param.paramTypeId().toString(), param.value()); } settings.endGroup(); @@ -616,7 +618,7 @@ DeviceManager::DeviceError DeviceManager::pairDevice(const PairingTransactionId DeviceManager::DeviceError DeviceManager::confirmPairing(const PairingTransactionId &pairingTransactionId, const QString &secret) { if (m_pairingsJustAdd.contains(pairingTransactionId)) { - qCWarning(dcDeviceManager) << "this SetupMethod is not implemented yet"; + qCWarning(dcDeviceManager) << "This SetupMethod is not implemented yet"; m_pairingsJustAdd.remove(pairingTransactionId); return DeviceErrorSetupFailed; } @@ -829,7 +831,7 @@ DeviceManager::DeviceError DeviceManager::verifyParams(const QList pa // This paramType has a default value... lets fill in that one. if (!paramType.defaultValue().isNull() && !found) { found = true; - params.append(Param(paramType.name(), paramType.defaultValue())); + params.append(Param(paramType.id(), paramType.defaultValue())); } if (!found) { @@ -848,6 +850,7 @@ DeviceManager::DeviceError DeviceManager::verifyParam(const QList par return verifyParam(paramType, param); } } + qCWarning(dcDeviceManager) << "Invalid parameter" << param.paramTypeId().toString() << "in parameter list"; return DeviceErrorInvalidParameter; } @@ -1001,13 +1004,19 @@ void DeviceManager::loadPlugins() if (!verifyPluginMetadata(loader.metaData().value("MetaData").toObject())) continue; - pluginIface->initPlugin(loader.metaData().value("MetaData").toObject(), this); + pluginIface->setMetaData(loader.metaData().value("MetaData").toObject()); + + pluginIface->setLocale(m_locale); + qApp->installTranslator(pluginIface->translator()); + + pluginIface->initPlugin(this); + qCDebug(dcDeviceManager) << "**** Loaded plugin" << pluginIface->pluginName(); foreach (const Vendor &vendor, pluginIface->supportedVendors()) { qCDebug(dcDeviceManager) << "* Loaded vendor:" << vendor.name(); - if (m_supportedVendors.contains(vendor.id())) { + if (m_supportedVendors.contains(vendor.id())) continue; - } + m_supportedVendors.insert(vendor.id(), vendor); } @@ -1021,25 +1030,20 @@ void DeviceManager::loadPlugins() qCDebug(dcDeviceManager) << "* Loaded device class:" << deviceClass.name(); } - if (!pluginIface->setLocale(m_locale)) - qCWarning(dcDeviceManager()) << "Could not load translation" << m_locale.name() << "for plugin" << pluginIface->pluginName(); - - qApp->installTranslator(pluginIface->translator()); - GuhSettings settings(GuhSettings::SettingsRolePlugins); settings.beginGroup("PluginConfig"); ParamList params; if (settings.childGroups().contains(pluginIface->pluginId().toString())) { settings.beginGroup(pluginIface->pluginId().toString()); - foreach (const QString ¶mName, settings.allKeys()) { - Param param(paramName, settings.value(paramName)); + foreach (const QString ¶mTypeIdString, settings.allKeys()) { + Param param(ParamTypeId(paramTypeIdString), settings.value(paramTypeIdString)); params.append(param); } settings.endGroup(); - } else if (pluginIface->configurationDescription().count() > 0){ + } else if (!pluginIface->configurationDescription().isEmpty()){ // plugin requires config but none stored. Init with defaults foreach (const ParamType ¶mType, pluginIface->configurationDescription()) { - Param param(paramType.name(), paramType.defaultValue()); + Param param(paramType.id(), paramType.defaultValue()); params.append(param); } } @@ -1077,10 +1081,8 @@ void DeviceManager::loadConfiguredDevices() ParamList params; settings.beginGroup("Params"); - foreach (QString paramNameString, settings.allKeys()) { - Param param(paramNameString); - param.setValue(settings.value(paramNameString)); - params.append(param); + foreach (const QString ¶mTypeIdString, settings.allKeys()) { + params.append(Param(ParamTypeId(paramTypeIdString), settings.value(paramTypeIdString))); } device->setParams(params); settings.endGroup(); diff --git a/libguh/network/avahi/qtavahiservicebrowser_p.cpp b/libguh/network/avahi/qtavahiservicebrowser_p.cpp index 18122db2..3bade547 100644 --- a/libguh/network/avahi/qtavahiservicebrowser_p.cpp +++ b/libguh/network/avahi/qtavahiservicebrowser_p.cpp @@ -134,8 +134,8 @@ void QtAvahiServiceBrowserPrivate::callbackServiceResolver(AvahiServiceResolver Q_UNUSED(type); Q_UNUSED(txt); - QtAvahiServiceBrowser *serviceBrowser = static_cast(userdata); - if (!serviceBrowser) + QPointer serviceBrowser = static_cast(userdata); + if (serviceBrowser.isNull()) return; switch (event) { diff --git a/libguh/plugin/device.cpp b/libguh/plugin/device.cpp index a208130a..cceeff61 100644 --- a/libguh/plugin/device.cpp +++ b/libguh/plugin/device.cpp @@ -131,7 +131,7 @@ void Device::setParamValue(const ParamTypeId ¶mTypeId, const QVariant &value if (param.paramTypeId() == paramTypeId) { param.setValue(value); } - params.append(param); + params << param; } m_params = params; } diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp index 5b942a3d..64fed053 100644 --- a/libguh/plugin/deviceplugin.cpp +++ b/libguh/plugin/deviceplugin.cpp @@ -321,7 +321,7 @@ QList DevicePlugin::supportedDevices() const eventType.setRuleRelevant(st.value("eventRuleRelevant").toBool()); eventType.setName(QString("%1 changed").arg(stateType.name())); - ParamType paramType(ParamTypeId(stateType.id().toString()),stateType.id().toString(), stateType.type()); + ParamType paramType(ParamTypeId(stateType.id().toString()),stateType.name(), stateType.type()); eventType.setParamTypes(QList() << paramType); eventType.setIndex(stateType.index()); eventTypes.append(eventType); @@ -452,7 +452,7 @@ bool DevicePlugin::setLocale(const QLocale &locale) { // check if there are local translations if (m_translator->load(locale, m_metaData.value("id").toString(), "-", QDir(QCoreApplication::applicationDirPath() + "../../translations/").absolutePath(), ".qm")) { - qCDebug(dcDeviceManager()) << "* Load translation" << locale.name() << "for" << pluginName() << "from" << QDir(QCoreApplication::applicationDirPath() + "../../translations/").absolutePath(); + qCDebug(dcDeviceManager()) << "* Load translation" << locale.name() << "for" << pluginName() << "from" << QDir(QCoreApplication::applicationDirPath() + "../../translations/").absolutePath() + "/" + m_metaData.value("id").toString() + "-" + locale.name() + ".qm"; return true; } @@ -569,19 +569,18 @@ QList DevicePlugin::configurationDescription() const /*! This will be called when the DeviceManager initializes the plugin and set up the things behind the scenes. When implementing a new plugin, use \l{DevicePlugin::init()} instead in order to do initialisation work. */ -void DevicePlugin::initPlugin(const QJsonObject &metaData, DeviceManager *deviceManager) +void DevicePlugin::initPlugin(DeviceManager *deviceManager) { - m_metaData = metaData; + m_deviceManager = deviceManager; // parse plugin configuration params if (m_metaData.contains("paramTypes")) { QPair > paramVerification = parseParamTypes(m_metaData.value("paramTypes").toArray()); - if (paramVerification.first) { - m_configurationDescription = paramVerification.second; - } + if (paramVerification.first) + m_configurationDescription << paramVerification.second; + } - m_deviceManager = deviceManager; init(); } @@ -592,7 +591,7 @@ QPair > DevicePlugin::parseParamTypes(const QJsonArray &a QJsonObject pt = paramTypesJson.toObject(); // Check fields - QStringList missingFields = verifyFields(QStringList() << "name" << "index" << "type", pt); + QStringList missingFields = verifyFields(QStringList() << "id" << "name" << "index" << "type", pt); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << pluginName() << "Error parsing ParamType: missing fields" << missingFields.join(", ") << endl << pt; return QPair >(false, QList()); @@ -639,9 +638,9 @@ QPair > DevicePlugin::parseParamTypes(const QJsonArray &a } // set readOnly if given (default false) - if (pt.contains("readOnly")) { + if (pt.contains("readOnly")) paramType.setReadOnly(pt.value("readOnly").toBool()); - } + paramType.setAllowedValues(allowedValues); paramType.setLimits(pt.value("minValue").toVariant(), pt.value("maxValue").toVariant()); paramTypes.append(paramType); @@ -669,23 +668,18 @@ ParamList DevicePlugin::configuration() const */ QVariant DevicePlugin::configValue(const ParamTypeId ¶mTypeId) const { - foreach (const Param ¶m, m_config) { - if (param.paramTypeId() == paramTypeId) { - return param.value(); - } - } - return QVariant(); + return m_config.paramValue(paramTypeId); } /*! Will be called by the DeviceManager to set a plugin's \a configuration. */ DeviceManager::DeviceError DevicePlugin::setConfiguration(const ParamList &configuration) { foreach (const Param ¶m, configuration) { - qCDebug(dcDeviceManager) << "* set plugin configuration" << param; + qCDebug(dcDeviceManager) << "* Set plugin configuration" << param; DeviceManager::DeviceError result = setConfigValue(param.paramTypeId(), param.value()); - if (result != DeviceManager::DeviceErrorNoError) { + if (result != DeviceManager::DeviceErrorNoError) return result; - } + } return DeviceManager::DeviceErrorNoError; } @@ -711,11 +705,14 @@ DeviceManager::DeviceError DevicePlugin::setConfigValue(const ParamTypeId ¶m } if (m_config.hasParam(paramTypeId)) { - m_config.setParamValue(paramTypeId, value); + if (!m_config.setParamValue(paramTypeId, value)) { + qCWarning(dcDeviceManager()) << "Could not set param value" << value << "for param with id" << paramTypeId.toString(); + return DeviceManager::DeviceErrorInvalidParameter; + } } else { - Param newParam(paramTypeId, value); - m_config.append(newParam); + m_config.append(Param(paramTypeId, value)); } + emit configValueChanged(paramTypeId, value); return DeviceManager::DeviceErrorNoError; } @@ -834,6 +831,11 @@ QNetworkReply *DevicePlugin::networkManagerPut(const QNetworkRequest &request, c return nullptr; } +void DevicePlugin::setMetaData(const QJsonObject &metaData) +{ + m_metaData = metaData; +} + /*! Starts a SSDP search for a certain \a searchTarget (ST). Certain UPnP devices need a special ST (i.e. "udap:rootservice" for LG Smart Tv's), otherwise they will not respond on the SSDP search. Each HTTP request to this device needs sometimes diff --git a/libguh/plugin/deviceplugin.h b/libguh/plugin/deviceplugin.h index 5dc2f99e..3dbb5038 100644 --- a/libguh/plugin/deviceplugin.h +++ b/libguh/plugin/deviceplugin.h @@ -129,7 +129,8 @@ protected: QNetworkReply *networkManagerPut(const QNetworkRequest &request, const QByteArray &data); private: - void initPlugin(const QJsonObject &metaData, DeviceManager *deviceManager); + void setMetaData(const QJsonObject &metaData); + void initPlugin(DeviceManager *deviceManager); QPair > parseParamTypes(const QJsonArray &array) const; diff --git a/libguh/types/param.cpp b/libguh/types/param.cpp index 1ecee872..9b0cd75d 100644 --- a/libguh/types/param.cpp +++ b/libguh/types/param.cpp @@ -95,29 +95,37 @@ QDebug operator<<(QDebug dbg, const ParamList ¶ms) /*! Returns true if this ParamList contains a Param with the given \a paramTypeId. */ bool ParamList::hasParam(const ParamTypeId ¶mTypeId) const { - return m_ids.contains(paramTypeId); + foreach (const Param ¶m, *this) { + if (param.paramTypeId() == paramTypeId) + return true; + } + + return false; } -/*! Returns the value of the Param with the given \a paramName. */ +/*! Returns the value of the Param with the given \a paramTypeId. */ QVariant ParamList::paramValue(const ParamTypeId ¶mTypeId) const { foreach (const Param ¶m, *this) { - if (param.paramTypeId() == paramTypeId) { + if (param.paramTypeId() == paramTypeId) return param.value(); - } + } + return QVariant(); } -/*! Sets the value of a Param with the given \a paramName to the given \a value. */ -void ParamList::setParamValue(const ParamTypeId ¶mTypeId, const QVariant &value) +/*! Sets the value of a Param with the given \a paramTypeId to the given \a value. */ +bool ParamList::setParamValue(const ParamTypeId ¶mTypeId, const QVariant &value) { for (int i = 0; i < count(); i++) { - if (this->operator [](i).paramTypeId() == paramTypeId) { + if (this->operator [](i).paramTypeId() == paramTypeId) { this->operator [](i).setValue(value); - return; + return true; } } + + return false; } /*! Appends the given \a param to a ParamList. */ diff --git a/libguh/types/param.h b/libguh/types/param.h index c2851ff2..518843d6 100644 --- a/libguh/types/param.h +++ b/libguh/types/param.h @@ -53,7 +53,7 @@ class LIBGUH_EXPORT ParamList: public QList public: bool hasParam(const ParamTypeId ¶mTypeId) const; QVariant paramValue(const ParamTypeId ¶mTypeId) const; - void setParamValue(const ParamTypeId ¶mTypeId, const QVariant &value); + bool setParamValue(const ParamTypeId ¶mTypeId, const QVariant &value); ParamList operator<<(const Param ¶m); private: diff --git a/libguh/types/ruleactionparam.cpp b/libguh/types/ruleactionparam.cpp index e097787b..d27f512a 100644 --- a/libguh/types/ruleactionparam.cpp +++ b/libguh/types/ruleactionparam.cpp @@ -41,30 +41,35 @@ RuleActionParam::RuleActionParam(const Param ¶m) : m_paramTypeId(param.paramTypeId()), m_value(param.value()), m_eventTypeId(EventTypeId()), - m_eventParamName(QString()) + m_eventParamTypeId(ParamTypeId()) { } /*! Constructs a \l{RuleActionParam} with the given \a name, \a value, \a eventTypeId and \a eventParamName. * \sa Param, Event, */ -RuleActionParam::RuleActionParam(const ParamTypeId ¶mTypeId, const QVariant &value, const EventTypeId &eventTypeId, const QString &eventParamName) : +RuleActionParam::RuleActionParam(const ParamTypeId ¶mTypeId, const QVariant &value, const EventTypeId &eventTypeId, const ParamTypeId &eventParamTypeId) : m_paramTypeId(paramTypeId), m_value(value), m_eventTypeId(eventTypeId), - m_eventParamName(eventParamName) + m_eventParamTypeId(eventParamTypeId) { } +ParamTypeId RuleActionParam::paramTypeId() const +{ + return m_paramTypeId; +} + /*! Returns the name of the eventParam for this RuleActionParam. */ -QString RuleActionParam::eventParamName() const +ParamTypeId RuleActionParam::eventParamTypeId() const { - return m_eventParamName; + return m_eventParamTypeId; } /*! Sets the \a eventParamName of this RuleActionParam. */ -void RuleActionParam::setEventParamName(const QString &eventParamName) +void RuleActionParam::setEventParamTypeId(const ParamTypeId &eventParamTypeId) { - m_eventParamName = eventParamName; + m_eventParamTypeId = eventParamTypeId; } /*! Returns the value of this RuleActionParam. */ @@ -82,8 +87,8 @@ void RuleActionParam::setValue(const QVariant &value) /*! Returns true if the name and value or the name, eventTypeId and eventParamName of this RuleActionParam are set.*/ bool RuleActionParam::isValid() const { - bool validValue = (!m_paramTypeId.isNull() && m_value.isValid() && m_eventTypeId.isNull() && m_eventParamName.isEmpty()); - bool validEvent = (!m_paramTypeId.isNull() && m_eventTypeId.isNull() && !m_eventParamName.isEmpty() && !m_value.isValid()); + bool validValue = (!m_paramTypeId.isNull() && m_value.isValid() && m_eventTypeId.isNull() && m_eventParamTypeId.isNull()); + bool validEvent = (!m_paramTypeId.isNull() && !m_value.isValid() && !m_eventTypeId.isNull() && !m_eventParamTypeId.isNull()); return validValue ^ validEvent; } @@ -104,7 +109,7 @@ QDebug operator<<(QDebug dbg, const RuleActionParam &ruleActionParam) { dbg.nospace() << "RuleActionParam(ParamTypeId: " << ruleActionParam.paramTypeId() << ", Value:" << ruleActionParam.value(); if (ruleActionParam.eventTypeId() != EventTypeId()) { - dbg.nospace() << ", EventTypeId:" << ruleActionParam.eventTypeId().toString() << ", EventParamName:" << ruleActionParam.eventParamName() << ")"; + dbg.nospace() << ", EventTypeId:" << ruleActionParam.eventTypeId().toString() << ", EventParamTypeId:" << ruleActionParam.eventParamTypeId().toString() << ")"; } else { dbg.nospace() << ")"; } @@ -136,18 +141,21 @@ QVariant RuleActionParamList::paramValue(const ParamTypeId &ruleActionParamTypeI return param.value(); } } + return QVariant(); } /*! Sets the value of the \l{RuleActionParam} with the given \a ruleActionParamTypeId to the given \a value. */ -void RuleActionParamList::setParamValue(const ParamTypeId &ruleActionParamTypeId, const QVariant &value) +bool RuleActionParamList::setParamValue(const ParamTypeId &ruleActionParamTypeId, const QVariant &value) { for (int i = 0; i < count(); i++) { if (this->operator [](i).paramTypeId() == ruleActionParamTypeId) { this->operator [](i).setValue(value); - return; + return true; } } + + return false; } /*! Appends the given \a ruleActionParam to a RuleActionParamList. */ diff --git a/libguh/types/ruleactionparam.h b/libguh/types/ruleactionparam.h index 7ee63b72..512fa22c 100644 --- a/libguh/types/ruleactionparam.h +++ b/libguh/types/ruleactionparam.h @@ -34,12 +34,12 @@ class LIBGUH_EXPORT RuleActionParam { public: RuleActionParam(const Param ¶m = Param()); - RuleActionParam(const ParamTypeId ¶mTypeId, const QVariant &value = QVariant(), const EventTypeId &eventTypeId = EventTypeId(), const QString &eventParamName = QString()); + RuleActionParam(const ParamTypeId ¶mTypeId, const QVariant &value = QVariant(), const EventTypeId &eventTypeId = EventTypeId(), const ParamTypeId &eventParamName = ParamTypeId()); ParamTypeId paramTypeId() const; - QString eventParamName() const; - void setEventParamName(const QString &eventParamName); + ParamTypeId eventParamTypeId() const; + void setEventParamTypeId(const ParamTypeId &eventParamTypeId); QVariant value() const; void setValue(const QVariant &value); @@ -53,7 +53,7 @@ private: ParamTypeId m_paramTypeId; QVariant m_value; EventTypeId m_eventTypeId; - QString m_eventParamName; + ParamTypeId m_eventParamTypeId; }; Q_DECLARE_METATYPE(RuleActionParam) @@ -64,7 +64,7 @@ class LIBGUH_EXPORT RuleActionParamList: public QList public: bool hasParam(const ParamTypeId &ruleActionParamTypeId) const; QVariant paramValue(const ParamTypeId &ruleActionParamName) const; - void setParamValue(const ParamTypeId &ruleActionParamTypeId, const QVariant &value); + bool setParamValue(const ParamTypeId &ruleActionParamTypeId, const QVariant &value); RuleActionParamList operator<<(const RuleActionParam &ruleActionParam); private: diff --git a/plugins/deviceplugins/mock/devicepluginmock.cpp b/plugins/deviceplugins/mock/devicepluginmock.cpp index c6e984b6..a2e98079 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.cpp +++ b/plugins/deviceplugins/mock/devicepluginmock.cpp @@ -52,6 +52,7 @@ DevicePluginMock::DevicePluginMock() { + } DevicePluginMock::~DevicePluginMock() @@ -405,3 +406,8 @@ void DevicePluginMock::onChildDeviceDiscovered(const DeviceId &parentId) emit autoDevicesAppeared(mockChildDeviceClassId, QList() << mockDescriptor); } + +void DevicePluginMock::onPluginConfigChanged() +{ + +} diff --git a/plugins/deviceplugins/mock/devicepluginmock.h b/plugins/deviceplugins/mock/devicepluginmock.h index a0015427..5b158951 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.h +++ b/plugins/deviceplugins/mock/devicepluginmock.h @@ -67,6 +67,7 @@ private slots: void onPushButtonPairingFinished(); void onDisplayPinPairingFinished(); void onChildDeviceDiscovered(const DeviceId &parentId); + void onPluginConfigChanged(); private: QHash m_daemons; diff --git a/plugins/deviceplugins/mock/devicepluginmock.json b/plugins/deviceplugins/mock/devicepluginmock.json index f51d7601..3e50cd46 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.json +++ b/plugins/deviceplugins/mock/devicepluginmock.json @@ -301,6 +301,8 @@ "pairingInfo": "Wait 3 second before you continue, the push button will be pressed automatically.", "discoveryParamTypes": [ { + "id": "d222adb4-2f9c-4c3f-8655-76400d0fb6ce", + "idName": "resultCount", "name": "resultCount", "type": "int", "index": 0, @@ -390,6 +392,8 @@ "pairingInfo": "Please enter the secret which normaly will be displayed on the device. For the mockdevice the pin is 243681.", "discoveryParamTypes": [ { + "id": "d222adb4-2f9c-4c3f-8655-76400d0fb6ce", + "idName": "resultCount", "name": "resultCount", "type": "int", "index": 0, diff --git a/plugins/deviceplugins/mock/translations/de_DE.ts b/plugins/deviceplugins/mock/translations/de_DE.ts index 6aa54139..edba5a8c 100644 --- a/plugins/deviceplugins/mock/translations/de_DE.ts +++ b/plugins/deviceplugins/mock/translations/de_DE.ts @@ -4,7 +4,7 @@ DevicePluginMock - + Display pin!! The pin is 243681 Pin anzeigen!! Der pin lautet 243581 @@ -15,49 +15,49 @@ guh The name of the vendor (2062d64d-3232-433c-88bc-0d33c0ba2ba6) - + guh Mock Device The name of the deviceClass - + Mock Gerät Mock Action 3 (async) The name of the ActionType fbae06d3-7666-483e-a39e-ec50fe89054e of deviceClass Mock Device - + Mock Aktion 3 (async) Mock Action 4 (broken) The name of the ActionType df3cf33d-26d5-4577-9132-9823bd33fad0 of deviceClass Mock Device - + Mock Aktion 4 (kaputt) Mock Action 5 (async, broken) The name of the ActionType bfe89a1d-3497-4121-8318-e77c37537219 of deviceClass Mock Device - + Mock Aktion 5 (async, kaputt) Mock Device (Auto created) The name of the deviceClass - + Mock Gerät (Auto erstellt) Mock Device (Push Button) The name of the deviceClass - + Mock Gerät (Drückknopf) Wait 3 second before you continue, the push button will be pressed automatically. The pairing info of deviceClass Mock Device (Push Button) - + Warte 3 Sekunden bevor du fortfährst, the Knopf wird automatisch gerückt. @@ -66,7 +66,7 @@ The name of the stateType (20dc7c22-c50e-42db-837c-2bbced939f8e) of deviceClass Mock Device (Push Button) ---------- The name of the stateType (20dc7c22-c50e-42db-837c-2bbced939f8e) of deviceClass Mock Device (Display Pin) - + Farbe @@ -75,7 +75,7 @@ The name of the stateType (20dc7c22-c50e-42db-837c-2bbced939f8e) of deviceClass The name of the stateType (72981c04-267a-4ba0-a59e-9921d2f3af9c) of deviceClass Mock Device (Push Button) ---------- The name of the stateType (72981c04-267a-4ba0-a59e-9921d2f3af9c) of deviceClass Mock Device (Display Pin) - + Prozent @@ -84,7 +84,7 @@ The name of the stateType (72981c04-267a-4ba0-a59e-9921d2f3af9c) of deviceClass The name of the stateType (05f63f9c-f61e-4dcf-ad55-3f13fde2765b) of deviceClass Mock Device (Push Button) ---------- The name of the stateType (05f63f9c-f61e-4dcf-ad55-3f13fde2765b) of deviceClass Mock Device (Display Pin) - + Erlaubte Werte @@ -93,7 +93,7 @@ The name of the stateType (05f63f9c-f61e-4dcf-ad55-3f13fde2765b) of deviceClass The name of the stateType (53cd7c55-49b7-441b-b970-9048f20f0e2c) of deviceClass Mock Device (Push Button) ---------- The name of the stateType (53cd7c55-49b7-441b-b970-9048f20f0e2c) of deviceClass Mock Device (Display Pin) - + Double Wert @@ -108,7 +108,7 @@ The name of the stateType (e680f7a4-b39e-46da-be41-fa3170fe3768) of deviceClass The name of the stateType (d24ede5f-4064-4898-bb84-cfb533b1fbc0) of deviceClass Mock Device (Parent) ---------- The name of the stateType (d24ede5f-4064-4898-bb84-cfb533b1fbc0) of deviceClass Mock Device (Child) - + Bool Wert @@ -117,37 +117,37 @@ The name of the stateType (d24ede5f-4064-4898-bb84-cfb533b1fbc0) of deviceClass The name of the ActionType 54646e7c-bc54-4895-81a2-590d72d120f9 of deviceClass Mock Device (Push Button) ---------- The name of the ActionType 54646e7c-bc54-4895-81a2-590d72d120f9 of deviceClass Mock Device (Display Pin) - + Timeout Aktion Mock Device (Display Pin) The name of the deviceClass - + Mock Gerät (Pin anzeigen) Please enter the secret which normaly will be displayed on the device. For the mockdevice the pin is 243681. The pairing info of deviceClass Mock Device (Display Pin) - + Bitte geben sie den Pincode ein der normalerweise auf dem Gerät angezeit werden würde. In diesem fall lautet der Pincode 243681. Mock Device (Parent) The name of the deviceClass - + Mock Gerät (Elternteil) Mock Device (Child) The name of the deviceClass - + Mock Gerät (Kind) Mock Device (InputTypes) The name of the deviceClass - + Mock Gerät (Eingabemethoden) diff --git a/plugins/deviceplugins/mock/translations/en_US.ts b/plugins/deviceplugins/mock/translations/en_US.ts index f8ba4a0c..7e50916c 100644 --- a/plugins/deviceplugins/mock/translations/en_US.ts +++ b/plugins/deviceplugins/mock/translations/en_US.ts @@ -4,7 +4,7 @@ DevicePluginMock - + Display pin!! The pin is 243681 diff --git a/server/jsonrpc/devicehandler.cpp b/server/jsonrpc/devicehandler.cpp index a3dc5cf1..2723220a 100644 --- a/server/jsonrpc/devicehandler.cpp +++ b/server/jsonrpc/devicehandler.cpp @@ -353,14 +353,9 @@ JsonReply* DeviceHandler::GetPlugins(const QVariantMap ¶ms) const JsonReply *DeviceHandler::GetPluginConfiguration(const QVariantMap ¶ms) const { - DevicePlugin *plugin = 0; - foreach (DevicePlugin *p, GuhCore::instance()->deviceManager()->plugins()) { - if (p->pluginId() == PluginId(params.value("pluginId").toString())) { - plugin = p; - } - } - QVariantMap returns; + + DevicePlugin *plugin = GuhCore::instance()->deviceManager()->plugin(PluginId(params.value("pluginId").toString())); if (!plugin) { returns.insert("deviceError", JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorPluginNotFound)); return createReply(returns); diff --git a/server/jsonrpc/jsontypes.cpp b/server/jsonrpc/jsontypes.cpp index dc1120a8..1560d1b0 100644 --- a/server/jsonrpc/jsontypes.cpp +++ b/server/jsonrpc/jsontypes.cpp @@ -136,6 +136,7 @@ void JsonTypes::init() s_configurationError = enumToStrings(GuhConfiguration::staticMetaObject, "ConfigurationError"); // ParamType + s_paramType.insert("id", basicTypeToString(Uuid)); s_paramType.insert("name", basicTypeToString(String)); s_paramType.insert("type", basicTypeRef()); s_paramType.insert("index", basicTypeToString(Int)); @@ -148,7 +149,7 @@ void JsonTypes::init() s_paramType.insert("o:readOnly", basicTypeToString(Bool)); // Param - s_param.insert("name", basicTypeToString(String)); + s_param.insert("paramTypeId", basicTypeToString(Uuid)); s_param.insert("value", basicTypeRef()); // RuleAction @@ -157,13 +158,13 @@ void JsonTypes::init() s_ruleAction.insert("o:ruleActionParams", QVariantList() << ruleActionParamRef()); // RuleActionParam - s_ruleActionParam.insert("name", basicTypeToString(String)); + s_ruleActionParam.insert("paramTypeId", basicTypeToString(Uuid)); s_ruleActionParam.insert("o:value", basicTypeRef()); s_ruleActionParam.insert("o:eventTypeId", basicTypeToString(Uuid)); - s_ruleActionParam.insert("o:eventParamName", basicTypeToString(String)); + s_ruleActionParam.insert("o:eventParamTypeId", basicTypeToString(Uuid)); // ParamDescriptor - s_paramDescriptor.insert("name", basicTypeToString(String)); + s_paramDescriptor.insert("paramTypeId", basicTypeToString(Uuid)); s_paramDescriptor.insert("value", basicTypeRef()); s_paramDescriptor.insert("operator", valueOperatorRef()); @@ -228,7 +229,7 @@ void JsonTypes::init() // Pugin s_plugin.insert("id", basicTypeToString(Uuid)); s_plugin.insert("name", basicTypeToString(String)); - s_plugin.insert("params", QVariantList() << paramRef()); + s_plugin.insert("paramTypes", QVariantList() << paramTypeRef()); // Vendor s_vendor.insert("id", basicTypeToString(Uuid)); @@ -490,11 +491,11 @@ QVariantMap JsonTypes::packRuleAction(const RuleAction &ruleAction) QVariantMap JsonTypes::packRuleActionParam(const RuleActionParam &ruleActionParam) { QVariantMap variantMap; - variantMap.insert("name", ruleActionParam.name()); + variantMap.insert("paramTypeId", ruleActionParam.paramTypeId().toString()); // if this ruleaction param has a valid EventTypeId, there is no value if (ruleActionParam.eventTypeId() != EventTypeId()) { variantMap.insert("eventTypeId", ruleActionParam.eventTypeId()); - variantMap.insert("eventParamName", ruleActionParam.eventParamName()); + variantMap.insert("eventParamTypeId", ruleActionParam.eventParamTypeId().toString()); } else { variantMap.insert("value", ruleActionParam.value()); } @@ -587,7 +588,7 @@ QVariantMap JsonTypes::packParam(const Param ¶m) QVariantMap JsonTypes::packParamDescriptor(const ParamDescriptor ¶mDescriptor) { QVariantMap variantMap; - variantMap.insert("paramTypeId", paramDescriptor.paramTypeId()); + variantMap.insert("paramTypeId", paramDescriptor.paramTypeId().toString()); variantMap.insert("value", paramDescriptor.value()); variantMap.insert("operator", s_valueOperator.at(paramDescriptor.operatorType())); return variantMap; @@ -597,7 +598,7 @@ QVariantMap JsonTypes::packParamDescriptor(const ParamDescriptor ¶mDescripto QVariantMap JsonTypes::packParamType(const ParamType ¶mType) { QVariantMap variantMap; - variantMap.insert("id", paramType.id()); + variantMap.insert("id", paramType.id().toString()); variantMap.insert("name", paramType.name()); variantMap.insert("type", basicTypeToString(paramType.type())); variantMap.insert("index", paramType.index()); @@ -641,9 +642,9 @@ QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass) { QVariantMap variant; variant.insert("name", deviceClass.name()); - variant.insert("id", deviceClass.id()); - variant.insert("vendorId", deviceClass.vendorId()); - variant.insert("pluginId", deviceClass.pluginId()); + variant.insert("id", deviceClass.id().toString()); + variant.insert("vendorId", deviceClass.vendorId().toString()); + variant.insert("pluginId", deviceClass.pluginId().toString()); variant.insert("deviceIcon", s_deviceIcon.at(deviceClass.deviceIcon())); QVariantList basicTags; @@ -702,8 +703,7 @@ QVariantMap JsonTypes::packPlugin(DevicePlugin *plugin) foreach (const ParamType ¶m, plugin->configurationDescription()) { params.append(packParamType(param)); } - pluginMap.insert("params", params); - + pluginMap.insert("paramTypes", params); return pluginMap; } @@ -1133,9 +1133,9 @@ Param JsonTypes::unpackParam(const QVariantMap ¶mMap) if (paramMap.keys().count() == 0) { return Param(); } - QString name = paramMap.value("name").toString(); + ParamTypeId paramTypeId = paramMap.value("paramTypeId").toString(); QVariant value = paramMap.value("value"); - return Param(name, value); + return Param(paramTypeId, value); } /*! Returns a \l{ParamList} created from the given \a paramList. */ @@ -1218,11 +1218,11 @@ RuleActionParam JsonTypes::unpackRuleActionParam(const QVariantMap &ruleActionPa if (ruleActionParamMap.keys().count() == 0) return RuleActionParam(); - QString name = ruleActionParamMap.value("name").toString(); + ParamTypeId paramTypeId = ParamTypeId(ruleActionParamMap.value("paramTypeId").toString()); QVariant value = ruleActionParamMap.value("value"); EventTypeId eventTypeId = EventTypeId(ruleActionParamMap.value("eventTypeId").toString()); - QString eventParamName = ruleActionParamMap.value("eventParamName").toString(); - return RuleActionParam(name, value, eventTypeId, eventParamName); + ParamTypeId eventParamTypeId = ParamTypeId(ruleActionParamMap.value("eventParamTypeId").toString()); + return RuleActionParam(paramTypeId, value, eventTypeId, eventParamTypeId); } /*! Returns a \l{RuleActionParamList} created from the given \a ruleActionParamList. */ @@ -1238,7 +1238,7 @@ RuleActionParamList JsonTypes::unpackRuleActionParams(const QVariantList &ruleAc /*! Returns a \l{ParamDescriptor} created from the given \a paramMap. */ ParamDescriptor JsonTypes::unpackParamDescriptor(const QVariantMap ¶mMap) { - ParamDescriptor param(paramMap.value("name").toString(), paramMap.value("value")); + ParamDescriptor param(ParamTypeId(paramMap.value("paramTypeId").toString()), paramMap.value("value")); QString operatorString = paramMap.value("operator").toString(); QMetaObject metaObject = Types::staticMetaObject; diff --git a/server/logging/logengine.cpp b/server/logging/logengine.cpp index ef068943..d0945d14 100644 --- a/server/logging/logengine.cpp +++ b/server/logging/logengine.cpp @@ -231,13 +231,17 @@ void LogEngine::logEvent(const Event &event) Logging::LoggingSource sourceType; if (event.isStateChangeEvent()) { sourceType = Logging::LoggingSourceStates; - valueList << event.param("value").value().toString(); + // There should only be one param + if (!event.params().isEmpty()) + valueList << event.params().first().value().toString(); + } else { sourceType = Logging::LoggingSourceEvents; foreach (const Param ¶m, event.params()) { valueList << param.value().toString(); } } + LogEntry entry(sourceType); entry.setTypeId(event.eventTypeId()); entry.setDeviceId(event.deviceId()); diff --git a/server/ruleengine.cpp b/server/ruleengine.cpp index 2d440807..0800cf13 100644 --- a/server/ruleengine.cpp +++ b/server/ruleengine.cpp @@ -232,7 +232,7 @@ RuleEngine::RuleEngine(QObject *parent) : foreach (QString groupName, settings.childGroups()) { if (groupName.startsWith("ParamDescriptor-")) { settings.beginGroup(groupName); - ParamDescriptor paramDescriptor(groupName.remove(QRegExp("^ParamDescriptor-")), settings.value("value")); + ParamDescriptor paramDescriptor(ParamTypeId(groupName.remove(QRegExp("^ParamDescriptor-"))), settings.value("value")); paramDescriptor.setOperatorType((Types::ValueOperator)settings.value("operator").toInt()); params.append(paramDescriptor); settings.endGroup(); @@ -260,13 +260,13 @@ RuleEngine::RuleEngine(QObject *parent) : DeviceId(settings.value("deviceId").toString())); RuleActionParamList params; - foreach (QString paramNameString, settings.childGroups()) { - if (paramNameString.startsWith("RuleActionParam-")) { - settings.beginGroup(paramNameString); - RuleActionParam param(paramNameString.remove(QRegExp("^RuleActionParam-")), + foreach (QString paramTypeIdString, settings.childGroups()) { + if (paramTypeIdString.startsWith("RuleActionParam-")) { + settings.beginGroup(paramTypeIdString); + RuleActionParam param(ParamTypeId(paramTypeIdString.remove(QRegExp("^RuleActionParam-"))), settings.value("value",QVariant()), EventTypeId(settings.value("eventTypeId", EventTypeId()).toString()), - settings.value("eventParamName", QString()).toString()); + settings.value("eventParamTypeId", ParamTypeId()).toString()); params.append(param); settings.endGroup(); } @@ -289,10 +289,11 @@ RuleEngine::RuleEngine(QObject *parent) : DeviceId(settings.value("deviceId").toString())); RuleActionParamList params; - foreach (QString paramNameString, settings.childGroups()) { - if (paramNameString.startsWith("RuleActionParam-")) { - settings.beginGroup(paramNameString); - RuleActionParam param(paramNameString.remove(QRegExp("^RuleActionParam-")), settings.value("value")); + foreach (QString paramTypeIdString, settings.childGroups()) { + if (paramTypeIdString.startsWith("RuleActionParam-")) { + settings.beginGroup(paramTypeIdString); + RuleActionParam param(ParamTypeId(paramTypeIdString.remove(QRegExp("^RuleActionParam-"))), + settings.value("value")); params.append(param); settings.endGroup(); } @@ -548,10 +549,10 @@ RuleEngine::RuleError RuleEngine::addRule(const Rule &rule, bool fromEdit) } // check if the param type of the event and the action match - QVariant::Type eventParamType = getEventParamType(ruleActionParam.eventTypeId(), ruleActionParam.eventParamName()); - QVariant::Type actionParamType = getActionParamType(action.actionTypeId(), ruleActionParam.name()); + QVariant::Type eventParamType = getEventParamType(ruleActionParam.eventTypeId(), ruleActionParam.eventParamTypeId()); + QVariant::Type actionParamType = getActionParamType(action.actionTypeId(), ruleActionParam.paramTypeId()); if (eventParamType != actionParamType) { - qCWarning(dcRuleEngine) << "Cannot create rule. RuleActionParam" << ruleActionParam.name() << " and given event param " << ruleActionParam.eventParamName() << "have not the same type:"; + qCWarning(dcRuleEngine) << "Cannot create rule. RuleActionParam" << ruleActionParam.paramTypeId().toString() << " and given event param " << ruleActionParam.eventParamTypeId().toString() << "have not the same type:"; qCWarning(dcRuleEngine) << " -> actionParamType:" << actionParamType; qCWarning(dcRuleEngine) << " -> eventParamType:" << eventParamType; return RuleErrorTypesNotMatching; @@ -949,6 +950,7 @@ bool RuleEngine::containsEvent(const Rule &rule, const Event &event) return true; } } + return false; } @@ -973,38 +975,41 @@ bool RuleEngine::checkEventDescriptors(const QList eventDescrip return true; } } + return false; } -QVariant::Type RuleEngine::getActionParamType(const ActionTypeId &actionTypeId, const QString ¶mName) +QVariant::Type RuleEngine::getActionParamType(const ActionTypeId &actionTypeId, const ParamTypeId ¶mTypeId) { foreach (const DeviceClass &deviceClass, GuhCore::instance()->deviceManager()->supportedDevices()) { foreach (const ActionType &actionType, deviceClass.actionTypes()) { if (actionType.id() == actionTypeId) { foreach (const ParamType ¶mType, actionType.paramTypes()) { - if (paramType.name() == paramName) { + if (paramType.id() == paramTypeId) { return paramType.type(); } } } } } + return QVariant::Invalid; } -QVariant::Type RuleEngine::getEventParamType(const EventTypeId &eventTypeId, const QString ¶mName) +QVariant::Type RuleEngine::getEventParamType(const EventTypeId &eventTypeId, const ParamTypeId ¶mTypeId) { foreach (const DeviceClass &deviceClass, GuhCore::instance()->deviceManager()->supportedDevices()) { foreach (const EventType &eventType, deviceClass.eventTypes()) { if (eventType.id() == eventTypeId) { foreach (const ParamType ¶mType, eventType.paramTypes()) { - if (paramType.name() == paramName) { + if (paramType.id() == paramTypeId) { return paramType.type(); } } } } } + return QVariant::Invalid; } @@ -1103,7 +1108,7 @@ void RuleEngine::saveRule(const Rule &rule) settings.setValue("eventTypeId", eventDescriptor.eventTypeId().toString()); foreach (const ParamDescriptor ¶mDescriptor, eventDescriptor.paramDescriptors()) { - settings.beginGroup("ParamDescriptor-" + paramDescriptor.name()); + settings.beginGroup("ParamDescriptor-" + paramDescriptor.paramTypeId().toString()); settings.setValue("value", paramDescriptor.value()); settings.setValue("operator", paramDescriptor.operatorType()); settings.endGroup(); @@ -1123,11 +1128,11 @@ void RuleEngine::saveRule(const Rule &rule) settings.setValue("deviceId", action.deviceId().toString()); settings.setValue("actionTypeId", action.actionTypeId().toString()); foreach (const RuleActionParam ¶m, action.ruleActionParams()) { - settings.beginGroup("RuleActionParam-" + param.name()); + settings.beginGroup("RuleActionParam-" + param.paramTypeId().toString()); settings.setValue("value", param.value()); if (param.eventTypeId() != EventTypeId()) { settings.setValue("eventTypeId", param.eventTypeId().toString()); - settings.setValue("eventParamName", param.eventParamName()); + settings.setValue("eventParamTypeId", param.eventParamTypeId()); } settings.endGroup(); } @@ -1144,7 +1149,7 @@ void RuleEngine::saveRule(const Rule &rule) settings.setValue("deviceId", action.deviceId().toString()); settings.setValue("actionTypeId", action.actionTypeId().toString()); foreach (const RuleActionParam ¶m, action.ruleActionParams()) { - settings.beginGroup("RuleActionParam-" + param.name()); + settings.beginGroup("RuleActionParam-" + param.paramTypeId().toString()); settings.setValue("value", param.value()); settings.endGroup(); } diff --git a/server/ruleengine.h b/server/ruleengine.h index c6d8dbd1..5a78a2a0 100644 --- a/server/ruleengine.h +++ b/server/ruleengine.h @@ -102,8 +102,8 @@ private: bool containsState(const StateEvaluator &stateEvaluator, const Event &stateChangeEvent); bool checkEventDescriptors(const QList eventDescriptors, const EventTypeId &eventTypeId); - QVariant::Type getActionParamType(const ActionTypeId &actionTypeId, const QString ¶mName); - QVariant::Type getEventParamType(const EventTypeId &eventTypeId, const QString ¶mName); + QVariant::Type getActionParamType(const ActionTypeId &actionTypeId, const ParamTypeId ¶mTypeId); + QVariant::Type getEventParamType(const EventTypeId &eventTypeId, const ParamTypeId ¶mTypeId); void appendRule(const Rule &rule); void saveRule(const Rule &rule); diff --git a/tests/auto/actions/testactions.cpp b/tests/auto/actions/testactions.cpp index 6ce18427..45c3a358 100644 --- a/tests/auto/actions/testactions.cpp +++ b/tests/auto/actions/testactions.cpp @@ -56,11 +56,11 @@ void TestActions::executeAction_data() QVariantList params; QVariantMap param1; - param1.insert("name", "mockActionParam1"); + param1.insert("paramTypeId", mockActionParam1ParamTypeId); param1.insert("value", 5); params.append(param1); QVariantMap param2; - param2.insert("name", "mockActionParam2"); + param2.insert("paramTypeId", mockActionParam2ParamTypeId); param2.insert("value", true); params.append(param2); diff --git a/tests/auto/devices/testdevices.cpp b/tests/auto/devices/testdevices.cpp index 635a6e55..872f18b7 100644 --- a/tests/auto/devices/testdevices.cpp +++ b/tests/auto/devices/testdevices.cpp @@ -162,7 +162,7 @@ void TestDevices::setPluginConfig() QVariantList configuration; QVariantMap configParam; - configParam.insert("name", "configParamInt"); + configParam.insert("paramTypeId", configParamIntParamTypeId); configParam.insert("value", value); configuration.append(configParam); params.insert("configuration", configuration); @@ -174,8 +174,8 @@ void TestDevices::setPluginConfig() params.insert("pluginId", pluginId); response = injectAndWait("Devices.GetPluginConfiguration", params); verifyDeviceError(response); - qDebug() << "222" << response.toMap().value("params").toMap().value("configuration").toList().first(); - QVERIFY2(response.toMap().value("params").toMap().value("configuration").toList().first().toMap().value("name") == "configParamInt", "Value not set correctly"); + qDebug() << value << response.toMap().value("params").toMap().value("configuration").toList().first(); + QVERIFY2(ParamTypeId(response.toMap().value("params").toMap().value("configuration").toList().first().toMap().value("paramTypeId").toString()) == configParamIntParamTypeId, "Value not set correctly"); QVERIFY2(response.toMap().value("params").toMap().value("configuration").toList().first().toMap().value("value") == value, "Value not set correctly"); } } @@ -221,15 +221,6 @@ void TestDevices::getSupportedDevices() QVariantList supportedDevices = result.toMap().value("params").toMap().value("deviceClasses").toList(); // Make sure there are the right amount of supported device classes with the name Mock Device QCOMPARE(supportedDevices.count() >= resultCount, true); - if (resultCount > 0) { - bool found = false; - foreach (const QVariant &listEntry, supportedDevices) { - if (listEntry.toMap().value("name").toString().startsWith("Mock Device")) { - found = true; - } - } - QVERIFY2(found, "Mock Device not found"); - } } void TestDevices::addConfiguredDevice_data() @@ -239,13 +230,13 @@ void TestDevices::addConfiguredDevice_data() QTest::addColumn("deviceError"); QVariantMap httpportParam; - httpportParam.insert("name", "httpport"); + httpportParam.insert("paramTypeId", httpportParamTypeId.toString()); httpportParam.insert("value", m_mockDevice1Port - 1); QVariantMap asyncParam; - asyncParam.insert("name", "async"); + asyncParam.insert("paramTypeId", asyncParamTypeId); asyncParam.insert("value", true); QVariantMap brokenParam; - brokenParam.insert("name", "broken"); + brokenParam.insert("paramTypeId", brokenParamTypeId); brokenParam.insert("value", true); QVariantList deviceParams; @@ -264,7 +255,7 @@ void TestDevices::addConfiguredDevice_data() QTest::newRow("User, JustAdd, missing params") << mockDeviceClassId << invalidDeviceParams << DeviceManager::DeviceErrorMissingParameter; QVariantMap fakeparam; - fakeparam.insert("name", "tropptth"); + fakeparam.insert("paramTypeId", ParamTypeId::createParamTypeId()); invalidDeviceParams.append(fakeparam); QTest::newRow("User, JustAdd, invalid param") << mockDeviceClassId << invalidDeviceParams << DeviceManager::DeviceErrorInvalidParameter; @@ -314,15 +305,15 @@ void TestDevices::storedDevices() params.insert("name", "Test stored Device"); QVariantList deviceParams; QVariantMap asyncParam; - asyncParam.insert("name", "async"); + asyncParam.insert("paramTypeId", asyncParamTypeId); asyncParam.insert("value", false); deviceParams.append(asyncParam); QVariantMap brokenParam; - brokenParam.insert("name", "broken"); + brokenParam.insert("paramTypeId", brokenParamTypeId); brokenParam.insert("value", false); deviceParams.append(brokenParam); QVariantMap httpportParam; - httpportParam.insert("name", "httpport"); + httpportParam.insert("paramTypeId", httpportParamTypeId); httpportParam.insert("value", 8889); deviceParams.append(httpportParam); params.insert("deviceParams", deviceParams); @@ -364,7 +355,7 @@ void TestDevices::discoverDevices_data() QVariantList discoveryParams; QVariantMap resultCountParam; - resultCountParam.insert("name", "resultCount"); + resultCountParam.insert("paramTypeId", resultCountParamTypeId); resultCountParam.insert("value", 1); discoveryParams.append(resultCountParam); @@ -429,7 +420,7 @@ void TestDevices::addPushButtonDevices() // Discover device QVariantList discoveryParams; QVariantMap resultCountParam; - resultCountParam.insert("name", "resultCount"); + resultCountParam.insert("paramTypeId", resultCountParamTypeId); resultCountParam.insert("value", 1); discoveryParams.append(resultCountParam); @@ -495,7 +486,7 @@ void TestDevices::addDisplayPinDevices() // Discover device QVariantList discoveryParams; QVariantMap resultCountParam; - resultCountParam.insert("name", "resultCount"); + resultCountParam.insert("paramTypeId", resultCountParamTypeId); resultCountParam.insert("value", 1); discoveryParams.append(resultCountParam); @@ -792,7 +783,7 @@ void TestDevices::editDevices() // add device QVariantList deviceParams; QVariantMap httpportParam; - httpportParam.insert("name", "httpport"); + httpportParam.insert("paramTypeId", httpportParamTypeId); httpportParam.insert("value", 8889); deviceParams.append(httpportParam); @@ -849,19 +840,19 @@ void TestDevices::reconfigureDevices_data() { QVariantList asyncChangeDeviceParams; QVariantMap asyncParamDifferent; - asyncParamDifferent.insert("name", "async"); + asyncParamDifferent.insert("paramTypeId", asyncParamTypeId); asyncParamDifferent.insert("value", true); asyncChangeDeviceParams.append(asyncParamDifferent); QVariantList httpportChangeDeviceParams; QVariantMap httpportParamDifferent; - httpportParamDifferent.insert("name", "httpport"); + httpportParamDifferent.insert("paramTypeId", httpportParamTypeId); httpportParamDifferent.insert("value", 8893); // if change -> change also newPort in reconfigureDevices() httpportChangeDeviceParams.append(httpportParamDifferent); QVariantList brokenChangedDeviceParams; QVariantMap brokenParamDifferent; - brokenParamDifferent.insert("name", "broken"); + brokenParamDifferent.insert("paramTypeId", brokenParamTypeId); brokenParamDifferent.insert("value", true); brokenChangedDeviceParams.append(brokenParamDifferent); @@ -896,15 +887,15 @@ void TestDevices::reconfigureDevices() params.insert("name", "Device to edit"); QVariantList deviceParams; QVariantMap asyncParam; - asyncParam.insert("name", "async"); + asyncParam.insert("paramTypeId", asyncParamTypeId); asyncParam.insert("value", false); deviceParams.append(asyncParam); QVariantMap brokenParam; - brokenParam.insert("name", "broken"); + brokenParam.insert("paramTypeId", brokenParamTypeId); brokenParam.insert("value", broken); deviceParams.append(brokenParam); QVariantMap httpportParam; - httpportParam.insert("name", "httpport"); + httpportParam.insert("paramTypeId", httpportParamTypeId); httpportParam.insert("value", 8892); deviceParams.append(httpportParam); params.insert("deviceParams", deviceParams); @@ -1019,7 +1010,7 @@ void TestDevices::reconfigureByDiscovery_data() QVariantList discoveryParams; QVariantMap resultCountParam; - resultCountParam.insert("name", "resultCount"); + resultCountParam.insert("paramTypeId", resultCountParamTypeId); resultCountParam.insert("value", 2); discoveryParams.append(resultCountParam); @@ -1124,7 +1115,7 @@ void TestDevices::reconfigureByDiscovery() // Note: this shows that by discovery a not editable param (name) can be changed! foreach (QVariant param, deviceMap.value("params").toList()) { - if (param.toMap().value("name") == "httpport") { + if (param.toMap().value("paramTypeId") == httpportParamTypeId) { QCOMPARE(param.toMap().value("value").toInt(), 55556); } } diff --git a/tests/auto/events/testevents.cpp b/tests/auto/events/testevents.cpp index 5aa2545a..55b12d63 100644 --- a/tests/auto/events/testevents.cpp +++ b/tests/auto/events/testevents.cpp @@ -60,7 +60,7 @@ void TestEvents::triggerEvent() QNetworkAccessManager nam; // trigger event in mock device - int port = device->paramValue("httpport").toInt(); + int port = device->paramValue(httpportParamTypeId).toInt(); QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(port).arg(mockEvent1Id.toString()))); QNetworkReply *reply = nam.get(request); reply->deleteLater(); @@ -89,7 +89,7 @@ void TestEvents::triggerStateChangeEvent() QNetworkAccessManager nam; // trigger state changed event in mock device - int port = device->paramValue("httpport").toInt(); + int port = device->paramValue(httpportParamTypeId).toInt(); QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockIntStateId.toString()).arg(11))); QNetworkReply *reply = nam.get(request); reply->deleteLater(); @@ -102,7 +102,7 @@ void TestEvents::triggerStateChangeEvent() if (event.deviceId() == device->id()) { // Make sure the event contains all the stuff we expect QCOMPARE(event.eventTypeId().toString(), mockIntStateId.toString()); - QCOMPARE(event.param("value").value().toInt(), 11); + QCOMPARE(event.param(ParamTypeId(mockIntStateId.toString())).value().toInt(), 11); } } } @@ -111,12 +111,13 @@ void TestEvents::params() { Event event; ParamList params; - Param p("foo", "bar"); + ParamTypeId id = ParamTypeId::createParamTypeId(); + Param p(id, "foo bar"); params.append(p); event.setParams(params); - QVERIFY(event.param("foo").value().toString() == "bar"); - QVERIFY(!event.param("baz").value().isValid()); + QVERIFY(event.param(id).value().toString() == "foo bar"); + QVERIFY(!event.param(ParamTypeId::createParamTypeId()).value().isValid()); } void TestEvents::getEventType_data() diff --git a/tests/auto/guhtestbase.cpp b/tests/auto/guhtestbase.cpp index 15462f0b..3d5de117 100644 --- a/tests/auto/guhtestbase.cpp +++ b/tests/auto/guhtestbase.cpp @@ -61,6 +61,34 @@ ActionTypeId mockActionIdAsync = ActionTypeId("fbae06d3-7666-483e-a39e-ec50fe890 ActionTypeId mockActionIdFailing = ActionTypeId("df3cf33d-26d5-4577-9132-9823bd33fad0"); ActionTypeId mockActionIdAsyncFailing = ActionTypeId("bfe89a1d-3497-4121-8318-e77c37537219"); +ParamTypeId configParamIntParamTypeId = ParamTypeId("e1f72121-a426-45e2-b475-8262b5cdf103"); +ParamTypeId configParamBoolParamTypeId = ParamTypeId("c75723b6-ea4f-4982-9751-6c5e39c88145"); +ParamTypeId httpportParamTypeId = ParamTypeId("d4f06047-125e-4479-9810-b54c189917f5"); +ParamTypeId asyncParamTypeId = ParamTypeId("f2977061-4dd0-4ef5-85aa-3b7134743be3"); +ParamTypeId brokenParamTypeId = ParamTypeId("ae8f8901-f2c1-42a5-8111-6d2fc8e4c1e4"); +ParamTypeId resultCountParamTypeId = ParamTypeId("d222adb4-2f9c-4c3f-8655-76400d0fb6ce"); +ParamTypeId mockActionParam1ParamTypeId = ParamTypeId("a2d3a256-a551-4712-a65b-ecd5a436a1cb"); +ParamTypeId mockActionParam2ParamTypeId = ParamTypeId("304a4899-18be-4e3b-94f4-d03be52f3233"); +ParamTypeId mockParamIntParamTypeId = ParamTypeId("0550e16d-60b9-4ba5-83f4-4d3cee656121"); +ParamTypeId colorActionParamTypeId = ParamTypeId("20dc7c22-c50e-42db-837c-2bbced939f8e"); +ParamTypeId percentageActionParamTypeId = ParamTypeId("72981c04-267a-4ba0-a59e-9921d2f3af9c"); +ParamTypeId allowedValuesActionParamTypeId = ParamTypeId("05f63f9c-f61e-4dcf-ad55-3f13fde2765b"); +ParamTypeId doubleActionParamTypeId = ParamTypeId("53cd7c55-49b7-441b-b970-9048f20f0e2c"); +ParamTypeId boolActionParamTypeId = ParamTypeId("e680f7a4-b39e-46da-be41-fa3170fe3768"); +ParamTypeId pinParamTypeId = ParamTypeId("da820e07-22dc-4173-9c07-2f49a4e265f9"); +ParamTypeId boolValueActionParamTypeId = ParamTypeId("d24ede5f-4064-4898-bb84-cfb533b1fbc0"); +ParamTypeId parentUuidParamTypeId = ParamTypeId("104b5288-404e-42d3-bf38-e40682e75681"); +ParamTypeId textLineParamTypeId = ParamTypeId("e6acf0c7-4b8e-4296-ac62-855d20deb816"); +ParamTypeId textAreaParamTypeId = ParamTypeId("716f0994-bc01-42b0-b64d-59236f7320d2"); +ParamTypeId passwordParamTypeId = ParamTypeId("e5c0d14b-c9f1-4aca-a56e-85bfa6977150"); +ParamTypeId searchParamTypeId = ParamTypeId("22add8c9-ee4f-43ad-8931-58e999313ac3"); +ParamTypeId mailParamTypeId = ParamTypeId("a8494faf-3a0f-4cf3-84b7-4b39148a838d"); +ParamTypeId ip4ParamTypeId = ParamTypeId("9e5f86a0-4bb3-4892-bff8-3fc4032af6e2"); +ParamTypeId ip6ParamTypeId = ParamTypeId("43bf3832-dd48-4090-a836-656e8b60216e"); +ParamTypeId urlParamTypeId = ParamTypeId("fa67229f-fcef-496f-b671-59a4b48f3ab5"); +ParamTypeId macParamTypeId = ParamTypeId("e93db587-7919-48f3-8c88-1651de63c765"); + + // Parent device EventTypeId mockParentChildEventId = EventTypeId("d24ede5f-4064-4898-bb84-cfb533b1fbc0"); ActionTypeId mockParentChildActionId = ActionTypeId("d24ede5f-4064-4898-bb84-cfb533b1fbc0"); @@ -151,12 +179,12 @@ void GuhTestBase::initTestCase() // Lets add one instance of the mockdevice QVariantMap params; - params.insert("deviceClassId", "{753f0d32-0468-4d08-82ed-1964aab03298}"); params.insert("name", "Test Mock Device"); + params.insert("deviceClassId", "{753f0d32-0468-4d08-82ed-1964aab03298}"); QVariantList deviceParams; QVariantMap httpPortParam; - httpPortParam.insert("name", "httpport"); + httpPortParam.insert("paramTypeId", httpportParamTypeId.toString()); httpPortParam.insert("value", m_mockDevice1Port); deviceParams.append(httpPortParam); params.insert("deviceParams", deviceParams); diff --git a/tests/auto/guhtestbase.h b/tests/auto/guhtestbase.h index e8a7f893..d9943880 100644 --- a/tests/auto/guhtestbase.h +++ b/tests/auto/guhtestbase.h @@ -55,6 +55,34 @@ extern EventTypeId mockEvent2Id; extern StateTypeId mockIntStateId; extern StateTypeId mockBoolStateId; +// ParamTypes from mock devices +extern ParamTypeId configParamIntParamTypeId; +extern ParamTypeId configParamBoolParamTypeId; +extern ParamTypeId httpportParamTypeId; +extern ParamTypeId asyncParamTypeId; +extern ParamTypeId brokenParamTypeId; +extern ParamTypeId resultCountParamTypeId; +extern ParamTypeId mockActionParam1ParamTypeId; +extern ParamTypeId mockActionParam2ParamTypeId; +extern ParamTypeId mockParamIntParamTypeId; +extern ParamTypeId colorActionParamTypeId; +extern ParamTypeId percentageActionParamTypeId; +extern ParamTypeId allowedValuesActionParamTypeId; +extern ParamTypeId doubleActionParamTypeId; +extern ParamTypeId boolActionParamTypeId; +extern ParamTypeId pinParamTypeId; +extern ParamTypeId boolValueActionParamTypeId; +extern ParamTypeId parentUuidParamTypeId; +extern ParamTypeId textLineParamTypeId; +extern ParamTypeId textAreaParamTypeId; +extern ParamTypeId passwordParamTypeId; +extern ParamTypeId searchParamTypeId; +extern ParamTypeId mailParamTypeId; +extern ParamTypeId ip4ParamTypeId; +extern ParamTypeId ip6ParamTypeId; +extern ParamTypeId urlParamTypeId; +extern ParamTypeId macParamTypeId; + // Parent / Child device extern EventTypeId mockParentChildEventId; extern ActionTypeId mockParentChildActionId; @@ -124,7 +152,7 @@ protected: foreach (const QVariant &requestParam, requestList) { bool found = false; foreach (const QVariant &responseParam, responseList) { - if (requestParam.toMap().value("name") == responseParam.toMap().value("name")){ + if (requestParam.toMap().value("paramTypeId") == responseParam.toMap().value("paramTypeId")){ QCOMPARE(requestParam.toMap().value("value"), responseParam.toMap().value("value")); found = true; break; diff --git a/tests/auto/jsonrpc/testjsonrpc.cpp b/tests/auto/jsonrpc/testjsonrpc.cpp index 687d9fa9..5c79ab83 100644 --- a/tests/auto/jsonrpc/testjsonrpc.cpp +++ b/tests/auto/jsonrpc/testjsonrpc.cpp @@ -208,7 +208,7 @@ void TestJSONRPC::deviceAddedRemovedNotifications() // add device and wait for notification QVariantList deviceParams; QVariantMap httpportParam; - httpportParam.insert("name", "httpport"); + httpportParam.insert("paramTypeId", httpportParamTypeId); httpportParam.insert("value", 8765); deviceParams.append(httpportParam); @@ -418,7 +418,7 @@ void TestJSONRPC::deviceChangedNotifications() // add device and wait for notification QVariantList deviceParams; QVariantMap httpportParam; - httpportParam.insert("name", "httpport"); + httpportParam.insert("paramTypeId", httpportParamTypeId); httpportParam.insert("value", 23234); deviceParams.append(httpportParam); @@ -445,7 +445,7 @@ void TestJSONRPC::deviceChangedNotifications() // now reconfigure the device and check the deviceChanged notification QVariantList newDeviceParams; QVariantMap newHttpportParam; - newHttpportParam.insert("name", "httpport"); + newHttpportParam.insert("paramTypeId", httpportParamTypeId); newHttpportParam.insert("value", 45473); newDeviceParams.append(newHttpportParam); diff --git a/tests/auto/logging/testlogging.cpp b/tests/auto/logging/testlogging.cpp index 285d1179..644259d5 100644 --- a/tests/auto/logging/testlogging.cpp +++ b/tests/auto/logging/testlogging.cpp @@ -165,7 +165,7 @@ void TestLogging::eventLogs() QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray))); // trigger event in mock device - int port = device->paramValue("httpport").toInt(); + int port = device->paramValue(httpportParamTypeId).toInt(); QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(port).arg(mockEvent1Id.toString()))); QNetworkReply *reply = nam.get(request); @@ -218,11 +218,11 @@ void TestLogging::actionLog() { QVariantList actionParams; QVariantMap param1; - param1.insert("name", "mockActionParam1"); + param1.insert("paramTypeId", mockActionParam1ParamTypeId); param1.insert("value", 7); actionParams.append(param1); QVariantMap param2; - param2.insert("name", "mockActionParam2"); + param2.insert("paramTypeId", mockActionParam2ParamTypeId); param2.insert("value", true); actionParams.append(param2); diff --git a/tests/auto/restdeviceclasses/testrestdeviceclasses.cpp b/tests/auto/restdeviceclasses/testrestdeviceclasses.cpp index a3a65b0c..65abd117 100644 --- a/tests/auto/restdeviceclasses/testrestdeviceclasses.cpp +++ b/tests/auto/restdeviceclasses/testrestdeviceclasses.cpp @@ -245,11 +245,11 @@ void TestRestDeviceClasses::discoverDevices_data() QTest::addColumn("error"); QVariantMap resultCountParam; - resultCountParam.insert("name", "resultCount"); + resultCountParam.insert("paramTypeId", resultCountParamTypeId); resultCountParam.insert("value", 1); QVariantMap invalidResultCountParam; - invalidResultCountParam.insert("name", "resultCount"); + invalidResultCountParam.insert("paramTypeId", resultCountParamTypeId); invalidResultCountParam.insert("value", 10); QVariantList discoveryParams; diff --git a/tests/auto/restdevices/testrestdevices.cpp b/tests/auto/restdevices/testrestdevices.cpp index 03c76a67..a1dbf2b4 100644 --- a/tests/auto/restdevices/testrestdevices.cpp +++ b/tests/auto/restdevices/testrestdevices.cpp @@ -96,19 +96,19 @@ void TestRestDevices::addConfiguredDevice_data() QTest::addColumn("expectedStatusCode"); QVariantMap httpportParam; - httpportParam.insert("name", "httpport"); + httpportParam.insert("paramTypeId", httpportParamTypeId); httpportParam.insert("value", m_mockDevice1Port - 1); QVariantMap asyncParam; - asyncParam.insert("name", "async"); + asyncParam.insert("paramTypeId", asyncParamTypeId); asyncParam.insert("value", true); QVariantMap notAsyncParam; - notAsyncParam.insert("name", "async"); + notAsyncParam.insert("paramTypeId", asyncParamTypeId); notAsyncParam.insert("value", false); QVariantMap notBrokenParam; - notBrokenParam.insert("name", "broken"); + notBrokenParam.insert("paramTypeId", brokenParamTypeId); notBrokenParam.insert("value", false); QVariantMap brokenParam; - brokenParam.insert("name", "broken"); + brokenParam.insert("paramTypeId", brokenParamTypeId); brokenParam.insert("value", true); QVariantList deviceParams; @@ -131,7 +131,7 @@ void TestRestDevices::addConfiguredDevice_data() QTest::newRow("User, JustAdd, missing params") << mockDeviceClassId << invalidDeviceParams << 500; QVariantMap fakeparam; - fakeparam.insert("name", "tropptth"); + fakeparam.insert("paramTypeId", ParamTypeId::createParamTypeId()); invalidDeviceParams.append(fakeparam); QTest::newRow("User, JustAdd, invalid param") << mockDeviceClassId << invalidDeviceParams << 500; @@ -190,7 +190,7 @@ void TestRestDevices::addPushButtonDevices() // Discover device QVariantList discoveryParams; QVariantMap resultCountParam; - resultCountParam.insert("name", "resultCount"); + resultCountParam.insert("paramTypeId", resultCountParamTypeId); resultCountParam.insert("value", 1); discoveryParams.append(resultCountParam); @@ -271,7 +271,7 @@ void TestRestDevices::addDisplayPinDevices() // Discover device QVariantList discoveryParams; QVariantMap resultCountParam; - resultCountParam.insert("name", "resultCount"); + resultCountParam.insert("paramTypeId", resultCountParamTypeId); resultCountParam.insert("value", 1); discoveryParams.append(resultCountParam); @@ -411,11 +411,11 @@ void TestRestDevices::executeAction_data() QVariantList params; QVariantMap param1; - param1.insert("name", "mockActionParam1"); + param1.insert("paramTypeId", mockActionParam1ParamTypeId); param1.insert("value", 5); params.append(param1); QVariantMap param2; - param2.insert("name", "mockActionParam2"); + param2.insert("paramTypeId", mockActionParam2ParamTypeId); param2.insert("value", true); params.append(param2); @@ -540,7 +540,7 @@ void TestRestDevices::editDevices() QVariantList deviceParams; QVariantMap httpportParam; - httpportParam.insert("name", "httpport"); + httpportParam.insert("paramTypeId", httpportParamTypeId); httpportParam.insert("value", m_mockDevice1Port - 2); deviceParams.append(httpportParam); @@ -579,19 +579,19 @@ void TestRestDevices::reconfigureDevices_data() { QVariantList asyncChangeDeviceParams; QVariantMap asyncParamDifferent; - asyncParamDifferent.insert("name", "async"); + asyncParamDifferent.insert("paramTypeId", asyncParamTypeId); asyncParamDifferent.insert("value", true); asyncChangeDeviceParams.append(asyncParamDifferent); QVariantList httpportChangeDeviceParams; QVariantMap httpportParamDifferent; - httpportParamDifferent.insert("name", "httpport"); + httpportParamDifferent.insert("paramTypeId", httpportParamTypeId); httpportParamDifferent.insert("value", 8895); // if change -> change also newPort in reconfigureDevices() httpportChangeDeviceParams.append(httpportParamDifferent); QVariantList brokenChangedDeviceParams; QVariantMap brokenParamDifferent; - brokenParamDifferent.insert("name", "broken"); + brokenParamDifferent.insert("paramTypeId", brokenParamTypeId); brokenParamDifferent.insert("value", true); brokenChangedDeviceParams.append(brokenParamDifferent); @@ -627,15 +627,15 @@ void TestRestDevices::reconfigureDevices() params.insert("name", "Edit mock device"); QVariantList deviceParams; QVariantMap asyncParam; - asyncParam.insert("name", "async"); + asyncParam.insert("paramTypeId", asyncParamTypeId); asyncParam.insert("value", false); deviceParams.append(asyncParam); QVariantMap brokenParam; - brokenParam.insert("name", "broken"); + brokenParam.insert("paramTypeId", brokenParamTypeId); brokenParam.insert("value", broken); deviceParams.append(brokenParam); QVariantMap httpportParam; - httpportParam.insert("name", "httpport"); + httpportParam.insert("paramTypeId", httpportParamTypeId); httpportParam.insert("value", 8896); deviceParams.append(httpportParam); params.insert("deviceParams", deviceParams); @@ -687,7 +687,7 @@ void TestRestDevices::reconfigureByDiscovery_data() QVariantList discoveryParams; QVariantMap resultCountParam; - resultCountParam.insert("name", "resultCount"); + resultCountParam.insert("paramTypeId", resultCountParamTypeId); resultCountParam.insert("value", 2); discoveryParams.append(resultCountParam); diff --git a/tests/auto/restlogging/testrestlogging.cpp b/tests/auto/restlogging/testrestlogging.cpp index c6ea5136..49d47289 100644 --- a/tests/auto/restlogging/testrestlogging.cpp +++ b/tests/auto/restlogging/testrestlogging.cpp @@ -42,8 +42,6 @@ private: private slots: void initLogs(); - void systemLogs(); - void invalidFilter_data(); void invalidFilter(); @@ -73,39 +71,6 @@ void TestRestLogging::initLogs() qDebug() << "Got" << logEntries.count() << "logs"; QVERIFY(logEntries.count() == 0); - restartServer(); -} - -void TestRestLogging::systemLogs() -{ - // check the active system log at boot - QVariantMap params; - params.insert("loggingSources", QVariantList() << JsonTypes::loggingSourceToString(Logging::LoggingSourceSystem)); - params.insert("eventTypes", QVariantList() << JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeActiveChange)); - - QUrl url("http://localhost:3333/api/v1/logs"); - QUrlQuery query; - query.addQueryItem("filter", QJsonDocument::fromVariant(params).toJson(QJsonDocument::Compact)); - url.setQuery(query); - - // there should be 2 logs, one for shutdown, one for startup (from server restart) - QVariant response = getAndWait(QNetworkRequest(url)); - QVariantList logEntries = response.toList(); - QVERIFY(logEntries.count() == 2); - - QVariantMap logEntryShutdown = logEntries.first().toMap(); - - QCOMPARE(logEntryShutdown.value("active").toBool(), false); - QCOMPARE(logEntryShutdown.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeActiveChange)); - QCOMPARE(logEntryShutdown.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceSystem)); - QCOMPARE(logEntryShutdown.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelInfo)); - - QVariantMap logEntryStartup = logEntries.last().toMap(); - - QCOMPARE(logEntryStartup.value("active").toBool(), true); - QCOMPARE(logEntryStartup.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeActiveChange)); - QCOMPARE(logEntryStartup.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceSystem)); - QCOMPARE(logEntryStartup.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelInfo)); } void TestRestLogging::invalidFilter_data() @@ -154,7 +119,6 @@ void TestRestLogging::invalidFilterJson() url.setQuery(query); getAndWait(QNetworkRequest(url), 400); - } void TestRestLogging::eventLogs() @@ -171,7 +135,7 @@ void TestRestLogging::eventLogs() QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray))); // trigger event in mock device - int port = device->paramValue("httpport").toInt(); + int port = device->paramValue(httpportParamTypeId).toInt(); QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(port).arg(mockEvent1Id.toString()))); QNetworkReply *reply = nam.get(request); clientSpy.wait(); @@ -223,11 +187,11 @@ void TestRestLogging::actionLog() { QVariantList actionParams; QVariantMap param1; - param1.insert("name", "mockActionParam1"); + param1.insert("paramTypeId", mockActionParam1ParamTypeId); param1.insert("value", 7); actionParams.append(param1); QVariantMap param2; - param2.insert("name", "mockActionParam2"); + param2.insert("paramTypeId", mockActionParam2ParamTypeId); param2.insert("value", true); actionParams.append(param2); @@ -374,7 +338,7 @@ void TestRestLogging::removeDevice() QUrl url("http://localhost:3333/api/v1/logs"); response = getAndWait(QNetworkRequest(url)); QVariantList logEntries = response.toList(); - QVERIFY(logEntries.count() > 0); + QVERIFY2(!logEntries.count() != 0, "No log entries left"); // verify that the logs from this device where removed from the db QVariantMap params; diff --git a/tests/auto/restrules/testrestrules.cpp b/tests/auto/restrules/testrestrules.cpp index 391503d8..fd805624 100644 --- a/tests/auto/restrules/testrestrules.cpp +++ b/tests/auto/restrules/testrestrules.cpp @@ -167,11 +167,11 @@ QVariant TestRestRules::validIntStateBasedRule(const QString &name, const bool & action.insert("actionTypeId", mockActionIdWithParams); QVariantList actionParams; QVariantMap param1; - param1.insert("name", "mockActionParam1"); + param1.insert("paramTypeId", mockActionParam1ParamTypeId); param1.insert("value", 5); actionParams.append(param1); QVariantMap param2; - param2.insert("name", "mockActionParam2"); + param2.insert("paramTypeId", mockActionParam2ParamTypeId); param2.insert("value", true); actionParams.append(param2); action.insert("deviceId", m_mockDeviceId); @@ -368,7 +368,7 @@ void TestRestRules::addRemoveRules_data() validEventDescriptor2.insert("deviceId", m_mockDeviceId); QVariantList params; QVariantMap param1; - param1.insert("name", "mockParamInt"); + param1.insert("paramTypeId", mockParamIntParamTypeId); param1.insert("value", 3); param1.insert("operator", JsonTypes::valueOperatorToString(Types::ValueOperatorEquals)); params.append(param1); @@ -394,11 +394,11 @@ void TestRestRules::addRemoveRules_data() validActionEventBased.insert("actionTypeId", mockActionIdWithParams); validActionEventBased.insert("deviceId", m_mockDeviceId); QVariantMap validActionEventBasedParam1; - validActionEventBasedParam1.insert("name", "mockActionParam1"); + validActionEventBasedParam1.insert("paramTypeId", mockActionParam1ParamTypeId); validActionEventBasedParam1.insert("eventTypeId", mockEvent2Id); - validActionEventBasedParam1.insert("eventParamName", "mockParamInt"); + validActionEventBasedParam1.insert("eventParamTypeId", mockEvent2Id); QVariantMap validActionEventBasedParam2; - validActionEventBasedParam2.insert("name", "mockActionParam2"); + validActionEventBasedParam2.insert("paramTypeId", mockActionParam2ParamTypeId); validActionEventBasedParam2.insert("value", false); validActionEventBased.insert("ruleActionParams", QVariantList() << validActionEventBasedParam1 << validActionEventBasedParam2); @@ -412,11 +412,11 @@ void TestRestRules::addRemoveRules_data() invalidActionEventBased2.insert("actionTypeId", mockActionIdWithParams); invalidActionEventBased2.insert("deviceId", m_mockDeviceId); QVariantMap invalidActionEventBasedParam2; - invalidActionEventBasedParam2.insert("name", "mockActionParam1"); + invalidActionEventBasedParam2.insert("paramTypeId", mockActionParam1ParamTypeId); invalidActionEventBasedParam2.insert("eventTypeId", mockEvent1Id); - invalidActionEventBasedParam2.insert("eventParamName", "value"); + invalidActionEventBasedParam2.insert("eventParamTypeId", mockEvent1Id); QVariantMap invalidActionEventBasedParam3; - invalidActionEventBasedParam3.insert("name", "mockActionParam2"); + invalidActionEventBasedParam3.insert("paramTypeId", mockActionParam2ParamTypeId); invalidActionEventBasedParam3.insert("value", 2); invalidActionEventBased2.insert("ruleActionParams", QVariantList() << invalidActionEventBasedParam2 << invalidActionEventBasedParam3); @@ -424,9 +424,9 @@ void TestRestRules::addRemoveRules_data() invalidActionEventBased3.insert("actionTypeId", mockActionIdWithParams); invalidActionEventBased3.insert("deviceId", m_mockDeviceId); QVariantMap invalidActionEventBasedParam4; - invalidActionEventBasedParam4.insert("name", "mockActionParam1"); + invalidActionEventBasedParam4.insert("paramTypeId", mockActionParam1ParamTypeId); invalidActionEventBasedParam4.insert("eventTypeId", mockEvent1Id); - invalidActionEventBasedParam4.insert("eventParamName", "mockParamInt"); + invalidActionEventBasedParam4.insert("eventParamTypeId", mockEvent1Id); invalidActionEventBased3.insert("ruleActionParams", QVariantList() << invalidActionEventBasedParam4); QTest::addColumn("enabled"); @@ -580,7 +580,7 @@ void TestRestRules::editRules_data() stateDescriptor.insert("stateTypeId", mockIntStateId); stateDescriptor.insert("deviceId", m_mockDeviceId); stateDescriptor.insert("operator", JsonTypes::valueOperatorToString(Types::ValueOperatorLess)); - stateDescriptor.insert("value", "20"); + stateDescriptor.insert("value", 20); // StateEvaluator QVariantMap validStateEvaluator; @@ -628,11 +628,11 @@ void TestRestRules::editRules_data() validActionEventBased.insert("actionTypeId", mockActionIdWithParams); validActionEventBased.insert("deviceId", m_mockDeviceId); QVariantMap validActionEventBasedParam1; - validActionEventBasedParam1.insert("name", "mockActionParam1"); + validActionEventBasedParam1.insert("paramTypeId", mockActionParam1ParamTypeId); validActionEventBasedParam1.insert("eventTypeId", mockEvent2Id); - validActionEventBasedParam1.insert("eventParamName", "mockParamInt"); + validActionEventBasedParam1.insert("eventParamTypeId", mockEvent2Id); QVariantMap validActionEventBasedParam2; - validActionEventBasedParam2.insert("name", "mockActionParam2"); + validActionEventBasedParam2.insert("paramTypeId", mockActionParam2ParamTypeId); validActionEventBasedParam2.insert("value", false); validActionEventBased.insert("ruleActionParams", QVariantList() << validActionEventBasedParam1 << validActionEventBasedParam2); @@ -646,11 +646,11 @@ void TestRestRules::editRules_data() invalidActionEventBased2.insert("actionTypeId", mockActionIdWithParams); invalidActionEventBased2.insert("deviceId", m_mockDeviceId); QVariantMap invalidActionEventBasedParam2; - invalidActionEventBasedParam2.insert("name", "mockActionParam1"); + invalidActionEventBasedParam2.insert("paramTypeId", mockActionParam1ParamTypeId); invalidActionEventBasedParam2.insert("eventTypeId", mockEvent1Id); - invalidActionEventBasedParam2.insert("eventParamName", "value"); + invalidActionEventBasedParam2.insert("eventParamTypeId", mockEvent1Id); QVariantMap invalidActionEventBasedParam3; - invalidActionEventBasedParam3.insert("name", "mockActionParam2"); + invalidActionEventBasedParam3.insert("paramTypeId", mockActionParam2ParamTypeId); invalidActionEventBasedParam3.insert("value", 2); invalidActionEventBased2.insert("ruleActionParams", QVariantList() << invalidActionEventBasedParam2 << invalidActionEventBasedParam3); @@ -658,9 +658,9 @@ void TestRestRules::editRules_data() invalidActionEventBased3.insert("actionTypeId", mockActionIdWithParams); invalidActionEventBased3.insert("deviceId", m_mockDeviceId); QVariantMap invalidActionEventBasedParam4; - invalidActionEventBasedParam4.insert("name", "mockActionParam1"); + invalidActionEventBasedParam4.insert("paramTypeId", mockActionParam1ParamTypeId); invalidActionEventBasedParam4.insert("eventTypeId", mockEvent1Id); - invalidActionEventBasedParam4.insert("eventParamName", "mockParamInt"); + invalidActionEventBasedParam4.insert("eventParamTypeId", mockEvent1Id); invalidActionEventBased3.insert("ruleActionParams", QVariantList() << invalidActionEventBasedParam4); QTest::addColumn("enabled"); @@ -717,7 +717,7 @@ void TestRestRules::editRules() eventDescriptor2.insert("deviceId", m_mockDeviceId); eventDescriptor2.insert("paramDescriptors", QVariantList()); QVariantMap eventParam1; - eventParam1.insert("name", "mockParamInt"); + eventParam1.insert("paramTypeId", mockParamIntParamTypeId); eventParam1.insert("value", 3); eventParam1.insert("operator", JsonTypes::valueOperatorToString(Types::ValueOperatorEquals)); eventParamDescriptors.append(eventParam1); @@ -760,11 +760,11 @@ void TestRestRules::editRules() action2.insert("deviceId", m_mockDeviceId); QVariantList action2Params; QVariantMap action2Param1; - action2Param1.insert("name", "mockActionParam1"); + action2Param1.insert("paramTypeId", mockActionParam1ParamTypeId); action2Param1.insert("value", 5); action2Params.append(action2Param1); QVariantMap action2Param2; - action2Param2.insert("name", "mockActionParam2"); + action2Param2.insert("paramTypeId", mockActionParam2ParamTypeId); action2Param2.insert("value", true); action2Params.append(action2Param2); action2.insert("ruleActionParams", action2Params); @@ -774,11 +774,11 @@ void TestRestRules::editRules() validActionEventBased.insert("actionTypeId", mockActionIdWithParams); validActionEventBased.insert("deviceId", m_mockDeviceId); QVariantMap validActionEventBasedParam1; - validActionEventBasedParam1.insert("name", "mockActionParam1"); + validActionEventBasedParam1.insert("paramTypeId", mockActionParam1ParamTypeId); validActionEventBasedParam1.insert("eventTypeId", mockEvent2Id); - validActionEventBasedParam1.insert("eventParamName", "mockParamInt"); + validActionEventBasedParam1.insert("eventParamTypeId", mockEvent2Id); QVariantMap validActionEventBasedParam2; - validActionEventBasedParam2.insert("name", "mockActionParam2"); + validActionEventBasedParam2.insert("paramTypeId", mockActionParam2ParamTypeId); validActionEventBasedParam2.insert("value", false); validActionEventBased.insert("ruleActionParams", QVariantList() << validActionEventBasedParam1 << validActionEventBasedParam2); diff --git a/tests/auto/rules/testrules.cpp b/tests/auto/rules/testrules.cpp index afb42937..7e7fe8c6 100644 --- a/tests/auto/rules/testrules.cpp +++ b/tests/auto/rules/testrules.cpp @@ -124,10 +124,10 @@ QVariantMap TestRules::createActionWithParams(const DeviceId &deviceId) QVariantMap action; QVariantList ruleActionParams; QVariantMap param1; - param1.insert("name", "mockActionParam1"); + param1.insert("paramTypeId", mockActionParam1ParamTypeId); param1.insert("value", 4); QVariantMap param2; - param2.insert("name", "mockActionParam2"); + param2.insert("paramTypeId", mockActionParam2ParamTypeId); param2.insert("value", true); ruleActionParams.append(param1); ruleActionParams.append(param2); @@ -168,6 +168,7 @@ void TestRules::verifyRuleNotExecuted() reply->deleteLater(); } + /***********************************************************************/ void TestRules::cleanup() { @@ -213,11 +214,11 @@ QVariant TestRules::validIntStateBasedRule(const QString &name, const bool &exec action.insert("actionTypeId", mockActionIdWithParams); QVariantList actionParams; QVariantMap param1; - param1.insert("name", "mockActionParam1"); + param1.insert("paramTypeId", mockActionParam1ParamTypeId); param1.insert("value", 5); actionParams.append(param1); QVariantMap param2; - param2.insert("name", "mockActionParam2"); + param2.insert("paramTypeId", mockActionParam2ParamTypeId); param2.insert("value", true); actionParams.append(param2); action.insert("deviceId", m_mockDeviceId); @@ -247,11 +248,6 @@ void TestRules::addRemoveRules_data() validActionNoParams.insert("deviceId", m_mockDeviceId); validActionNoParams.insert("ruleActionParams", QVariantList()); - QVariantMap validActionWithParams; - validActionWithParams.insert("actionTypeId", mockActionIdNoParams); - validActionWithParams.insert("deviceId", m_mockDeviceId); - validActionWithParams.insert("ruleActionParams", QVariantList()); - QVariantMap invalidAction; invalidAction.insert("actionTypeId", ActionTypeId()); invalidAction.insert("deviceId", m_mockDeviceId); @@ -295,7 +291,7 @@ void TestRules::addRemoveRules_data() validEventDescriptor2.insert("deviceId", m_mockDeviceId); QVariantList params; QVariantMap param1; - param1.insert("name", "mockParamInt"); + param1.insert("paramTypeId", mockParamIntParamTypeId); param1.insert("value", 3); param1.insert("operator", JsonTypes::valueOperatorToString(Types::ValueOperatorEquals)); params.append(param1); @@ -321,11 +317,11 @@ void TestRules::addRemoveRules_data() validActionEventBased.insert("actionTypeId", mockActionIdWithParams); validActionEventBased.insert("deviceId", m_mockDeviceId); QVariantMap validActionEventBasedParam1; - validActionEventBasedParam1.insert("name", "mockActionParam1"); + validActionEventBasedParam1.insert("paramTypeId", mockActionParam1ParamTypeId); validActionEventBasedParam1.insert("eventTypeId", mockEvent2Id); - validActionEventBasedParam1.insert("eventParamName", "mockParamInt"); + validActionEventBasedParam1.insert("eventParamTypeId", mockParamIntParamTypeId); QVariantMap validActionEventBasedParam2; - validActionEventBasedParam2.insert("name", "mockActionParam2"); + validActionEventBasedParam2.insert("paramTypeId", mockActionParam2ParamTypeId); validActionEventBasedParam2.insert("value", false); validActionEventBased.insert("ruleActionParams", QVariantList() << validActionEventBasedParam1 << validActionEventBasedParam2); @@ -339,11 +335,11 @@ void TestRules::addRemoveRules_data() invalidActionEventBased2.insert("actionTypeId", mockActionIdWithParams); invalidActionEventBased2.insert("deviceId", m_mockDeviceId); QVariantMap invalidActionEventBasedParam2; - invalidActionEventBasedParam2.insert("name", "mockActionParam1"); + invalidActionEventBasedParam2.insert("paramTypeId", mockActionParam1ParamTypeId); invalidActionEventBasedParam2.insert("eventTypeId", mockEvent1Id); - invalidActionEventBasedParam2.insert("eventParamName", "value"); + invalidActionEventBasedParam2.insert("eventParamTypeId", "value"); QVariantMap invalidActionEventBasedParam3; - invalidActionEventBasedParam3.insert("name", "mockActionParam2"); + invalidActionEventBasedParam3.insert("paramTypeId", mockActionParam2ParamTypeId); invalidActionEventBasedParam3.insert("value", 2); invalidActionEventBased2.insert("ruleActionParams", QVariantList() << invalidActionEventBasedParam2 << invalidActionEventBasedParam3); @@ -351,12 +347,11 @@ void TestRules::addRemoveRules_data() invalidActionEventBased3.insert("actionTypeId", mockActionIdWithParams); invalidActionEventBased3.insert("deviceId", m_mockDeviceId); QVariantMap invalidActionEventBasedParam4; - invalidActionEventBasedParam4.insert("name", "mockActionParam1"); + invalidActionEventBasedParam4.insert("paramTypeId", mockActionParam1ParamTypeId); invalidActionEventBasedParam4.insert("eventTypeId", mockEvent1Id); - invalidActionEventBasedParam4.insert("eventParamName", "mockParamInt"); + invalidActionEventBasedParam4.insert("eventParamTypeId", mockParamIntParamTypeId); invalidActionEventBased3.insert("ruleActionParams", QVariantList() << invalidActionEventBasedParam4); - QTest::addColumn("enabled"); QTest::addColumn("action1"); QTest::addColumn("exitAction1"); @@ -449,8 +444,6 @@ void TestRules::addRemoveRules() params.clear(); params.insert("ruleId", newRuleId); response = injectAndWait("Rules.GetRuleDetails", params); - // verifySuccess(response); - QVariantMap rule = response.toMap().value("params").toMap().value("rule").toMap(); qDebug() << rule.value("name").toString(); @@ -541,7 +534,7 @@ void TestRules::editRules_data() validEventDescriptor2.insert("deviceId", m_mockDeviceId); QVariantList params; QVariantMap param1; - param1.insert("name", "mockParamInt"); + param1.insert("paramTypeId", mockParamIntParamTypeId); param1.insert("value", 3); param1.insert("operator", JsonTypes::valueOperatorToString(Types::ValueOperatorEquals)); params.append(param1); @@ -567,11 +560,11 @@ void TestRules::editRules_data() validActionEventBased.insert("actionTypeId", mockActionIdWithParams); validActionEventBased.insert("deviceId", m_mockDeviceId); QVariantMap validActionEventBasedParam1; - validActionEventBasedParam1.insert("name", "mockActionParam1"); + validActionEventBasedParam1.insert("paramTypeId", mockActionParam1ParamTypeId); validActionEventBasedParam1.insert("eventTypeId", mockEvent2Id); - validActionEventBasedParam1.insert("eventParamName", "mockParamInt"); + validActionEventBasedParam1.insert("eventParamTypeId", mockParamIntParamTypeId); QVariantMap validActionEventBasedParam2; - validActionEventBasedParam2.insert("name", "mockActionParam2"); + validActionEventBasedParam2.insert("paramTypeId", mockActionParam2ParamTypeId); validActionEventBasedParam2.insert("value", false); validActionEventBased.insert("ruleActionParams", QVariantList() << validActionEventBasedParam1 << validActionEventBasedParam2); @@ -585,11 +578,11 @@ void TestRules::editRules_data() invalidActionEventBased2.insert("actionTypeId", mockActionIdWithParams); invalidActionEventBased2.insert("deviceId", m_mockDeviceId); QVariantMap invalidActionEventBasedParam2; - invalidActionEventBasedParam2.insert("name", "mockActionParam1"); + invalidActionEventBasedParam2.insert("paramTypeId", mockActionParam1ParamTypeId); invalidActionEventBasedParam2.insert("eventTypeId", mockEvent1Id); - invalidActionEventBasedParam2.insert("eventParamName", "value"); + invalidActionEventBasedParam2.insert("eventParamTypeId", "value"); QVariantMap invalidActionEventBasedParam3; - invalidActionEventBasedParam3.insert("name", "mockActionParam2"); + invalidActionEventBasedParam3.insert("paramTypeId", mockActionParam2ParamTypeId); invalidActionEventBasedParam3.insert("value", 2); invalidActionEventBased2.insert("ruleActionParams", QVariantList() << invalidActionEventBasedParam2 << invalidActionEventBasedParam3); @@ -597,9 +590,9 @@ void TestRules::editRules_data() invalidActionEventBased3.insert("actionTypeId", mockActionIdWithParams); invalidActionEventBased3.insert("deviceId", m_mockDeviceId); QVariantMap invalidActionEventBasedParam4; - invalidActionEventBasedParam4.insert("name", "mockActionParam1"); + invalidActionEventBasedParam4.insert("paramTypeId", mockActionParam1ParamTypeId); invalidActionEventBasedParam4.insert("eventTypeId", mockEvent1Id); - invalidActionEventBasedParam4.insert("eventParamName", "mockParamInt"); + invalidActionEventBasedParam4.insert("eventParamTypeId", mockParamIntParamTypeId); invalidActionEventBased3.insert("ruleActionParams", QVariantList() << invalidActionEventBasedParam4); QTest::addColumn("enabled"); @@ -656,7 +649,7 @@ void TestRules::editRules() eventDescriptor2.insert("deviceId", m_mockDeviceId); eventDescriptor2.insert("paramDescriptors", QVariantList()); QVariantMap eventParam1; - eventParam1.insert("name", "mockParamInt"); + eventParam1.insert("paramTypeId", mockParamIntParamTypeId); eventParam1.insert("value", 3); eventParam1.insert("operator", JsonTypes::valueOperatorToString(Types::ValueOperatorEquals)); eventParamDescriptors.append(eventParam1); @@ -699,11 +692,11 @@ void TestRules::editRules() action2.insert("deviceId", m_mockDeviceId); QVariantList action2Params; QVariantMap action2Param1; - action2Param1.insert("name", "mockActionParam1"); + action2Param1.insert("paramTypeId", mockActionParam1ParamTypeId); action2Param1.insert("value", 5); action2Params.append(action2Param1); QVariantMap action2Param2; - action2Param2.insert("name", "mockActionParam2"); + action2Param2.insert("paramTypeId", mockActionParam2ParamTypeId); action2Param2.insert("value", true); action2Params.append(action2Param2); action2.insert("ruleActionParams", action2Params); @@ -713,11 +706,11 @@ void TestRules::editRules() validActionEventBased.insert("actionTypeId", mockActionIdWithParams); validActionEventBased.insert("deviceId", m_mockDeviceId); QVariantMap validActionEventBasedParam1; - validActionEventBasedParam1.insert("name", "mockActionParam1"); + validActionEventBasedParam1.insert("paramTypeId", mockActionParam1ParamTypeId); validActionEventBasedParam1.insert("eventTypeId", mockEvent2Id); - validActionEventBasedParam1.insert("eventParamName", "mockParamInt"); + validActionEventBasedParam1.insert("eventParamTypeId", mockParamIntParamTypeId); QVariantMap validActionEventBasedParam2; - validActionEventBasedParam2.insert("name", "mockActionParam2"); + validActionEventBasedParam2.insert("paramTypeId", mockActionParam2ParamTypeId); validActionEventBasedParam2.insert("value", false); validActionEventBased.insert("ruleActionParams", QVariantList() << validActionEventBasedParam1 << validActionEventBasedParam2); @@ -949,7 +942,7 @@ void TestRules::loadStoreConfig() eventDescriptor2.insert("paramDescriptors", QVariantList()); QVariantList eventParamDescriptors; QVariantMap eventParam1; - eventParam1.insert("name", "mockParamInt"); + eventParam1.insert("paramTypeId", mockParamIntParamTypeId); eventParam1.insert("value", 3); eventParam1.insert("operator", JsonTypes::valueOperatorToString(Types::ValueOperatorEquals)); eventParamDescriptors.append(eventParam1); @@ -997,11 +990,11 @@ void TestRules::loadStoreConfig() action2.insert("deviceId", m_mockDeviceId); QVariantList action2Params; QVariantMap action2Param1; - action2Param1.insert("name", "mockActionParam1"); + action2Param1.insert("paramTypeId", mockActionParam1ParamTypeId); action2Param1.insert("value", 5); action2Params.append(action2Param1); QVariantMap action2Param2; - action2Param2.insert("name", "mockActionParam2"); + action2Param2.insert("paramTypeId", mockActionParam2ParamTypeId); action2Param2.insert("value", true); action2Params.append(action2Param2); action2.insert("ruleActionParams", action2Params); @@ -1011,11 +1004,11 @@ void TestRules::loadStoreConfig() validActionEventBased.insert("actionTypeId", mockActionIdWithParams); validActionEventBased.insert("deviceId", m_mockDeviceId); QVariantMap validActionEventBasedParam1; - validActionEventBasedParam1.insert("name", "mockActionParam1"); + validActionEventBasedParam1.insert("paramTypeId", mockActionParam1ParamTypeId); validActionEventBasedParam1.insert("eventTypeId", mockEvent2Id); - validActionEventBasedParam1.insert("eventParamName", "mockParamInt"); + validActionEventBasedParam1.insert("eventParamTypeId", mockParamIntParamTypeId); QVariantMap validActionEventBasedParam2; - validActionEventBasedParam2.insert("name", "mockActionParam2"); + validActionEventBasedParam2.insert("paramTypeId", mockActionParam2ParamTypeId); validActionEventBasedParam2.insert("value", false); validActionEventBased.insert("ruleActionParams", QVariantList() << validActionEventBasedParam1 << validActionEventBasedParam2); @@ -1067,11 +1060,14 @@ void TestRules::loadStoreConfig() RuleId newRuleId3 = RuleId(response3.toMap().value("params").toMap().value("ruleId").toString()); verifyRuleError(response3); + response = injectAndWait("Rules.GetRules"); + QVariantList rules = response.toMap().value("params").toMap().value("ruleDescriptions").toList(); + qDebug() << response; + restartServer(); response = injectAndWait("Rules.GetRules"); - - QVariantList rules = response.toMap().value("params").toMap().value("ruleDescriptions").toList(); + rules = response.toMap().value("params").toMap().value("ruleDescriptions").toList(); QVERIFY2(rules.count() == 3, "There should be exactly three rule."); @@ -1100,6 +1096,7 @@ void TestRules::loadStoreConfig() if (expectedEventDescriptorVariant.toMap().value("eventTypeId") == replyEventDescriptorVariant.toMap().value("eventTypeId") && expectedEventDescriptorVariant.toMap().value("deviceId") == replyEventDescriptorVariant.toMap().value("deviceId")) { found = true; + qDebug() << endl << replyEventDescriptorVariant << endl << expectedEventDescriptorVariant; QVERIFY2(replyEventDescriptorVariant == expectedEventDescriptorVariant, "EventDescriptor doesn't match"); } } @@ -1128,11 +1125,13 @@ void TestRules::loadStoreConfig() if (actionVariant.toMap().value("actionTypeId") == replyActionVariant.toMap().value("actionTypeId") && actionVariant.toMap().value("deviceId") == replyActionVariant.toMap().value("deviceId")) { found = true; - QJsonDocument bDoc = QJsonDocument::fromVariant(actionVariant); - QString bString = bDoc.toJson(); - QJsonDocument aDoc = QJsonDocument::fromVariant(replyActionVariant); - QString aString = aDoc.toJson(); - QVERIFY2(actionVariant == replyActionVariant, QString("Action doesn't match after loading from config.\nBefore storing: %1\nAfter storing:%2").arg(bString).arg(aString).toUtf8().data()); + // Check rule action params + QVariantList actionParams = actionVariant.toMap().value("ruleActionParams").toList(); + QVariantList replyActionParams = replyActionVariant.toMap().value("ruleActionParams").toList(); + QVERIFY2(actionParams.count() == replyActionParams.count(), "Not the same list size of action params"); + foreach (const QVariant &ruleParam, actionParams) { + QVERIFY(replyActionParams.contains(ruleParam)); + } } } QVERIFY2(found, "Action not found after loading from config."); @@ -1167,11 +1166,13 @@ void TestRules::loadStoreConfig() if (actionVariant.toMap().value("actionTypeId") == replyActionVariant.toMap().value("actionTypeId") && actionVariant.toMap().value("deviceId") == replyActionVariant.toMap().value("deviceId")) { found = true; - QJsonDocument bDoc = QJsonDocument::fromVariant(actionVariant); - QString bString = bDoc.toJson(); - QJsonDocument aDoc = QJsonDocument::fromVariant(replyActionVariant); - QString aString = aDoc.toJson(); - QVERIFY2(actionVariant == replyActionVariant, QString("Action doesn't match after loading from config.\nBefore storing: %1\nAfter storing:%2").arg(bString).arg(aString).toUtf8().data()); + // Check rule action params + QVariantList actionParams = actionVariant.toMap().value("ruleActionParams").toList(); + QVariantList replyActionParams = replyActionVariant.toMap().value("ruleActionParams").toList(); + QVERIFY2(actionParams.count() == replyActionParams.count(), "Not the same list size of action params"); + foreach (const QVariant &ruleParam, actionParams) { + QVERIFY(replyActionParams.contains(ruleParam)); + } } } QVERIFY2(found, "Action not found after loading from config."); @@ -1185,11 +1186,13 @@ void TestRules::loadStoreConfig() if (exitActionVariant.toMap().value("actionTypeId") == replyActionVariant.toMap().value("actionTypeId") && exitActionVariant.toMap().value("deviceId") == replyActionVariant.toMap().value("deviceId")) { found = true; - QJsonDocument bDoc = QJsonDocument::fromVariant(exitActionVariant); - QString bString = bDoc.toJson(); - QJsonDocument aDoc = QJsonDocument::fromVariant(replyActionVariant); - QString aString = aDoc.toJson(); - QVERIFY2(exitActionVariant == replyActionVariant, QString("Action doesn't match after loading from config.\nBefore storing: %1\nAfter storing:%2").arg(bString).arg(aString).toUtf8().data()); + // Check rule action params + QVariantList actionParams = exitActionVariant.toMap().value("ruleActionParams").toList(); + QVariantList replyActionParams = replyActionVariant.toMap().value("ruleActionParams").toList(); + QVERIFY2(actionParams.count() == replyActionParams.count(), "Not the same list size of action params"); + foreach (const QVariant &ruleParam, actionParams) { + QVERIFY(replyActionParams.contains(ruleParam)); + } } } QVERIFY2(found, "Exit Action not found after loading from config."); @@ -1222,11 +1225,13 @@ void TestRules::loadStoreConfig() if (actionVariant.toMap().value("actionTypeId") == replyActionVariant.toMap().value("actionTypeId") && actionVariant.toMap().value("deviceId") == replyActionVariant.toMap().value("deviceId")) { found = true; - QJsonDocument bDoc = QJsonDocument::fromVariant(actionVariant); - QString bString = bDoc.toJson(); - QJsonDocument aDoc = QJsonDocument::fromVariant(replyActionVariant); - QString aString = aDoc.toJson(); - QVERIFY2(actionVariant == replyActionVariant, QString("Action doesn't match after loading from config.\nBefore storing: %1\nAfter storing:%2").arg(bString).arg(aString).toUtf8().data()); + // Check rule action params + QVariantList actionParams = actionVariant.toMap().value("ruleActionParams").toList(); + QVariantList replyActionParams = replyActionVariant.toMap().value("ruleActionParams").toList(); + QVERIFY2(actionParams.count() == replyActionParams.count(), "Not the same list size of action params"); + foreach (const QVariant &ruleParam, actionParams) { + QVERIFY(replyActionParams.contains(ruleParam)); + } } } QVERIFY2(found, "Action not found after loading from config."); @@ -1559,11 +1564,11 @@ void TestRules::testEventBasedAction() QVariantMap action; QVariantList ruleActionParams; QVariantMap param1; - param1.insert("name", "mockActionParam1"); + param1.insert("paramTypeId", mockActionParam1ParamTypeId); param1.insert("eventTypeId", mockIntStateId); - param1.insert("eventParamName", "value"); + param1.insert("eventParamTypeId", mockIntStateId); QVariantMap param2; - param2.insert("name", "mockActionParam2"); + param2.insert("paramTypeId", mockActionParam2ParamTypeId); param2.insert("value", true); ruleActionParams.append(param1); ruleActionParams.append(param2); @@ -1755,10 +1760,10 @@ void TestRules::testRuleActionParams_data() QVariantMap action; QVariantList ruleActionParams; QVariantMap param1; - param1.insert("name", "mockActionParam1"); + param1.insert("paramTypeId", mockActionParam1ParamTypeId); param1.insert("value", 4); QVariantMap param2; - param2.insert("name", "mockActionParam2"); + param2.insert("paramTypeId", mockActionParam2ParamTypeId); param2.insert("value", true); ruleActionParams.append(param1); ruleActionParams.append(param2);