Skip to content

Commit

Permalink
[Tests] Add tests to TestCluster.yaml for unsupported attributes, lon…
Browse files Browse the repository at this point in the history
…g octet string and lists. (project-chip#7741)

* Update src/app/util to not use uint8_t for emAfSend and update encoder-src.zapt template to put the right size when writing an attribute

* Add LONG_OCTET_STRING to TestCluster and an attribute that is not supported on the server side

* Add a test for unsupported attributes and a test for LONG_OCTET_STRING

* Update templates and src/app/clusters/test-cluster-server

* Add an helper for c++ literal suffix

* Update gen/ folders
  • Loading branch information
vivien-apple authored and Nikita committed Sep 23, 2021
1 parent 5593b7f commit c85d975
Show file tree
Hide file tree
Showing 26 changed files with 1,719 additions and 761 deletions.
19 changes: 17 additions & 2 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"featureLevel": 35,
"featureLevel": 39,
"creator": "zap",
"keyValuePairs": [
{
Expand Down Expand Up @@ -12309,6 +12309,21 @@
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "long_octet_string",
"code": 29,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "cluster revision",
"code": 65533,
Expand Down Expand Up @@ -15539,4 +15554,4 @@
}
],
"log": []
}
}
132 changes: 122 additions & 10 deletions examples/all-clusters-app/all-clusters-common/gen/endpoint_config.h

Large diffs are not rendered by default.

140 changes: 140 additions & 0 deletions examples/chip-tool/commands/clusters/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -15358,6 +15358,8 @@ class ReadTemperatureMeasurementClusterRevision : public ModelCommand
| * ListInt8u | 0x001A |
| * ListOctetString | 0x001B |
| * ListStructOctetString | 0x001C |
| * LongOctetString | 0x001D |
| * Unsupported | 0x00FF |
| * ClusterRevision | 0xFFFD |
\*----------------------------------------------------------------------------*/

Expand Down Expand Up @@ -16684,6 +16686,140 @@ class ReadTestClusterListStructOctetString : public ModelCommand
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};

/*
* Attribute LongOctetString
*/
class ReadTestClusterLongOctetString : public ModelCommand
{
public:
ReadTestClusterLongOctetString() : ModelCommand("read")
{
AddArgument("attr-name", "long-octet-string");
ModelCommand::AddArguments();
}

~ReadTestClusterLongOctetString()
{
delete onSuccessCallback;
delete onFailureCallback;
}

CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster (0x050F) command (0x00) on endpoint %" PRIu16, endpointId);

chip::Controller::TestClusterCluster cluster;
cluster.Associate(device, endpointId);
return cluster.ReadAttributeLongOctetString(onSuccessCallback->Cancel(), onFailureCallback->Cancel());
}

private:
chip::Callback::Callback<StringAttributeCallback> * onSuccessCallback =
new chip::Callback::Callback<StringAttributeCallback>(OnStringAttributeResponse, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback =
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};

class WriteTestClusterLongOctetString : public ModelCommand
{
public:
WriteTestClusterLongOctetString() : ModelCommand("write")
{
AddArgument("attr-name", "long-octet-string");
AddArgument("attr-value", &mValue);
ModelCommand::AddArguments();
}

~WriteTestClusterLongOctetString()
{
delete onSuccessCallback;
delete onFailureCallback;
}

CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster (0x050F) command (0x01) on endpoint %" PRIu16, endpointId);

chip::Controller::TestClusterCluster cluster;
cluster.Associate(device, endpointId);
return cluster.WriteAttributeLongOctetString(onSuccessCallback->Cancel(), onFailureCallback->Cancel(), mValue);
}

private:
chip::Callback::Callback<DefaultSuccessCallback> * onSuccessCallback =
new chip::Callback::Callback<DefaultSuccessCallback>(OnDefaultSuccessResponse, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback =
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
chip::ByteSpan mValue;
};

/*
* Attribute Unsupported
*/
class ReadTestClusterUnsupported : public ModelCommand
{
public:
ReadTestClusterUnsupported() : ModelCommand("read")
{
AddArgument("attr-name", "unsupported");
ModelCommand::AddArguments();
}

~ReadTestClusterUnsupported()
{
delete onSuccessCallback;
delete onFailureCallback;
}

CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster (0x050F) command (0x00) on endpoint %" PRIu16, endpointId);

chip::Controller::TestClusterCluster cluster;
cluster.Associate(device, endpointId);
return cluster.ReadAttributeUnsupported(onSuccessCallback->Cancel(), onFailureCallback->Cancel());
}

private:
chip::Callback::Callback<BooleanAttributeCallback> * onSuccessCallback =
new chip::Callback::Callback<BooleanAttributeCallback>(OnBooleanAttributeResponse, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback =
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};

class WriteTestClusterUnsupported : public ModelCommand
{
public:
WriteTestClusterUnsupported() : ModelCommand("write")
{
AddArgument("attr-name", "unsupported");
AddArgument("attr-value", 0, UINT8_MAX, &mValue);
ModelCommand::AddArguments();
}

~WriteTestClusterUnsupported()
{
delete onSuccessCallback;
delete onFailureCallback;
}

CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster (0x050F) command (0x01) on endpoint %" PRIu16, endpointId);

chip::Controller::TestClusterCluster cluster;
cluster.Associate(device, endpointId);
return cluster.WriteAttributeUnsupported(onSuccessCallback->Cancel(), onFailureCallback->Cancel(), mValue);
}

private:
chip::Callback::Callback<DefaultSuccessCallback> * onSuccessCallback =
new chip::Callback::Callback<DefaultSuccessCallback>(OnDefaultSuccessResponse, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback =
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
uint8_t mValue;
};

/*
* Attribute ClusterRevision
*/
Expand Down Expand Up @@ -21178,6 +21314,10 @@ void registerClusterTestCluster(Commands & commands)
make_unique<ReadTestClusterListInt8u>(),
make_unique<ReadTestClusterListOctetString>(),
make_unique<ReadTestClusterListStructOctetString>(),
make_unique<ReadTestClusterLongOctetString>(),
make_unique<WriteTestClusterLongOctetString>(),
make_unique<ReadTestClusterUnsupported>(),
make_unique<WriteTestClusterUnsupported>(),
make_unique<ReadTestClusterClusterRevision>(),
};

Expand Down
Loading

0 comments on commit c85d975

Please sign in to comment.