diff --git a/examples/chip-tool/templates/partials/test_cluster.zapt b/examples/chip-tool/templates/partials/test_cluster.zapt index e9778de4277379..cfd3213eb1ef5e 100644 --- a/examples/chip-tool/templates/partials/test_cluster.zapt +++ b/examples/chip-tool/templates/partials/test_cluster.zapt @@ -56,7 +56,9 @@ class {{filename}}: public TestCommand // Test {{label}} using SuccessCallback_{{index}} = void (*)(void * context{{#chip_tests_item_response_parameters}}, {{#if isList}}uint16_t count, {{/if}}{{chipType}} {{#if isList}}* {{/if}}{{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}}); chip::Callback::Callback mOnSuccessCallback_{{index}} { OnTestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}_SuccessResponse, this }; + {{#unless noFailureCallback}} chip::Callback::Callback mOnFailureCallback_{{index}} { OnTestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}_FailureResponse, this }; + {{/unless}} {{#if isSubscribeAttribute}} chip::Callback::Callback mOnSubscriptionEstablishedCallback_{{index}} { SubscribeAttribute_{{ index }}_OnSubscriptionEstablishedCallback, this }; {{/if}} @@ -66,6 +68,9 @@ class {{filename}}: public TestCommand {{#if isSubscribeAttribute}} bool mReceivedReport_{{index}} = false; {{/if}} + {{#if isWaitForReport}} + bool mReceivedReport_{{index}} = false; + {{/if}} CHIP_ERROR TestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}() { @@ -88,6 +93,8 @@ class {{filename}}: public TestCommand {{else if isSubscribeAttribute}} cluster.ReportAttribute{{asUpperCamelCase attribute}}(mOnSuccessCallback_{{index}}.Cancel()); err = cluster.ConfigureAttribute{{asUpperCamelCase attribute}}(mOnSubscriptionEstablishedCallback_{{index}}.Cancel(), mOnFailureCallback_{{index}}.Cancel(), {{minInterval}}, {{maxInterval}}); + {{else if isWaitForReport}} + err = cluster.ReportAttribute{{asUpperCamelCase attribute}}(mOnSuccessCallback_{{index}}.Cancel()); {{else if isReadAttribute}} err = cluster.ReadAttribute{{asUpperCamelCase attribute}}(mOnSuccessCallback_{{index}}.Cancel(), mOnFailureCallback_{{index}}.Cancel()); {{else if isWriteAttribute}} @@ -119,6 +126,7 @@ class {{filename}}: public TestCommand } {{/if}} + {{#unless noFailureCallback}} static void OnTestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}_FailureResponse(void * context, uint8_t status) { ChipLogProgress(chipTool, "{{cluster}} - {{label}}: Failure Response"); @@ -140,6 +148,7 @@ class {{filename}}: public TestCommand runner->NextTest(); } + {{/unless}} static void OnTestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}_SuccessResponse(void * context {{#chip_tests_item_response_parameters}}, {{#if isList}}uint16_t count, {{/if}}{{chipType}} {{#if isList}}* {{/if}}{{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}}) { @@ -154,6 +163,15 @@ class {{filename}}: public TestCommand return; } + {{#if isWaitForReport }} + if (runner->mReceivedReport_{{index}}) { + // Receiving report more than once is not an error since the subscription may be alive for a long time. + ChipLogProgress(chipTool, "Note: on report called more than once."); + return; + } + runner->mReceivedReport_{{index}} = true; + {{/if}} + {{> process_response_value}} {{#if isSubscribeAttribute}} diff --git a/src/app/tests/suites/TestSubscribe_OnOff.yaml b/src/app/tests/suites/TestSubscribe_OnOff.yaml index 69c0c4620d80c2..927c3582083de7 100644 --- a/src/app/tests/suites/TestSubscribe_OnOff.yaml +++ b/src/app/tests/suites/TestSubscribe_OnOff.yaml @@ -31,11 +31,14 @@ tests: - label: "Turn On the light to see attribute change" command: "On" - label: "Check for attribute report" - cluster: "TestSuite" - command: "WaitForAttributeReport" - waitfor: - endpoint: 1 - cluster: "On/Off" - attribute: "OnOff" - response: - value: true + command: "waitForReport" + attribute: "OnOff" + response: + value: true + - label: "Turn Off the light to see attribute change" + command: "Off" + - label: "Check for attribute report" + command: "waitForReport" + attribute: "OnOff" + response: + value: false diff --git a/src/app/zap-templates/common/ClusterTestGeneration.js b/src/app/zap-templates/common/ClusterTestGeneration.js index 4b0c741199bc9c..21a5cce39f3a07 100644 --- a/src/app/zap-templates/common/ClusterTestGeneration.js +++ b/src/app/zap-templates/common/ClusterTestGeneration.js @@ -64,8 +64,10 @@ function setDefaultType(test) const type = test[kCommandName]; switch (type) { case 'readAttribute': - test.isAttribute = true; - test.isReadAttribute = true; + test.isAttribute = true; + test.isReadAttribute = true; + test.noCommandSpecificRequestArguments = true; + test.useReadAttributeCallback = true; break; case 'writeAttribute': @@ -74,9 +76,18 @@ function setDefaultType(test) break; case 'subscribeAttribute': - test.isAttribute = true; - test.isReadAttribute = true; - test.isSubscribeAttribute = true; + test.isAttribute = true; + test.isSubscribeAttribute = true; + test.noCommandSpecificRequestArguments = true; + test.useReadAttributeCallback = true; + break; + + case 'waitForReport': + test.isAttribute = true; + test.isWaitForReport = true; + test.useReadAttributeCallback = true; + test.noCommandSpecificRequestArguments = true; + test.noFailureCallback = true; break; default: @@ -142,7 +153,7 @@ function setDefaultResponse(test) throwError(test, errorStr); } - if (!test.isReadAttribute) { + if (!test.useReadAttributeCallback) { return; } diff --git a/src/darwin/Framework/CHIP/templates/partials/process_response_value.zapt b/src/darwin/Framework/CHIP/templates/partials/process_response_value.zapt index 87927090450d6e..8d52cdd83d2fba 100644 --- a/src/darwin/Framework/CHIP/templates/partials/process_response_value.zapt +++ b/src/darwin/Framework/CHIP/templates/partials/process_response_value.zapt @@ -1,38 +1,37 @@ - {{#chip_tests_item_response_parameters}} - {{#if hasExpectedValue}} - {{#if isList}} - XCTAssertEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] count], {{expectedValue.length}}); - {{else}} - {{#if (isString type)}} - {{#if (isOctetString type)}} - NSString * {{asLowerCamelCase name}}ArgumentString= @"{{expectedValue}}"; - NSData * {{asLowerCamelCase name}}Argument = [{{asLowerCamelCase name}}ArgumentString dataUsingEncoding:NSUTF8StringEncoding]; - XCTAssertTrue([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] isEqualToData:{{asLowerCamelCase name}}Argument]); - {{else}} - NSString * {{asLowerCamelCase name}}Argument= @"{{expectedValue}}"; - XCTAssertTrue([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] isEqualToString:{{asLowerCamelCase name}}Argument]); - {{/if}} - {{else}} - XCTAssertEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedValue}}{{asTypeLiteralSuffix}}); - {{/if}} - {{/if}} - {{/if}} - {{#if hasExpectedConstraints}} - {{#if expectedConstraints.minLength}} - XCTAssertGreaterThanOrEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] length], {{expectedConstraints.minLength}}); - {{/if}} - {{#if expectedConstraints.maxLength}} - XCTAssertLessThanOrEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] length], {{expectedConstraints.maxLength}}); - {{/if}} - {{#if expectedConstraints.minValue}} - XCTAssertGreaterThanOrEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedConstraints.minValue}}); - {{/if}} - {{#if expectedConstraints.maxValue}} - XCTAssertLessThanOrEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedConstraints.maxValue}}); - {{/if}} - {{#if expectedConstraints.notValue}} - XCTAssertNotEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedConstraints.notValue}}); - {{/if}} - {{/if}} - {{/chip_tests_item_response_parameters}} - \ No newline at end of file +{{#chip_tests_item_response_parameters}} +{{#if hasExpectedValue}} +{{#if isList}} +XCTAssertEqual([values[@"{{#if parent.useReadAttributeCallback}}value{{else}}{{name}}{{/if}}"] count], {{expectedValue.length}}); +{{else}} +{{#if (isString type)}} +{{#if (isOctetString type)}} +NSString * {{asLowerCamelCase name}}ArgumentString= @"{{expectedValue}}"; +NSData * {{asLowerCamelCase name}}Argument = [{{asLowerCamelCase name}}ArgumentString dataUsingEncoding:NSUTF8StringEncoding]; +XCTAssertTrue([values[@"{{#if parent.useReadAttributeCallback}}value{{else}}{{name}}{{/if}}"] isEqualToData:{{asLowerCamelCase name}}Argument]); +{{else}} +NSString * {{asLowerCamelCase name}}Argument= @"{{expectedValue}}"; +XCTAssertTrue([values[@"{{#if parent.useReadAttributeCallback}}value{{else}}{{name}}{{/if}}"] isEqualToString:{{asLowerCamelCase name}}Argument]); +{{/if}} +{{else}} +XCTAssertEqual([values[@"{{#if parent.useReadAttributeCallback}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedValue}}{{asTypeLiteralSuffix}}); +{{/if}} +{{/if}} +{{/if}} +{{#if hasExpectedConstraints}} +{{#if expectedConstraints.minLength}} +XCTAssertGreaterThanOrEqual([values[@"{{#if parent.useReadAttributeCallback}}value{{else}}{{name}}{{/if}}"] length], {{expectedConstraints.minLength}}); +{{/if}} +{{#if expectedConstraints.maxLength}} +XCTAssertLessThanOrEqual([values[@"{{#if parent.useReadAttributeCallback}}value{{else}}{{name}}{{/if}}"] length], {{expectedConstraints.maxLength}}); +{{/if}} +{{#if expectedConstraints.minValue}} +XCTAssertGreaterThanOrEqual([values[@"{{#if parent.useReadAttributeCallback}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedConstraints.minValue}}); +{{/if}} +{{#if expectedConstraints.maxValue}} +XCTAssertLessThanOrEqual([values[@"{{#if parent.useReadAttributeCallback}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedConstraints.maxValue}}); +{{/if}} +{{#if expectedConstraints.notValue}} +XCTAssertNotEqual([values[@"{{#if parent.useReadAttributeCallback}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedConstraints.notValue}}); +{{/if}} +{{/if}} +{{/chip_tests_item_response_parameters}} diff --git a/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt b/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt index ad989f3171b060..a42168c6723700 100644 --- a/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt +++ b/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt @@ -12,8 +12,7 @@ CHIP{{asUpperCamelCase cluster}} * cluster = [[CHIP{{asUpperCamelCase cluster}} alloc] initWithDevice:device endpoint:{{endpoint}} queue:queue]; XCTAssertNotNil(cluster); - {{#if isReadAttribute}} - {{else}} + {{#unless noCommandSpecificRequestArguments}} {{#chip_tests_item_parameters}} {{#if (isString type)}} {{#if (isOctetString type)}} @@ -26,7 +25,7 @@ {{chipType}} {{asLowerCamelCase name}}Argument = {{definedValue}}{{asTypeLiteralSuffix chipType}}; {{/if}} {{/chip_tests_item_parameters}} - {{/if}} + {{/unless}} {{#if isCommand}} [cluster {{asLowerCamelCase command}}:{{#chip_tests_item_parameters}}{{#not_first}}{{asLowerCamelCase name}}:{{/not_first}}{{asLowerCamelCase name}}Argument {{#last}}responseHandler:{{/last}}{{/chip_tests_item_parameters}}^(NSError * err, NSDictionary * values) { {{else if isSubscribeAttribute}} @@ -41,6 +40,8 @@ [cluster configureAttribute{{asUpperCamelCase attribute}}WithMinInterval:{{minInterval}} maxInterval:{{maxInterval}} responseHandler:^(NSError * err, NSDictionary * values) { + {{else if isWaitForReport}} + [cluster reportAttribute{{asUpperCamelCase attribute}}WithResponseHandler:^(NSError * err, NSDictionary * values) { {{else if isReadAttribute}} [cluster readAttribute{{asUpperCamelCase attribute}}WithResponseHandler:^(NSError * err, NSDictionary * values) { {{else if isWriteAttribute}} diff --git a/src/darwin/Framework/CHIP/templates/templates.json b/src/darwin/Framework/CHIP/templates/templates.json index 34c4f155e569dc..f0f9231bd67103 100644 --- a/src/darwin/Framework/CHIP/templates/templates.json +++ b/src/darwin/Framework/CHIP/templates/templates.json @@ -26,17 +26,6 @@ { "name": "CHIPCallbackBridge", "path": "partials/CHIPCallbackBridge.zapt" -<<<<<<< HEAD - }, - { - "name": "TestSuiteHelper_WaitForMs", - "path": "partials/testsuite/WaitForMs.zapt" - }, - { - "name": "TestSuiteHelper_WaitForAttributeReport", - "path": "partials/testsuite/WaitForAttributeReport.zapt" -======= ->>>>>>> parent of 8390956ec ([testsuite] Refactor test suite simulated cluster command) } ], "templates": [