diff --git a/src/darwin/Framework/CHIP/templates/helper.js b/src/darwin/Framework/CHIP/templates/helper.js index 7aa0599390bf77..d79ab45d90d4c6 100644 --- a/src/darwin/Framework/CHIP/templates/helper.js +++ b/src/darwin/Framework/CHIP/templates/helper.js @@ -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); } diff --git a/src/darwin/Framework/CHIP/templates/partials/check_test_value.zapt b/src/darwin/Framework/CHIP/templates/partials/check_test_value.zapt index 4da8e480ea8f40..7ef670c1723cc4 100644 --- a/src/darwin/Framework/CHIP/templates/partials/check_test_value.zapt +++ b/src/darwin/Framework/CHIP/templates/partials/check_test_value.zapt @@ -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}}"]); diff --git a/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt b/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt index 2dc923a4739c32..a302c592fc4ac6 100644 --- a/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt +++ b/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt @@ -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}} @@ -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}} @@ -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}} } diff --git a/src/darwin/Framework/CHIP/templates/partials/test_value.zapt b/src/darwin/Framework/CHIP/templates/partials/test_value.zapt index 74488126dd1876..2e022ced5e50f8 100644 --- a/src/darwin/Framework/CHIP/templates/partials/test_value.zapt +++ b/src/darwin/Framework/CHIP/templates/partials/test_value.zapt @@ -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)}}