Skip to content

Commit

Permalink
[YAML] Add 'saveAs' support for CHAR_STRING and OCTET_STRING for Darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple committed Jan 13, 2022
1 parent a2bebc0 commit 105f280
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/darwin/Framework/CHIP/templates/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ function asTestValue()
}
}

function asObjectiveCBasicType(type)
function asObjectiveCBasicType(type, options)
{
if (StringHelper.isOctetString(type)) {
return 'NSData *';
return options.hash.is_mutable ? 'NSMutableData *' : 'NSData *';
} else if (StringHelper.isCharString(type)) {
return 'NSString *';
return options.hash.is_mutable ? 'NSMutableString *' : 'NSString *';
} else {
return ChipTypesHelper.asBasicType(this.chipType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
{{! Maybe we should add a check for properties in the expected object (other
than "global") that are not present in the struct ? }}
{{else}}
{{#if (isOctetString type)}}
{{#if (chip_tests_variables_has expected)}}
{{#if (isString type)}}
XCTAssertEqualObjects({{actual}}, {{expected}});
{{else}}
XCTAssertEqual([{{actual}} {{asObjectiveCNumberType "" type true}}Value], {{expected}});
{{/if}}
{{else if (isOctetString type)}}
XCTAssertTrue([{{actual}} isEqualToData:[[NSData alloc] initWithBytes:"{{octetStringEscapedForCLiteral expected}}" length:{{expected.length}}]]);
{{else if (isCharString type)}}
XCTAssertTrue([{{actual}} isEqualToString:@"{{expected}}"]);
Expand Down
12 changes: 11 additions & 1 deletion src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bool testSendCluster{{parent.filename}}_{{asTestIndex index}}_{{asUpperCamelCase
{{/if}}
{{#chip_tests_item_response_parameters}}
{{#if saveAs}}
{{asBasicType chipType}} {{saveAs}};
{{asObjectiveCBasicType type is_mutable=true}} {{saveAs}};
{{/if}}
{{/chip_tests_item_response_parameters}}

Expand Down Expand Up @@ -103,8 +103,14 @@ ResponseHandler {{> subscribeDataCallback}} = nil;
{{> actualValue}}
{{>check_test_value actual="actualValue" expected=expectedValue cluster=../cluster}}
{{#if saveAs}}
{{#if (isOctetString type)}}
{{saveAs}} = [NSMutableData dataWithData:actualValue];
{{else if (isCharString type)}}
{{saveAs}} = [NSMutableString stringWithString:actualValue];
{{else}}
{{saveAs}} = [actualValue {{asObjectiveCNumberType "" type true}}Value];
{{/if}}
{{/if}}
}
{{/if}}
{{#if hasExpectedConstraints}}
Expand Down Expand Up @@ -177,7 +183,11 @@ ResponseHandler {{> subscribeDataCallback}} = nil;
XCTAssertFalse(actualValue == nil);
{{else}}
if (actualValue != nil) {
{{#if (isString type)}}
XCTAssertNotEqualObjects(actualValue, {{expectedConstraints.notValue}});
{{else}}
XCTAssertNotEqual([actualValue {{asObjectiveCNumberType "" type true}}Value], {{asTypedLiteral expectedConstraints.notValue type}});
{{/if}}
}
{{/if}}
}
Expand Down
6 changes: 6 additions & 0 deletions src/darwin/Framework/CHIP/templates/partials/test_value.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
{{/if_include_struct_item_value}}
{{/zcl_struct_items_by_struct_name}}

{{else if (chip_tests_variables_has definedValue)}}
{{#if (isString type)}}
{{target}} = [{{definedValue}} copy];
{{else}}
{{target}} = [NSNumber numberWith{{asObjectiveCNumberType definedValue type false}}:{{definedValue}}];
{{/if}}
{{else if (isCharString type)}}
{{target}} = @"{{definedValue}}";
{{else if (isOctetString type)}}
Expand Down

0 comments on commit 105f280

Please sign in to comment.