convert ActionType to use ParamType instead of variants,
extend tests
This commit is contained in:
parent
b5d77460c0
commit
df001695a1
@ -343,6 +343,8 @@ DeviceManager::DeviceError DeviceManager::executeAction(const Action &action)
|
||||
if (actionType.id() == action.actionTypeId()) {
|
||||
found = true;
|
||||
|
||||
qDebug() << "checking params" << actionType.parameters().count() << action.params().count();
|
||||
qDebug() << "action params:" << action.params();
|
||||
if (actionType.parameters().count() > action.params().count()) {
|
||||
return DeviceErrorMissingParameter;
|
||||
}
|
||||
|
||||
@ -59,14 +59,14 @@ void ActionType::setName(const QString &name)
|
||||
|
||||
/*! Returns the parameter description of this ActionType. \l{Action}{Actions} created
|
||||
from this ActionType must have their parameters matching to this template. */
|
||||
QVariantList ActionType::parameters() const
|
||||
QList<ParamType> ActionType::parameters() const
|
||||
{
|
||||
return m_parameters;
|
||||
}
|
||||
|
||||
/*! Set the parameter description of this ActionType. \l{Action}{Actions} created
|
||||
from this ActionType must have their \a parameters matching to this template. */
|
||||
void ActionType::setParameters(const QVariantList ¶meters)
|
||||
void ActionType::setParameters(const QList<ParamType> ¶meters)
|
||||
{
|
||||
m_parameters = parameters;
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#define ACTIONTYPE_H
|
||||
|
||||
#include "typeutils.h"
|
||||
#include "paramtype.h"
|
||||
|
||||
#include <QVariantList>
|
||||
|
||||
@ -33,14 +34,14 @@ public:
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
QVariantList parameters() const;
|
||||
void setParameters(const QVariantList ¶meters);
|
||||
QList<ParamType> parameters() const;
|
||||
void setParameters(const QList<ParamType> ¶meters);
|
||||
|
||||
private:
|
||||
ActionTypeId m_id;
|
||||
QString m_name;
|
||||
|
||||
QVariantList m_parameters;
|
||||
QList<ParamType> m_parameters;
|
||||
};
|
||||
|
||||
#endif // ACTIONTYPE_H
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
class Param
|
||||
{
|
||||
public:
|
||||
Param(const QString &name, const QVariant &value = QVariant());
|
||||
Param(const QString &name = QString(), const QVariant &value = QVariant());
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
@ -40,6 +40,7 @@ private:
|
||||
QVariant m_value;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(Param)
|
||||
QDebug operator<<(QDebug dbg, const Param ¶m);
|
||||
QDebug operator<<(QDebug dbg, const QList<Param> ¶ms);
|
||||
|
||||
|
||||
@ -74,10 +74,8 @@ QList<DeviceClass> DevicePluginBoblight::supportedDevices() const
|
||||
ActionType setColorAction(setColorActionTypeId);
|
||||
setColorAction.setName("Set color");
|
||||
|
||||
QVariantList actionParamsSetColor;
|
||||
QVariantMap actionParamSetColor;
|
||||
actionParamSetColor.insert("name", "color");
|
||||
actionParamSetColor.insert("type", "color");
|
||||
QList<ParamType> actionParamsSetColor;
|
||||
ParamType actionParamSetColor("color", QVariant::Color);
|
||||
actionParamsSetColor.append(actionParamSetColor);
|
||||
setColorAction.setParameters(actionParamsSetColor);
|
||||
|
||||
|
||||
@ -187,10 +187,8 @@ QList<DeviceClass> DevicePluginElro::supportedDevices() const
|
||||
deviceClassElroSwitch.setParams(deviceParamsSwitch);
|
||||
|
||||
|
||||
QVariantList actionParamsSwitch;
|
||||
QVariantMap actionParamSwitch;
|
||||
actionParamSwitch.insert("name", "power");
|
||||
actionParamSwitch.insert("type", "bool");
|
||||
QList<ParamType> actionParamsSwitch;
|
||||
ParamType actionParamSwitch("power", QVariant::Bool);
|
||||
actionParamsSwitch.append(actionParamSwitch);
|
||||
|
||||
QList<ActionType> switchActions;
|
||||
|
||||
@ -185,15 +185,11 @@ QList<DeviceClass> DevicePluginGoogleMail::supportedDevices() const
|
||||
// Actions
|
||||
QList<ActionType> googleMailActions;
|
||||
|
||||
QVariantList actionParamsMail;
|
||||
QVariantMap actionParamSubject;
|
||||
actionParamSubject.insert("name", "subject");
|
||||
actionParamSubject.insert("type", "string");
|
||||
QList<ParamType> actionParamsMail;
|
||||
ParamType actionParamSubject("subject", QVariant::String);
|
||||
actionParamsMail.append(actionParamSubject);
|
||||
|
||||
QVariantMap actionParamBody;
|
||||
actionParamBody.insert("name", "body");
|
||||
actionParamBody.insert("type", "string");
|
||||
ParamType actionParamBody("body", QVariant::String);
|
||||
actionParamsMail.append(actionParamBody);
|
||||
|
||||
ActionType sendMailAction(sendMailActionTypeId);
|
||||
|
||||
@ -318,13 +318,8 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
|
||||
|
||||
QList<ActionType> switchActions;
|
||||
|
||||
QVariantList paramsSwitch;
|
||||
QVariantMap paramSwitch;
|
||||
|
||||
// on = true
|
||||
// off = false
|
||||
paramSwitch.insert("name", "power");
|
||||
paramSwitch.insert("type", "bool");
|
||||
QList<ParamType> paramsSwitch;
|
||||
ParamType paramSwitch("power", QVariant::Bool);
|
||||
paramsSwitch.append(paramSwitch);
|
||||
|
||||
ActionType switchActionPower(ActionTypeId("df19fb51-c3cd-4b95-8d88-ebbb535f4789"));
|
||||
|
||||
@ -90,8 +90,14 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
|
||||
|
||||
QList<ActionType> mockActions;
|
||||
|
||||
mockParams.clear();
|
||||
ActionType action1(mockAction1Id);
|
||||
action1.setName("Mock Action 1");
|
||||
ParamType mockActionParam1("mockActionParam1", QVariant::Int);
|
||||
mockParams.append(mockActionParam1);
|
||||
ParamType mockActionParam2("mockActionParam2", QVariant::Bool);
|
||||
mockParams.append(mockActionParam2);
|
||||
action1.setParameters(mockParams);
|
||||
mockActions.append(action1);
|
||||
|
||||
ActionType action2(mockAction2Id);
|
||||
|
||||
@ -223,7 +223,11 @@ QVariantMap JsonTypes::packActionType(const ActionType &actionType)
|
||||
QVariantMap variantMap;
|
||||
variantMap.insert("id", actionType.id());
|
||||
variantMap.insert("name", actionType.name());
|
||||
variantMap.insert("params", actionType.parameters());
|
||||
QVariantList params;
|
||||
foreach (const ParamType ¶mType, actionType.parameters()) {
|
||||
params.append(packParamType(paramType));
|
||||
}
|
||||
variantMap.insert("params", params);
|
||||
return variantMap;
|
||||
}
|
||||
|
||||
|
||||
@ -326,22 +326,33 @@ void TestJSONRPC::executeAction_data()
|
||||
{
|
||||
QTest::addColumn<DeviceId>("deviceId");
|
||||
QTest::addColumn<ActionTypeId>("actionTypeId");
|
||||
QTest::addColumn<QVariantList>("actionParams");
|
||||
QTest::addColumn<bool>("success");
|
||||
|
||||
QTest::newRow("valid action") << m_mockDeviceId << mockAction1Id << true;
|
||||
QTest::newRow("invalid device TypeId") << DeviceId("f2965936-0dd0-4014-8f31-4c2ef7fc5952") << mockAction1Id << false;
|
||||
QTest::newRow("invalid action TypeId") << m_mockDeviceId << ActionTypeId("f2965936-0dd0-4014-8f31-4c2ef7fc5952") << false;
|
||||
QVariantList params;
|
||||
QVariantMap param1;
|
||||
param1.insert("mockActionParam1", 5);
|
||||
params.append(param1);
|
||||
QVariantMap param2;
|
||||
param2.insert("mockActionParam2", true);
|
||||
params.append(param2);
|
||||
|
||||
QTest::newRow("valid action") << m_mockDeviceId << mockAction1Id << params << true;
|
||||
QTest::newRow("invalid device TypeId") << DeviceId("f2965936-0dd0-4014-8f31-4c2ef7fc5952") << mockAction1Id << params << false;
|
||||
QTest::newRow("invalid action TypeId") << m_mockDeviceId << ActionTypeId("f2965936-0dd0-4014-8f31-4c2ef7fc5952") << params << false;
|
||||
}
|
||||
|
||||
void TestJSONRPC::executeAction()
|
||||
{
|
||||
QFETCH(DeviceId, deviceId);
|
||||
QFETCH(ActionTypeId, actionTypeId);
|
||||
QFETCH(QVariantList, actionParams);
|
||||
QFETCH(bool, success);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("actionTypeId", actionTypeId);
|
||||
params.insert("deviceId", deviceId);
|
||||
params.insert("params", actionParams);
|
||||
QVariant response = injectAndWait("Actions.ExecuteAction", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("success").toBool(), success);
|
||||
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -z $3 ]; then
|
||||
echo "usage: $0 host actionTypeId deviceId [paramname paramvalue]"
|
||||
echo "usage: $0 host actionTypeId deviceId [paramname paramvalue] [paramname paramvalue]"
|
||||
elif [ -z $4 ]; then
|
||||
(echo '{"id":1, "method":"Actions.ExecuteAction","params":{"actionTypeId": "{'$2'}", "deviceId":"{'$3'}"}}'; sleep 1) | nc $1 1234
|
||||
elif [ -z $5 ]; then
|
||||
echo "usage: $0 host actionTypeId deviceId [paramname paramvalue]"
|
||||
echo "usage: $0 host actionTypeId deviceId [paramname paramvalue] [paramname paramvalue]"
|
||||
elif [ -z $6 ]; then
|
||||
(echo '{"id":1, "method":"Actions.ExecuteAction","params":{"actionTypeId": "{'$2'}", "deviceId":"{'$3'}","params":[{"'$4'":"'$5'"}]}}'; sleep 1) | nc $1 1234
|
||||
elif [ -z $7 ]; then
|
||||
echo "usage: $0 host actionTypeId deviceId [paramname paramvalue] [paramname paramvalue]"
|
||||
else
|
||||
(echo '{"id":1, "method":"Actions.ExecuteAction","params":{"actionTypeId": "{'$2'}", "deviceId":"{'$3'}","params":{"'$4'":"'$5'"}}}'; sleep 1) | nc $1 1234
|
||||
(echo '{"id":1, "method":"Actions.ExecuteAction","params":{"actionTypeId": "{'$2'}", "deviceId":"{'$3'}","params":[{"'$4'":"'$5'"}, {"'$6'": "'$7'"}]}}'; sleep 1) | nc $1 1234
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user