Skip to content

Commit

Permalink
[YAML] Generates write attribute methods for non writeable attributes (
Browse files Browse the repository at this point in the history
…#9554)

* Add {{clusterName}}ClusterTest interfaces with write methods for non-writeable attributes

* Add Objc Test{{clusterName}} interfaces with write methods for non-writeable attributes

* Remove some disabled flags from some tests trying to write to ClusterRevision/FeatureMap

* Update generated content
  • Loading branch information
vivien-apple authored Sep 16, 2021
1 parent 535feb0 commit 96e825a
Show file tree
Hide file tree
Showing 23 changed files with 10,671 additions and 616 deletions.
1 change: 1 addition & 0 deletions examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "../common/Command.h"
#include <controller/ExampleOperationalCredentialsIssuer.h>
#include <zap-generated/tests/CHIPClusters.h>

class TestCommand : public Command
{
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class {{filename}}: public TestCommand
{
ChipLogProgress(chipTool, "{{cluster}} - {{label}}: Sending command...");

chip::Controller::{{asUpperCamelCase cluster}}Cluster cluster;
chip::Controller::{{asUpperCamelCase cluster}}ClusterTest cluster;
cluster.Associate(mDevice, {{endpoint}});

CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down
1 change: 1 addition & 0 deletions scripts/tools/zap_regen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def getSpecificTemplatesTargets():
'src/controller/python/templates/templates.json': None,
'src/darwin/Framework/CHIP/templates/templates.json': None,
'src/controller/java/templates/templates.json': None,
'src/app/tests/suites/templates/templates.json': 'zzz_generated/controller-clusters/zap-generated',
}

for template, output_dir in templates.items():
Expand Down
9 changes: 9 additions & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ template("chip_data_model") {
_use_default_im_dispatch = !defined(invoker.use_default_im_dispatch) ||
invoker.use_default_im_dispatch

_use_tests_apis = defined(invoker.use_tests_apis) && invoker.use_tests_apis

_use_default_client_callbacks =
defined(invoker.use_default_client_callbacks) &&
invoker.use_default_client_callbacks
Expand Down Expand Up @@ -169,6 +171,13 @@ template("chip_data_model") {
sources +=
[ "${invoker.zap_pregenerated_dir}/IMClusterCommandHandler.cpp" ]
}

if (_use_tests_apis) {
sources += [
"${invoker.zap_pregenerated_dir}/tests/CHIPClusters.cpp",
"${invoker.zap_pregenerated_dir}/tests/CHIPClusters.h",
]
}
}

if (!defined(public_deps)) {
Expand Down
1 change: 0 additions & 1 deletion src/app/tests/suites/certification/Test_TC_BI_1_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ tests:
- label:
"write the default values to mandatory global attribute:
ClusterRevision"
disabled: true
command: "writeAttribute"
attribute: "ClusterRevision"
arguments:
Expand Down
2 changes: 0 additions & 2 deletions src/app/tests/suites/certification/Test_TC_OO_1_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ tests:
- label:
"write the default values to mandatory global attribute:
ClusterRevision"
disabled: true
command: "writeAttribute"
attribute: "ClusterRevision"
arguments:
Expand All @@ -49,7 +48,6 @@ tests:
value: 0

- label: "write the default values to optional global attribute: FeatureMap"
disabled: true
command: "writeAttribute"
attribute: "FeatureMap"
arguments:
Expand Down
1 change: 0 additions & 1 deletion src/app/tests/suites/certification/Test_TC_WNCV_1_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ tests:
- label:
"write the default value to mandatory global attribute:
ClusterRevision"
disabled: true
command: "writeAttribute"
attribute: "ClusterRevision"
arguments:
Expand Down
28 changes: 28 additions & 0 deletions src/app/tests/suites/templates/templates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "CHIP Tests templates",
"version": "chip-v1",
"helpers": [
"../../../zap-templates/common/StringHelper.js",
"../../../zap-templates/templates/app/helper.js",
"../../../zap-templates/templates/chip/helper.js"
],
"override": "../../../zap-templates/common/override.js",
"partials": [
{
"name": "header",
"path": "../../../zap-templates/partials/header.zapt"
}
],
"templates": [
{
"path": "../../../zap-templates/templates/app/tests/CHIPClusters.zapt",
"name": "Tests C++ API Header",
"output": "tests/CHIPClusters.h"
},
{
"path": "../../../zap-templates/templates/app/tests/CHIPClusters-src.zapt",
"name": "Tests C++ API",
"output": "tests/CHIPClusters.cpp"
}
]
}
49 changes: 49 additions & 0 deletions src/app/zap-templates/templates/app/tests/CHIPClusters-src.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{#if (chip_has_client_clusters)}}
{{> header}}

#include "CHIPClusters.h"

#include <app/InteractionModelEngine.h>
#include <app/util/basic-types.h>

#include <app-common/zap-generated/ids/Attributes.h>
#include <zap-generated/CHIPClientCallbacks.h>

using namespace chip::app::Clusters;
using namespace chip::System;
using namespace chip::Encoding::LittleEndian;

namespace chip {
namespace Controller {

{{#chip_client_clusters}}

{{#chip_server_cluster_attributes}}
{{#unless isWritableAttribute}}
{{#unless isList}}
{{#unless isStruct}}
CHIP_ERROR {{asUpperCamelCase parent.name}}ClusterTest::WriteAttribute{{asUpperCamelCase name}}(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback, {{chipType}} {{asLowerCamelCase name}})
{
app::WriteClientHandle handle;
chip::app::AttributePathParams attributePath;
attributePath.mNodeId = mDevice->GetDeviceId();
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mFieldId = {{#if isGlobalAttribute}}Globals{{else}}{{asUpperCamelCase parent.name}}{{/if}}::Attributes::Ids::{{asUpperCamelCase name}};
attributePath.mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);

ReturnErrorOnFailure(app::InteractionModelEngine::GetInstance()->NewWriteClient(handle));
ReturnErrorOnFailure(handle.EncodeScalarAttributeWritePayload(attributePath, {{asLowerCamelCase name}}));

return mDevice->SendWriteAttributeRequest(std::move(handle), onSuccessCallback, onFailureCallback);
}

{{/unless}}
{{/unless}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{/chip_client_clusters}}

} // namespace Controller
} // namespace chip
{{/if}}
32 changes: 32 additions & 0 deletions src/app/zap-templates/templates/app/tests/CHIPClusters.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{#if (chip_has_client_clusters)}}
{{> header}}

#pragma once

#include <zap-generated/CHIPClusters.h>

namespace chip {
namespace Controller {

{{#chip_client_clusters}}
class DLL_EXPORT {{asUpperCamelCase name}}ClusterTest : public {{asUpperCamelCase name}}Cluster
{
public:
{{asUpperCamelCase name}}ClusterTest() : {{asUpperCamelCase name}}Cluster() {}
~{{asUpperCamelCase name}}ClusterTest() {}

{{#chip_server_cluster_attributes}}
{{#unless isWritableAttribute}}
{{#unless isList}}
{{#unless isStruct}}
CHIP_ERROR WriteAttribute{{asUpperCamelCase name}}(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback, {{chipType}} value);
{{/unless}}
{{/unless}}
{{/unless}}
{{/chip_server_cluster_attributes}}
};

{{/chip_client_clusters}}
} // namespace Controller
} // namespace chip
{{/if}}
1 change: 1 addition & 0 deletions src/controller/data_model/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ chip_data_model("data_model") {
zap_pregenerated_dir =
"${chip_root}/zzz_generated/controller-clusters/zap-generated"

use_tests_apis = true
use_default_client_callbacks = true
allow_circular_includes_from = [ "${chip_root}/src/controller" ]
}
12 changes: 12 additions & 0 deletions src/darwin/Framework/CHIP.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
1E16A8FE26B9876900683C53 /* CHIPClusters.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E16A8FD26B9876900683C53 /* CHIPClusters.cpp */; };
1E16A90226B98AB700683C53 /* CHIPTestClustersObjc.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1E16A8FA26B9835700683C53 /* CHIPTestClustersObjc.mm */; };
1E16A90326B98AF100683C53 /* CHIPTestClustersObjc.h in Headers */ = {isa = PBXBuildFile; fileRef = 1E16A8F926B9835600683C53 /* CHIPTestClustersObjc.h */; settings = {ATTRIBUTES = (Public, ); }; };
1E857306265519720050A4D9 /* CHIPClientCallbacks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E857305265519720050A4D9 /* CHIPClientCallbacks.cpp */; };
1E85730C265519AE0050A4D9 /* callback-stub.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E857307265519AE0050A4D9 /* callback-stub.cpp */; };
1E85730E265519AE0050A4D9 /* CHIPClusters.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1E857309265519AE0050A4D9 /* CHIPClusters.cpp */; };
Expand Down Expand Up @@ -92,6 +95,9 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1E16A8F926B9835600683C53 /* CHIPTestClustersObjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CHIPTestClustersObjc.h; path = zap-generated/CHIPTestClustersObjc.h; sourceTree = "<group>"; };
1E16A8FA26B9835700683C53 /* CHIPTestClustersObjc.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CHIPTestClustersObjc.mm; path = zap-generated/CHIPTestClustersObjc.mm; sourceTree = "<group>"; };
1E16A8FD26B9876900683C53 /* CHIPClusters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CHIPClusters.cpp; path = "../../../../zzz_generated/controller-clusters/zap-generated/tests/CHIPClusters.cpp"; sourceTree = "<group>"; };
1E857305265519720050A4D9 /* CHIPClientCallbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CHIPClientCallbacks.cpp; path = "../../../../zzz_generated/controller-clusters/zap-generated/CHIPClientCallbacks.cpp"; sourceTree = "<group>"; };
1E857307265519AE0050A4D9 /* callback-stub.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "callback-stub.cpp"; path = "../../../../zzz_generated/controller-clusters/zap-generated/callback-stub.cpp"; sourceTree = "<group>"; };
1E857309265519AE0050A4D9 /* CHIPClusters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CHIPClusters.cpp; path = "../../../../zzz_generated/controller-clusters/zap-generated/CHIPClusters.cpp"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -195,6 +201,7 @@
isa = PBXGroup;
children = (
2F79A67626CE6672006377B0 /* im-client-callbacks.cpp */,
1E16A8FD26B9876900683C53 /* CHIPClusters.cpp */,
2FD775542695557E00FF4B12 /* error-mapping.cpp */,
1E85733326551A700050A4D9 /* reporting-default-configuration.cpp */,
1E85733226551A700050A4D9 /* reporting.cpp */,
Expand All @@ -221,6 +228,8 @@
1EC4CE5825CC26AB00D7304F /* CHIPGeneratedFiles */ = {
isa = PBXGroup;
children = (
1E16A8F926B9835600683C53 /* CHIPTestClustersObjc.h */,
1E16A8FA26B9835700683C53 /* CHIPTestClustersObjc.mm */,
1ED276DF26C57CF000547A89 /* CHIPCallbackBridge.mm */,
1E85730A265519AE0050A4D9 /* attribute-size.cpp */,
1E857307265519AE0050A4D9 /* callback-stub.cpp */,
Expand Down Expand Up @@ -329,6 +338,7 @@
buildActionMask = 2147483647;
files = (
2CB7163B252E8A7B0026E2BB /* CHIPDevicePairingDelegateBridge.h in Headers */,
1E16A90326B98AF100683C53 /* CHIPTestClustersObjc.h in Headers */,
2C1B027B2641DB4E00780EF1 /* CHIPOperationalCredentialsDelegate.h in Headers */,
B289D4212639C0D300D4E314 /* CHIPOnboardingPayloadParser.h in Headers */,
2CB7163F252F731E0026E2BB /* CHIPDevicePairingDelegate.h in Headers */,
Expand Down Expand Up @@ -481,6 +491,7 @@
1E85732426551A490050A4D9 /* attribute-list-byte-span.cpp in Sources */,
998F287126D56940001846C6 /* CHIPP256KeypairBridge.mm in Sources */,
1E85730E265519AE0050A4D9 /* CHIPClusters.cpp in Sources */,
1E16A90226B98AB700683C53 /* CHIPTestClustersObjc.mm in Sources */,
1E85732326551A490050A4D9 /* process-global-message.cpp in Sources */,
1E85732E26551A490050A4D9 /* ember-print.cpp in Sources */,
2C5EEEF7268A85C400CAE3D3 /* CHIPDeviceConnectionBridge.mm in Sources */,
Expand All @@ -497,6 +508,7 @@
1E85732526551A490050A4D9 /* message.cpp in Sources */,
B2E0D7B3245B0B5C003C5B48 /* CHIPError.mm in Sources */,
1E85732726551A490050A4D9 /* client-api.cpp in Sources */,
1E16A8FE26B9876900683C53 /* CHIPClusters.cpp in Sources */,
1E85730C265519AE0050A4D9 /* callback-stub.cpp in Sources */,
1E857310265519AE0050A4D9 /* IMClusterCommandHandler.cpp in Sources */,
1ED276E026C57CF000547A89 /* CHIPCallbackBridge.mm in Sources */,
Expand Down
50 changes: 50 additions & 0 deletions src/darwin/Framework/CHIP/templates/CHIPTestClustersObjc-src.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{#if (chip_has_client_clusters)}}
{{> header}}
#import <Foundation/Foundation.h>

#import "CHIPCallbackBridge_internal.h"
#import "CHIPCluster_internal.h"
#import "CHIPDevice.h"
#import "CHIPDevice_Internal.h"

#import "zap-generated/tests/CHIPClusters.h"
#import "zap-generated/CHIPTestClustersObjc.h"

using chip::Callback::Cancelable;

{{#chip_client_clusters}}

@interface CHIPTest{{asUpperCamelCase name}} ()
@property (readonly) chip::Controller::{{asUpperCamelCase name}}ClusterTest cppCluster;
@end

@implementation CHIPTest{{asUpperCamelCase name}}

- (chip::Controller::ClusterBase *)getCluster
{
return &_cppCluster;
}

{{#chip_server_cluster_attributes}}
{{#unless isWritableAttribute}}
{{#unless isList}}
{{#unless isStruct}}
{{#*inline "attribute"}}Attribute{{asUpperCamelCase name}}{{/inline}}
{{#*inline "callbackName"}}DefaultSuccess{{/inline}}
{{#*inline "callbackParams"}}, {{#if (isString type)}}[self asSpan:{{/if}}value{{#if (isString type)}}]{{/if}}{{/inline}}
- (void)write{{>attribute}}WithValue:({{asObjectiveCBasicType type}})value responseHandler:(ResponseHandler)responseHandler
{
new CHIP{{>callbackName}}CallbackBridge(self.callbackQueue, responseHandler, ^(Cancelable * success, Cancelable * failure) {
return self.cppCluster.Write{{>attribute}}(success, failure{{>callbackParams}});
});
}

{{/unless}}
{{/unless}}
{{/unless}}
{{/chip_server_cluster_attributes}}

@end

{{/chip_client_clusters}}
{{/if}}
33 changes: 33 additions & 0 deletions src/darwin/Framework/CHIP/templates/CHIPTestClustersObjc.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{#if (chip_has_client_clusters)}}
{{> header}}

#import <CHIP/CHIPClustersObjc.h>

@class CHIPDevice;

NS_ASSUME_NONNULL_BEGIN

{{#chip_client_clusters}}

/**
* Cluster {{name}}
* {{description}}
*/
@interface CHIPTest{{asUpperCamelCase name}} : CHIP{{asUpperCamelCase name}}

{{#chip_server_cluster_attributes}}
{{#unless isWritableAttribute}}
{{#unless isList}}
{{#unless isStruct}}
- (void)writeAttribute{{asUpperCamelCase name}}WithValue:({{asObjectiveCBasicType type}})value responseHandler:(ResponseHandler)responseHandler;
{{/unless}}
{{/unless}}
{{/unless}}
{{/chip_server_cluster_attributes}}

@end

{{/chip_client_clusters}}

NS_ASSUME_NONNULL_END
{{/if}}
1 change: 1 addition & 0 deletions src/darwin/Framework/CHIP/templates/clusters-tests.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

// module headers
#import <CHIP/CHIP.h>
#import <CHIP/CHIPTestClustersObjc.h>

// system dependencies
#import <XCTest/XCTest.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{else}}
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
CHIP{{asUpperCamelCase cluster}} * cluster = [[CHIP{{asUpperCamelCase cluster}} alloc] initWithDevice:device endpoint:{{endpoint}} queue:queue];
CHIPTest{{asUpperCamelCase cluster}} * cluster = [[CHIPTest{{asUpperCamelCase cluster}} alloc] initWithDevice:device endpoint:{{endpoint}} queue:queue];
XCTAssertNotNil(cluster);

{{#if isReadAttribute}}
Expand Down
10 changes: 10 additions & 0 deletions src/darwin/Framework/CHIP/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@
"name": "Objc ZCL API",
"output": "src/darwin/Framework/CHIP/zap-generated/CHIPClustersObjc.mm"
},
{
"path": "CHIPTestClustersObjc.zapt",
"name": "Test Objc API Header",
"output": "src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.h"
},
{
"path": "CHIPTestClustersObjc-src.zapt",
"name": "Test Objc API",
"output": "src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.mm"
},
{
"path": "clusters-tests.zapt",
"name": "Cluster Tests",
Expand Down
Loading

0 comments on commit 96e825a

Please sign in to comment.