@@ -60,77 +60,69 @@ class {{filename}}: public TestCommand
60
60
{{/chip_tests_item_response_parameters}}
61
61
{{/chip_tests_items}}
62
62
63
- {{#*inline "failureCallback"}}mOnFailureCallback_{{index}}{{/inline}}
64
- {{#*inline "successCallback"}}mOnSuccessCallback_{{index}}{{/inline}}
65
-
66
- {{#if isGroupCommand}}
67
- {{#*inline "doneCallback"}}mOnDoneCallback_{{index}}{{/inline}}
63
+ {{~#*inline "subscribeDataCallback"}}
64
+ mTest_{{parent.filename}}_{{attribute}}_Reported
65
+ {{/inline}}
66
+ {{#*inline "subscribeDataCallbackType"}}
67
+ Test_{{parent.filename}}_{{attribute}}_ReportCallback
68
+ {{/inline}}
69
+ {{#chip_tests_items}}
70
+ {{#if allocateSubscribeDataCallback}}
71
+ typedef void (*{{> subscribeDataCallbackType}})(void * context, {{zapTypeToDecodableClusterObjectType attributeObject.type ns=parent.cluster isArgument=true}} value);
72
+ {{> subscribeDataCallbackType}} {{> subscribeDataCallback}} = nullptr;
68
73
{{/if}}
74
+ {{/chip_tests_items}}
69
75
70
- {{#*inline "failureResponse"}}OnFailureCallback_ {{index}}{{/inline}}
71
- {{#*inline "successResponse"}}OnSuccessCallback_ {{index}}{{/inline}}
72
-
73
- {{#*inline "doneResponse"}}OnDoneCallback_ {{index}}{{/inline}}
76
+ {{#*inline "failureResponse"}}OnFailureResponse_ {{index}}{{/inline}}
77
+ {{#*inline "successResponse"}}OnSuccessResponse_ {{index}}{{/inline}}
78
+ {{#*inline "subscriptionEstablished"}}OnSubscriptionEstablishedResponse_{{index}}{{/inline}}
79
+ {{#*inline "doneResponse"}}OnDoneResponse_ {{index}}{{/inline}}
74
80
75
- {{#*inline "successArguments"}}void * context{{#chip_tests_item_response_parameters}}, {{zapTypeToDecodableClusterObjectType type ns=parent.cluster isArgument=true}} {{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}}{{/inline}}
76
- {{#*inline "failureArguments"}}void * context, uint8_t status{{/inline}}
81
+ {{#*inline "staticFailureResponse"}}OnFailureCallback_{{index}}{{/inline}}
82
+ {{#*inline "staticSuccessResponse"}}OnSuccessCallback_{{index}}{{/inline}}
83
+ {{#*inline "staticSubscriptionEstablished"}}OnSubscriptionEstablished_{{index}}{{/inline}}
84
+ {{#*inline "staticDoneResponse"}}OnDoneCallback_{{index}}{{/inline}}
77
85
78
- {{#if isGroupCommand}}
79
- {{#*inline "doneArguments"}}void * context{{/inline}}
80
- {{/if}}
86
+ {{#*inline "successArguments"}}{{#chip_tests_item_response_parameters}}{{#first}}{{#if ../leadingComma}}, {{/if}}{{/first}} {{zapTypeToDecodableClusterObjectType type ns=parent.cluster isArgument=true}} {{asLowerCamelCase name}}{{#not_last}}, {{/not_last}}{{/chip_tests_item_response_parameters}}{{/inline}}
87
+ {{#*inline "failureArguments"}}{{#if leadingComma}}, {{/if}}EmberAfStatus status{{/inline}}
88
+ {{#*inline "staticSuccessArguments"}}void * context{{> successArguments leadingComma=true}}{{/inline}}
89
+ {{#*inline "staticFailureArguments"}}void * context{{> failureArguments leadingComma=true}}{{/inline}}
90
+ {{#*inline "staticDoneArguments"}}void * context{{/inline}}
91
+ {{#*inline "doneArguments"}}{{/inline}}
81
92
82
- {{#chip_tests_items}}
83
- {{#unless (isTestOnlyCluster cluster)}}
84
- {{#unless isWait}}
85
- {{#unless isCommand}}
86
- {{#unless isWriteAttribute}}
87
- {{#unless isReadAttribute}}
88
- chip::Callback::Callback<void (*) ({{>failureArguments}})> {{>failureCallback}} { {{>failureResponse}}, this };
89
- chip::Callback::Callback<void (*) ({{>successArguments}})> {{>successCallback}} { {{>successResponse}}, this };
90
- {{/unless}}
91
- {{/unless}}
92
- {{/unless}}
93
- {{/unless}}
94
- {{/unless}}
95
- {{/chip_tests_items}}
93
+ {{#*inline "staticSubscriptionEstablishedArguments"}}void * context{{/inline}}
94
+ {{#*inline "subscriptionEstablishedArguments"}}{{/inline}}
96
95
97
96
{{#chip_tests_items}}
98
97
{{#unless (isTestOnlyCluster cluster)}}
99
98
{{#unless isWait}}
100
99
{{#unless isCommand}}
101
100
{{#if isWriteAttribute}}
102
- static void {{>failureResponse}}(void * context, EmberAfStatus status)
103
- {
104
- (static_cast<{{filename}} *>(context))->OnFailureResponse_{{index}}(chip::to_underlying(status));
105
- }
106
-
107
- {{#if isGroupCommand}}
108
- static void {{>doneResponse}}(void * context)
109
- {
110
- (static_cast<{{filename}} *>(context))->OnDoneResponse_{{index}}();
111
-
112
- }
101
+ {{#if isGroupCommand}}
102
+ static void {{>staticDoneResponse}}({{>staticDoneArguments}})
103
+ {
104
+ (static_cast<{{filename}} *>(context))->{{> doneResponse }}();
105
+ }
106
+ {{/if}}
113
107
{{/if}}
114
108
115
- {{else if isReadAttribute}}
116
- static void {{>failureResponse}}(void * context, EmberAfStatus status)
109
+ static void {{>staticFailureResponse}}({{>staticFailureArguments}})
117
110
{
118
- (static_cast<{{filename}} *>(context))->OnFailureResponse_{{index }}(chip::to_underlying( status) );
111
+ (static_cast<{{filename}} *>(context))->{{>failureResponse }}(status);
119
112
}
120
- {{else}}
121
- static void {{>failureResponse }}({{> failureArguments }})
113
+
114
+ static void {{>staticSuccessResponse }}({{> staticSuccessArguments }})
122
115
{
123
- (static_cast<{{filename}} *>(context))->OnFailureResponse_{{index }}(status );
116
+ (static_cast<{{filename}} *>(context))->{{>successResponse }}({{#chip_tests_item_response_parameters}}{{#not_first}}, {{/not_first}}{{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}} );
124
117
}
125
- {{/if}}
126
118
127
-
128
- static void {{>successResponse }}({{> successArguments }})
119
+ {{#if isSubscribeAttribute}}
120
+ static void {{> staticSubscriptionEstablished }}({{> staticSubscriptionEstablishedArguments }})
129
121
{
130
- (static_cast<{{filename}} *>(context))->OnSuccessResponse_{{index}}({{#chip_tests_item_response_parameters}}{{#not_first}}, {{/not_first}}{{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}} );
122
+ (static_cast<{{filename}} *>(context))->{{> subscriptionEstablished}}( );
131
123
}
124
+ {{/if}}
132
125
133
- {{! "isWaitForReport" can be replaced by "async" if there is a mechanism to remove the report handler}}
134
126
{{#if isWaitForReport}}
135
127
bool mReceivedReport_{{index}} = false;
136
128
{{/if}}
@@ -164,13 +156,6 @@ class {{filename}}: public TestCommand
164
156
return CHIP_NO_ERROR;
165
157
}
166
158
{{else}}
167
- {{#*inline "failureResponse"}}OnFailureResponse_{{index}}{{/inline}}
168
- {{#*inline "successResponse"}}OnSuccessResponse_{{index}}{{/inline}}
169
- {{#*inline "doneResponse"}}OnDoneResponse_{{index}}{{/inline}}
170
-
171
- {{#*inline "failureArguments"}}uint8_t status{{/inline}}
172
- {{#*inline "successArguments"}}{{#chip_tests_item_response_parameters}}{{#not_first}}, {{/not_first}}{{zapTypeToDecodableClusterObjectType type ns=parent.cluster isArgument=true}} {{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}}{{/inline}}
173
- {{#*inline "doneArguments"}}{{/inline}}
174
159
175
160
{{#*inline "device"}}mDevices[kIdentity{{asUpperCamelCase identity}}]{{/inline}}
176
161
CHIP_ERROR {{>testCommand}}()
@@ -212,11 +197,11 @@ class {{filename}}: public TestCommand
212
197
{{/chip_tests_item_parameters}}
213
198
214
199
auto success = [](void * context, const typename RequestType::ResponseType & data) {
215
- (static_cast<{{filename}} *>(context))->OnSuccessResponse_{{index }}({{#chip_tests_item_response_parameters}}{{#not_first}}, {{/not_first}}data.{{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}});
200
+ (static_cast<{{filename}} *>(context))->{{>successResponse }}({{#chip_tests_item_response_parameters}}{{#not_first}}, {{/not_first}}data.{{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}});
216
201
};
217
202
218
203
auto failure = [](void * context, EmberAfStatus status) {
219
- (static_cast<{{filename}} *>(context))->OnFailureResponse_{{index }}(status);
204
+ (static_cast<{{filename}} *>(context))->{{>failureResponse }}(status);
220
205
};
221
206
222
207
ReturnErrorOnFailure(chip::Controller::{{#if isGroupCommand}}InvokeGroupCommand{{else}}InvokeCommand{{/if}}({{>device}}, this, success, failure,
@@ -225,7 +210,6 @@ class {{filename}}: public TestCommand
225
210
{{> maybeTimedInteractionTimeout }}
226
211
));
227
212
{{> maybeWait }}
228
- {{#unless async}}return CHIP_NO_ERROR;{{/unless}}
229
213
{{else}}
230
214
chip::Controller::{{asUpperCamelCase cluster}}ClusterTest cluster;
231
215
{{#if isGroupCommand}}
@@ -240,26 +224,26 @@ class {{filename}}: public TestCommand
240
224
{{/chip_tests_item_parameters}}
241
225
242
226
{{#if isWriteAttribute}}
243
- {{#*inline "failureResponse"}}OnFailureCallback_{{index}}{{/inline}}
244
- {{#*inline "successResponse"}}OnSuccessCallback_{{index}}{{/inline}}
245
- {{#*inline "doneResponse"}}OnDoneCallback_{{index}}{{/inline}}
246
- ReturnErrorOnFailure(cluster.WriteAttribute<chip::app::Clusters::{{asUpperCamelCase cluster}}::Attributes::{{asUpperCamelCase attribute}}::TypeInfo>({{#chip_tests_item_parameters}}{{asLowerCamelCase name}}Argument, {{/chip_tests_item_parameters}}this, {{>successResponse}}, {{>failureResponse}}
227
+ ReturnErrorOnFailure(cluster.WriteAttribute<chip::app::Clusters::{{asUpperCamelCase cluster}}::Attributes::{{asUpperCamelCase attribute}}::TypeInfo>({{#chip_tests_item_parameters}}{{asLowerCamelCase name}}Argument, {{/chip_tests_item_parameters}}this, {{>staticSuccessResponse}}, {{>staticFailureResponse}}
247
228
{{~> maybeTimedInteractionTimeout ~}}
248
- {{~#if isGroupCommand}}, {{>doneResponse }}{{/if~}}
229
+ {{~#if isGroupCommand}}, {{>staticDoneResponse }}{{/if~}}
249
230
));
250
231
{{> maybeWait }}
251
- {{#unless async}}return CHIP_NO_ERROR;{{/unless}}
252
232
{{else if isReadAttribute}}
253
- {{#*inline "failureResponse"}}OnFailureCallback_{{index}}{{/inline}}
254
- {{#*inline "successResponse"}}OnSuccessCallback_{{index}}{{/inline}}
255
- {{#if async}}ReturnErrorOnFailure({{else}}return {{/if}}cluster.ReadAttribute<chip::app::Clusters::{{asUpperCamelCase cluster}}::Attributes::{{asUpperCamelCase attribute}}::TypeInfo>({{#chip_tests_item_parameters}}{{asLowerCamelCase name}}Argument, {{/chip_tests_item_parameters}}this, {{>successResponse}}, {{>failureResponse}}){{#if async}}){{/if}};
233
+ ReturnErrorOnFailure(cluster.ReadAttribute<chip::app::Clusters::{{asUpperCamelCase cluster}}::Attributes::{{asUpperCamelCase attribute}}::TypeInfo>({{#chip_tests_item_parameters}}{{asLowerCamelCase name}}Argument, {{/chip_tests_item_parameters}}this, {{>staticSuccessResponse}}, {{>staticFailureResponse}}));
234
+ {{else if isSubscribeAttribute}}
235
+ ReturnErrorOnFailure(cluster.SubscribeAttribute<chip::app::Clusters::{{asUpperCamelCase cluster}}::Attributes::{{asUpperCamelCase attribute}}::TypeInfo>(this, {{>staticSuccessResponse}}, {{>staticFailureResponse}}, minIntervalArgument, maxIntervalArgument, {{>staticSubscriptionEstablished}}));
236
+ {{else if isWaitForReport}}
237
+ {{> subscribeDataCallback}} = {{> staticSuccessResponse}};
256
238
{{else}}
257
- {{~#*inline "commandName"}}{{asUpperCamelCase commandName}}{{#if isAttribute}}Attribute{{asUpperCamelCase attribute}}{{/if}}{{/inline}}
258
- {{#if async}}ReturnErrorOnFailure({{else}}return {{/if}}cluster.{{>commandName}}({{>successCallback}}.Cancel(){{#unless isWaitForReport}}, {{>failureCallback}}.Cancel(){{/unless}}{{#chip_tests_item_parameters}}, {{asLowerCamelCase name}}Argument{{/chip_tests_item_parameters}}){{#if async}}){{/if}};
239
+ UNEXPECTED COMMAND: {{>commandName}}
259
240
{{/if}}
260
-
261
241
{{/if}}
262
- {{#if async}}return WaitForMs(0);{{/if}}
242
+ {{#if async}}
243
+ return WaitForMs(0);
244
+ {{else}}
245
+ return CHIP_NO_ERROR;
246
+ {{/if}}
263
247
}
264
248
265
249
void {{>failureResponse}}({{>failureArguments}})
@@ -275,21 +259,40 @@ class {{filename}}: public TestCommand
275
259
{{/if}}
276
260
}
277
261
262
+ {{#if isSubscribeAttribute}}
263
+ void {{>successResponse}}({{zapTypeToDecodableClusterObjectType attributeObject.type ns=parent.cluster isArgument=true}} value)
264
+ {
265
+ {{#if response.error}}
266
+ ThrowSuccessResponse();
267
+ {{else if response.errorWrongValue}}
268
+ ThrowSuccessResponse();
269
+ {{else}}
270
+ if ({{> subscribeDataCallback}}) {
271
+ auto callback = {{> subscribeDataCallback}};
272
+ {{> subscribeDataCallback}} = nullptr;
273
+ callback(this, value);
274
+ }
275
+ {{/if}}
276
+ }
277
+
278
+ void {{>subscriptionEstablished}}({{> subscriptionEstablishedArguments}})
279
+ {
280
+ {{#if hasWaitForReport}}
281
+ VerifyOrReturn(mReceivedReport_{{waitForReport.index}}, Exit("Initial report not received!"));
282
+ {{/if}}
283
+ {{#unless async}}NextTest();{{/unless}}
284
+ }
285
+ {{else}}
278
286
void {{>successResponse}}({{>successArguments}})
279
287
{
280
288
{{~#if response.error}}
281
289
ThrowSuccessResponse();
282
290
{{else if response.errorWrongValue}}
283
291
ThrowSuccessResponse();
284
292
{{else}}
285
- {{! This block can be removed if there is a mechanism to remove the report handler}}
286
293
{{#if isWaitForReport}}
287
- VerifyOrReturn(mReceivedReport_{{index}} == false, ChipLogError(chipTool, "Not Fatal: on report called more than once."));
288
294
mReceivedReport_{{index}} = true;
289
295
{{/if}}
290
- {{#if hasWaitForReport}}
291
- VerifyOrReturn(mReceivedReport_{{waitForReport.index}}, Exit("Initial report not received!"));
292
- {{/if}}
293
296
{{#chip_tests_item_response_parameters}}
294
297
{{~#*inline "item"}}{{asLowerCamelCase name}}{{#if isOptional}}.Value(){{/if}}{{/inline}}
295
298
{{#if hasExpectedValue}}
@@ -318,6 +321,7 @@ class {{filename}}: public TestCommand
318
321
{{#unless async}}NextTest();{{/unless}}
319
322
{{/if}}
320
323
}
324
+ {{/if}}
321
325
322
326
{{#if isGroupCommand}}
323
327
void {{>doneResponse}}({{>doneArguments}})
0 commit comments