Skip to content

Commit 565b6d4

Browse files
[YAML] Add a constraint to say not equal to some value (#9538)
* [YAML] Add notValue constraints support * Update generated tests * Update examples/chip-tool/templates/partials/test_cluster.zapt * Regenerate generated file Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent fce8561 commit 565b6d4

File tree

7 files changed

+436
-2
lines changed

7 files changed

+436
-2
lines changed

examples/chip-tool/templates/partials/test_cluster.zapt

+9
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ class {{filename}}: public TestCommand
197197
return;
198198
}
199199
{{/if}}
200+
201+
{{#if expectedConstraints.notValue}}
202+
if ({{asLowerCamelCase name}} == {{expectedConstraints.notValue}})
203+
{
204+
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} was not expected to be '{{expectedConstraints.notValue}}' due to notValue constraint");
205+
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
206+
return;
207+
}
208+
{{/if}}
200209
{{/if}}
201210
{{/chip_tests_item_response_parameters}}
202211

examples/chip-tool/templates/tests-commands.zapt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
#include <commands/tests/TestCommand.h>
66

7-
{{>test_cluster tests="TV_TargetNavigatorCluster, TV_AudioOutputCluster, TV_ApplicationLauncherCluster, TV_KeypadInputCluster, TV_AccountLoginCluster, TV_WakeOnLanCluster, TV_ApplicationBasicCluster, TV_MediaPlaybackCluster, TV_TvChannelCluster, TV_LowPowerCluster, TV_MediaInputCluster, TestCluster, TestDelayCommands, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_CC_8, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1, Test_TC_FLW_1_1, Test_TC_TM_1_1, Test_TC_OCC_1_1, OperationalCredentialsCluster"}}
7+
{{>test_cluster tests="TV_TargetNavigatorCluster, TV_AudioOutputCluster, TV_ApplicationLauncherCluster, TV_KeypadInputCluster, TV_AccountLoginCluster, TV_WakeOnLanCluster, TV_ApplicationBasicCluster, TV_MediaPlaybackCluster, TV_TvChannelCluster, TV_LowPowerCluster, TV_MediaInputCluster, TestCluster, TestConstraints, TestDelayCommands, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_CC_8, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1, Test_TC_FLW_1_1, Test_TC_TM_1_1, Test_TC_OCC_1_1, OperationalCredentialsCluster"}}
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) 2021 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Test Cluster Constraints Tests
16+
17+
config:
18+
cluster: "Test Cluster"
19+
endpoint: 1
20+
21+
tests:
22+
# Tests for UInt32 attribute
23+
24+
- label: "Write attribute INT32U Value"
25+
command: "writeAttribute"
26+
attribute: "int32u"
27+
arguments:
28+
value: 5
29+
30+
- label: "Read attribute INT32U Value MinValue Constraints"
31+
command: "readAttribute"
32+
attribute: "int32u"
33+
response:
34+
constraints:
35+
minValue: 5
36+
37+
- label: "Read attribute INT32U Value MaxValue Constraints"
38+
command: "readAttribute"
39+
attribute: "int32u"
40+
response:
41+
constraints:
42+
maxValue: 5
43+
44+
- label: "Read attribute INT32U Value NotValue Constraints"
45+
command: "readAttribute"
46+
attribute: "int32u"
47+
response:
48+
constraints:
49+
notValue: 6

src/darwin/Framework/CHIP/templates/clusters-tests.zapt

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ CHIPDevice * GetPairedDevice(uint64_t deviceId)
215215
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
216216
}
217217

218-
{{>test_cluster tests="TestCluster, TestDelayCommands, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_CC_8, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1, Test_TC_FLW_1_1, Test_TC_TM_1_1, Test_TC_OCC_1_1, OperationalCredentialsCluster"}}
218+
{{>test_cluster tests="TestCluster, TestConstraints, TestDelayCommands, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_CC_8, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1, Test_TC_FLW_1_1, Test_TC_TM_1_1, Test_TC_OCC_1_1, OperationalCredentialsCluster"}}
219219

220220
{{#chip_client_clusters}}
221221
{{#unless (isStrEqual "Test Cluster" name)}}

src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
{{#if expectedConstraints.maxValue}}
8080
XCTAssertLessThanOrEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedConstraints.maxValue}});
8181
{{/if}}
82+
{{#if expectedConstraints.notValue}}
83+
XCTAssertNotEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedConstraints.notValue}});
84+
{{/if}}
8285
{{/if}}
8386
{{/chip_tests_item_response_parameters}}
8487
[expectation fulfill];

src/darwin/Framework/CHIPTests/CHIPClustersTests.m

+74
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)