Skip to content

Commit

Permalink
Update subscription test per comment
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed Sep 14, 2021
1 parent b0c7b38 commit 6aa7fc0
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 66 deletions.
18 changes: 18 additions & 0 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -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<SuccessCallback_{{index}}> mOnSuccessCallback_{{index}} { OnTestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}_SuccessResponse, this };
{{#unless noFailureCallback}}
chip::Callback::Callback<DefaultFailureCallback> mOnFailureCallback_{{index}} { OnTestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}_FailureResponse, this };
{{/unless}}
{{#if isSubscribeAttribute}}
chip::Callback::Callback<DefaultSuccessCallback> mOnSubscriptionEstablishedCallback_{{index}} { SubscribeAttribute_{{ index }}_OnSubscriptionEstablishedCallback, this };
{{/if}}
Expand All @@ -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}}()
{
Expand All @@ -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}}
Expand Down Expand Up @@ -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");
Expand All @@ -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}})
{
Expand All @@ -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}}
Expand Down
19 changes: 11 additions & 8 deletions src/app/tests/suites/TestSubscribe_OnOff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 17 additions & 6 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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:
Expand Down Expand Up @@ -142,7 +153,7 @@ function setDefaultResponse(test)
throwError(test, errorStr);
}

if (!test.isReadAttribute) {
if (!test.useReadAttributeCallback) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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}}

{{#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}}
Original file line number Diff line number Diff line change
Expand Up @@ -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)}}
Expand All @@ -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}}
Expand All @@ -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}}
Expand Down
11 changes: 0 additions & 11 deletions src/darwin/Framework/CHIP/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit 6aa7fc0

Please sign in to comment.