Skip to content

Commit

Permalink
Fix incorrect GetClusterId() in cluster-objects. (#11019)
Browse files Browse the repository at this point in the history
If the name of a cluster happens to overlap with the name of some
other construct (e.g. a command), we can get the wrong ids like so:

    static constexpr CommandId GetCommandId() { return Identify::Id; }
    static constexpr ClusterId GetClusterId() { return Identify::Id; }

The solution, for now, is to prefix with Cluster:: and Command:: as needed.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Oct 27, 2021
1 parent f8d0743 commit d68a5b9
Show file tree
Hide file tree
Showing 7 changed files with 1,633 additions and 1,504 deletions.
1 change: 1 addition & 0 deletions examples/chip-tool/templates/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function getTests()
'TestLogCommands',
'TestDescriptorCluster',
'TestBasicInformation',
'TestIdentifyCluster',
'TestOperationalCredentialsCluster',
];

Expand Down
27 changes: 27 additions & 0 deletions src/app/tests/suites/TestIdentifyCluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Identify Cluster Tests

config:
cluster: "Identify"
endpoint: 0

tests:
- label: "Send Identify command and expect success response"
command: "identify"
arguments:
values:
- name: "IdentifyTime"
value: 0
12 changes: 6 additions & 6 deletions src/app/zap-templates/templates/app/cluster-objects.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ struct Type
{
public:
// Use GetCommandId instead of commandId directly to avoid naming conflict with CommandIdentification in ExecutionOfACommand
static constexpr CommandId GetCommandId() { return {{asUpperCamelCase name}}::Id; }
static constexpr ClusterId GetClusterId() { return {{asUpperCamelCase parent.name}}::Id; }
static constexpr CommandId GetCommandId() { return Commands::{{asUpperCamelCase name}}::Id; }
static constexpr ClusterId GetClusterId() { return Clusters::{{asUpperCamelCase parent.name}}::Id; }

{{#zcl_command_arguments}}
{{zapTypeToEncodableClusterObjectType type}} {{asLowerCamelCase label}};
Expand All @@ -114,8 +114,8 @@ public:

struct DecodableType {
public:
static constexpr CommandId GetCommandId() { return {{asUpperCamelCase name}}::Id; }
static constexpr ClusterId GetClusterId() { return {{asUpperCamelCase parent.name}}::Id; }
static constexpr CommandId GetCommandId() { return Commands::{{asUpperCamelCase name}}::Id; }
static constexpr ClusterId GetClusterId() { return Clusters::{{asUpperCamelCase parent.name}}::Id; }

{{#zcl_command_arguments}}
{{zapTypeToDecodableClusterObjectType type}} {{asLowerCamelCase label}};
Expand Down Expand Up @@ -171,7 +171,7 @@ struct Type
public:
static constexpr PriorityLevel priorityLevel = PriorityLevel::{{asUpperCamelCase priority}};
static constexpr EventId eventId = {{asMEI manufacturerCode code}};
static constexpr ClusterId GetClusterId() { return {{asUpperCamelCase parent.name}}::Id; }
static constexpr ClusterId GetClusterId() { return Clusters::{{asUpperCamelCase parent.name}}::Id; }

{{#zcl_event_fields}}
{{zapTypeToEncodableClusterObjectType type}} {{asLowerCamelCase name}};
Expand All @@ -184,7 +184,7 @@ struct DecodableType {
public:
static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; }
static constexpr EventId GetEventId() { return kEventId; }
static constexpr ClusterId GetClusterId() { return {{asUpperCamelCase parent.name}}::Id; }
static constexpr ClusterId GetClusterId() { return Clusters::{{asUpperCamelCase parent.name}}::Id; }

{{#zcl_event_fields}}
{{zapTypeToDecodableClusterObjectType type}} {{asLowerCamelCase name}};
Expand Down
1 change: 1 addition & 0 deletions src/darwin/Framework/CHIP/templates/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function getTests()
'TestDelayCommands',
'TestDescriptorCluster',
'TestBasicInformation',
'TestIdentifyCluster',
'TestOperationalCredentialsCluster',
];

Expand Down
22 changes: 22 additions & 0 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 d68a5b9

Please sign in to comment.