Skip to content

Commit

Permalink
Fix TestGroupMessaging test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Dec 19, 2021
1 parent 7fb48ab commit 704cb2e
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 45 deletions.
89 changes: 89 additions & 0 deletions src/app/clusters/basic/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,98 @@ using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::Basic;
using namespace chip::app::Clusters::Basic::Attributes;
using namespace chip::DeviceLayer;

namespace {

class BasicAttrAccess : public AttributeAccessInterface
{
public:
// Register for the Basic cluster on all endpoints.
BasicAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), Basic::Id) {}

CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override;

private:
CHIP_ERROR ReadLocation(AttributeValueEncoder & aEncoder);
CHIP_ERROR WriteLocation(AttributeValueDecoder & aDecoder);
};

BasicAttrAccess gAttrAccess;

CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
if (aPath.mClusterId != Basic::Id)
{
// We shouldn't have been called at all.
return CHIP_ERROR_INVALID_ARGUMENT;
}

switch (aPath.mAttributeId)
{
case Location::Id:
return ReadLocation(aEncoder);
default:
break;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR BasicAttrAccess::ReadLocation(AttributeValueEncoder & aEncoder)
{
CHIP_ERROR err = CHIP_NO_ERROR;

char location[DeviceLayer::ConfigurationManager::kMaxLocationLength + 1];
size_t codeLen = 0;

if (ConfigurationMgr().GetCountryCode(location, sizeof(location), codeLen) == CHIP_NO_ERROR)
{
if (codeLen == 0)
{
err = aEncoder.Encode(chip::CharSpan("XX", strlen("XX")));
}
else
{
err = aEncoder.Encode(chip::CharSpan(location, strlen(location)));
}
}
else
{
err = aEncoder.Encode(chip::CharSpan("XX", strlen("XX")));
}

return err;
}

CHIP_ERROR BasicAttrAccess::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder)
{
VerifyOrDie(aPath.mClusterId == Basic::Id);

switch (aPath.mAttributeId)
{
case Location::Id:
return WriteLocation(aDecoder);
default:
break;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR BasicAttrAccess::WriteLocation(AttributeValueDecoder & aDecoder)
{
chip::CharSpan location;

ReturnErrorOnFailure(aDecoder.Decode(location));
VerifyOrReturnError(location.size() <= DeviceLayer::ConfigurationManager::kMaxLocationLength,
CHIP_ERROR_INVALID_MESSAGE_LENGTH);

return DeviceLayer::ConfigurationMgr().StoreCountryCode(location.data(), location.size());
}

class PlatformMgrDelegate : public DeviceLayer::PlatformManagerDelegate
{
// Gets called by the current Node after completing a boot or reboot process.
Expand Down Expand Up @@ -232,5 +320,6 @@ void emberAfBasicClusterServerInitCallback(chip::EndpointId endpoint)

void MatterBasicPluginServerInitCallback()
{
registerAttributeAccessOverride(&gAttrAccess);
PlatformMgr().SetDelegate(&gPlatformMgrDelegate);
}
6 changes: 2 additions & 4 deletions src/app/tests/suites/TestBasicInformation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ tests:
- label: "Wait for the commissioned device to be retrieved"
cluster: "DelayCommands"
command: "WaitForCommissionee"
#Disabled due to issue-12983

- label: "Read location"
disabled: true
command: "readAttribute"
attribute: "location"
response:
Expand All @@ -35,9 +34,8 @@ tests:
attribute: "location"
arguments:
value: "us"
#Disabled due to issue-12983

- label: "Read back location"
disabled: true
command: "readAttribute"
attribute: "location"
response:
Expand Down
8 changes: 3 additions & 5 deletions src/app/tests/suites/TestGroupMessaging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ tests:
groupId: "1234"
arguments:
value: "us"
#Disabled due to issue-12983

- label: "Read back Attribute"
disabled: true
command: "readAttribute"
attribute: "location"
response:
Expand All @@ -47,13 +46,12 @@ tests:
groupId: "1234"
arguments:
value: ""
#Disabled due to issue-12983

- label: "Read back Attribute"
disabled: true
command: "readAttribute"
attribute: "location"
response:
value: ""
value: "XX"

- label: "Turn On the light to see attribute change"
cluster: "On/Off"
Expand Down
54 changes: 51 additions & 3 deletions src/darwin/Framework/CHIPTests/CHIPClustersTests.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 704cb2e

Please sign in to comment.