Skip to content

Commit

Permalink
Check for not-exactly-representable ints in more places in YAML. (pro…
Browse files Browse the repository at this point in the history
…ject-chip#15228)

Specifically constraints and config variables.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Mar 3, 2022
1 parent 1ac96ad commit 5c63ca8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,8 @@ function chip_tests_item_response_parameters(options)

if ('constraints' in expected) {
responseArg.hasExpectedConstraints = true;
responseArg.expectedConstraints = expected.constraints;
responseArg.expectedConstraints
= attachGlobal(this.global, expected.constraints, { thisVal : this, name : responseArg.name });
}

if ('saveAs' in expected) {
Expand Down
10 changes: 7 additions & 3 deletions src/app/zap-templates/common/variables/Variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ async function extractVariablesFromConfig(context, suite)
}

if (!isKnownVariable && !('defaultValue' in target)) {
throw new Error(`${suite.filename}: No default value defined for config ${key}`);
throw new Error(`${suite.filename}: No default value defined for config '${key}'`);
}

value.defaultValue = isKnownVariable ? suite.config[key] : suite.config[key].defaultValue;
value.chipType = await zclHelper.asUnderlyingZclType.call(context, value.type, { 'hash' : {} });
value.name = key;
if (Number.isInteger(value.defaultValue) && !Number.isSafeInteger(value.defaultValue)) {
throw new Error(`${suite.filename}: Default value defined for config '${
key}' is too large to represent exactly as an integer in YAML. Put quotes around it to treat it as a string.`);
}
value.chipType = await zclHelper.asUnderlyingZclType.call(context, value.type, { 'hash' : {} });
value.name = key;
variables.push(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,22 @@ ResponseHandler {{> subscribeDataCallback}} = nil;
{
{{> actualValue}}
BOOL isLowerCase = [actualValue isEqualToString:[actualValue lowercaseString]];
XCTAssert{{#if expectedConstraints.isLowerCase}}True{{else}}False{{/if}}(isLowerCase);
XCTAssert{{#if (isStrEqual "true" expectedConstraints.isLowerCase)}}True{{else}}False{{/if}}(isLowerCase);
}
{{/if}}
{{#if (hasProperty expectedConstraints "isUpperCase")}}
{
{{> actualValue}}
BOOL isUpperCase = [actualValue isEqualToString:[actualValue uppercaseString]];
XCTAssert{{#if expectedConstraints.isUpperCase}}True{{else}}False{{/if}}(isUpperCase);
XCTAssert{{#if (isStrEqual "true" expectedConstraints.isUpperCase)}}True{{else}}False{{/if}}(isUpperCase);
}
{{/if}}
{{#if (hasProperty expectedConstraints "isHexString")}}
{
{{> actualValue}}
NSCharacterSet *chars = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789ABCDEF"] invertedSet];
BOOL isHexString = (NSNotFound == [actualValue rangeOfCharacterFromSet:chars].location);
XCTAssert{{#if expectedConstraints.isHexString}}True{{else}}False{{/if}}(isHexString);
XCTAssert{{#if (isStrEqual "true" expectedConstraints.isHexString)}}True{{else}}False{{/if}}(isHexString);
}
{{/if}}
{{#if (hasProperty expectedConstraints "maxLength")}}
Expand Down

0 comments on commit 5c63ca8

Please sign in to comment.