-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[YAML] Make some partials for checking the constraints and saving val…
…ues (#15414) * Use an helper instead of multiple inline partials for determining the name of the property for the maybeCheckExpectedValue,maybeCheckExpectedContraints,maybeSaveAs partials * [YAML] Move template saveAs blocks into dedicated partials * [YAML] Move template blocks used to check the response content into dedicated partials * Allow digits into the isUpperCase constraint * Update generated content
- Loading branch information
1 parent
df88ca4
commit 70ae428
Showing
13 changed files
with
448 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
examples/chip-tool/templates/tests/partials/checks/maybeCheckExpectedConstraints.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{{#if hasExpectedConstraints}} | ||
{{#if isOptional}} | ||
VerifyOrReturn(CheckValuePresent("{{asPropertyValue dontUnwrapValue=true}}", {{asPropertyValue dontUnwrapValue=true}})); | ||
{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "type")}}VerifyOrReturn(CheckConstraintType("{{asPropertyValue}}", "", "{{expectedConstraints.type}}"));{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "format")}}VerifyOrReturn(CheckConstraintFormat("{{asPropertyValue}}", "", "{{expectedConstraints.format}}"));{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "startsWith")}}VerifyOrReturn(CheckConstraintStartsWith("{{asPropertyValue}}", {{asPropertyValue}}, "{{expectedConstraints.startsWith}}"));{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "endsWith")}}VerifyOrReturn(CheckConstraintEndsWith("{{asPropertyValue}}", {{asPropertyValue}}, "{{expectedConstraints.endsWith}}"));{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "isUpperCase")}}VerifyOrReturn(CheckConstraintIsUpperCase("{{asPropertyValue}}", {{asPropertyValue}}, {{expectedConstraints.isUpperCase}}));{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "isLowerCase")}}VerifyOrReturn(CheckConstraintIsLowerCase("{{asPropertyValue}}", {{asPropertyValue}}, {{expectedConstraints.isLowerCase}}));{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "isHexString")}}VerifyOrReturn(CheckConstraintIsHexString("{{asPropertyValue}}", {{asPropertyValue}}, {{expectedConstraints.isHexString}}));{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "minLength")}}VerifyOrReturn(CheckConstraintMinLength("{{asPropertyValue}}", {{asPropertyValue}}.size(), {{expectedConstraints.minLength}}));{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "maxLength")}}VerifyOrReturn(CheckConstraintMaxLength("{{asPropertyValue}}", {{asPropertyValue}}.size(), {{expectedConstraints.maxLength}}));{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "minValue")}}VerifyOrReturn(CheckConstraintMinValue<{{chipType}}>("{{asPropertyValue}}", {{asPropertyValue}}, {{asTypedLiteral expectedConstraints.minValue type}}));{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "maxValue")}}VerifyOrReturn(CheckConstraintMaxValue<{{chipType}}>("{{asPropertyValue}}", {{asPropertyValue}}, {{asTypedLiteral expectedConstraints.maxValue type}}));{{/if}} | ||
|
||
{{~#if (hasProperty expectedConstraints "notValue")}} | ||
{{#if (isLiteralNull expectedConstraints.notValue)}} | ||
VerifyOrReturn(CheckValueNonNull("{{asPropertyValue}}", {{asPropertyValue}})); | ||
{{else}} | ||
VerifyOrReturn(CheckConstraintNotValue("{{asPropertyValue}}", {{asPropertyValue}}, {{asTypedLiteral expectedConstraints.notValue type}})); | ||
{{/if}} | ||
{{/if}} | ||
{{/if}} | ||
|
3 changes: 3 additions & 0 deletions
3
examples/chip-tool/templates/tests/partials/checks/maybeCheckExpectedValue.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{~#if hasExpectedValue}} | ||
{{~>valueEquals actual=(asPropertyValue dontUnwrapValue=true) label=(asLowerCamelCase name) expected=expectedValue depth=0~}} | ||
{{~/if~}} |
13 changes: 13 additions & 0 deletions
13
examples/chip-tool/templates/tests/partials/saveAs/maybeSaveAs.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{{#if saveAs}} | ||
{{#if (isString type)}} | ||
if ({{saveAs}}Buffer != nullptr) | ||
{ | ||
chip::Platform::MemoryFree({{saveAs}}Buffer); | ||
} | ||
{{saveAs}}Buffer = static_cast<{{#if (isOctetString type)}}uint8_t{{else}}char{{/if}} *>(chip::Platform::MemoryAlloc({{asPropertyValue}}.size())); | ||
memcpy({{saveAs}}Buffer, {{asPropertyValue}}.data(), {{asPropertyValue}}.size()); | ||
{{saveAs}} = {{chipType}}({{saveAs}}Buffer, {{asPropertyValue}}.size()); | ||
{{else}} | ||
{{saveAs}} = {{asPropertyValue}}; | ||
{{/if}} | ||
{{/if}} |
10 changes: 10 additions & 0 deletions
10
examples/chip-tool/templates/tests/partials/saveAs/setupSaveAs.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{{#chip_tests_items}} | ||
{{#chip_tests_item_response_parameters}} | ||
{{#if saveAs}} | ||
{{~#if (isString type)}} | ||
{{#if (isOctetString type)}}uint8_t{{else}}char{{/if}} * {{saveAs}}Buffer = nullptr; | ||
{{/if~}} | ||
{{zapTypeToDecodableClusterObjectType type ns=../cluster}} {{saveAs}}; | ||
{{/if}} | ||
{{/chip_tests_item_response_parameters}} | ||
{{/chip_tests_items}} |
13 changes: 13 additions & 0 deletions
13
examples/chip-tool/templates/tests/partials/saveAs/teardownSaveAs.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{{#chip_tests_items}} | ||
{{#chip_tests_item_response_parameters}} | ||
{{#if saveAs}} | ||
{{#if (isString type)}} | ||
if ({{saveAs}}Buffer != nullptr) | ||
{ | ||
chip::Platform::MemoryFree({{saveAs}}Buffer); | ||
{{saveAs}}Buffer = nullptr; | ||
} | ||
{{/if}} | ||
{{/if}} | ||
{{/chip_tests_item_response_parameters}} | ||
{{/chip_tests_items}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.