Skip to content

Commit

Permalink
[Darwin] Remove automatically generated tests for Darwin since there …
Browse files Browse the repository at this point in the history
…are many YAMLs tests now (#14828)

* [Darwin] Remove automatically generated tests for Darwin since there are many YAMLs tests now

* Update generated darwin tests
  • Loading branch information
vivien-apple authored and pull[bot] committed Sep 29, 2023
1 parent 03b946b commit 2073285
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16,611 deletions.
67 changes: 0 additions & 67 deletions src/darwin/Framework/CHIP/templates/clusters-tests.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -212,71 +212,4 @@ CHIPDevice * GetConnectedDevice(void)

{{>test_cluster tests=(getTests)}}

{{#chip_client_clusters}}
{{#unless (isStrEqual "Test Cluster" name)}}
{{#unless (isStrEqual "Access Control" name)}}
{{#unless (isStrEqual "Basic" name)}}
{{#unless (isStrEqual "Thermostat" name)}}
{{#unless (isStrEqual "OTA Software Update Provider" name)}}
{{#unless (isStrEqual "Network Commissioning" name)}} {{! "Networks" is broken }}
{{#unless (isStrEqual "Application Basic" name)}} {{! "Application App" is broken }}
{{#chip_server_cluster_attributes}}
- (void)testSendCluster{{asUpperCamelCase parent.name}}ReadAttribute{{asUpperCamelCase name}}WithCompletionHandler
{
dispatch_queue_t queue = dispatch_get_main_queue();

XCTestExpectation * connectedExpectation = [self expectationWithDescription:@"Wait for the commissioned device to be retrieved"];
WaitForCommissionee(connectedExpectation, queue);
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];

CHIPDevice * device = GetConnectedDevice();
CHIP{{asUpperCamelCase parent.name}} * cluster = [[CHIP{{asUpperCamelCase parent.name}} alloc] initWithDevice:device endpoint:{{asExpectedEndpointForCluster (asUpperCamelCase parent.name)}} queue:queue];
XCTAssertNotNil(cluster);

XCTestExpectation * expectation = [self expectationWithDescription:@"{{asUpperCamelCase parent.name}}ReadAttribute{{asUpperCamelCase name}}WithCompletionHandler"];

[cluster readAttribute{{asUpperCamelCase name}}WithCompletionHandler:^({{asObjectiveCClass type parent.name}} * _Nullable value, NSError * _Nullable err) {
NSLog(@"{{asUpperCamelCase parent.name}} {{asUpperCamelCase name}} Error: %@", err);
XCTAssertEqual(err.code, 0);
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

{{#if isWritableAttribute}}
- (void)testSendCluster{{asUpperCamelCase parent.name}}WriteAttribute{{asUpperCamelCase name}}WithValue
{
dispatch_queue_t queue = dispatch_get_main_queue();

XCTestExpectation * connectedExpectation = [self expectationWithDescription:@"Wait for the commissioned device to be retrieved"];
WaitForCommissionee(connectedExpectation, queue);
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];

CHIPDevice * device = GetConnectedDevice();
CHIP{{asUpperCamelCase parent.name}} * cluster = [[CHIP{{asUpperCamelCase parent.name}} alloc] initWithDevice:device endpoint:{{asExpectedEndpointForCluster (asUpperCamelCase parent.name)}} queue:queue];
XCTAssertNotNil(cluster);

XCTestExpectation * expectation = [self expectationWithDescription:@"{{asUpperCamelCase parent.name}}WriteAttribute{{asUpperCamelCase name}}WithValue"];

{{asObjectiveCType type parent.name}} value = {{asTestValue parent.name}};
[cluster writeAttribute{{asUpperCamelCase name}}WithValue:value completionHandler:^(NSError * _Nullable err) {
NSLog(@"{{asUpperCamelCase parent.name}} {{asUpperCamelCase name}} Error: %@", err);
XCTAssertEqual(err.code, 0);
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}
{{/if}}
{{/chip_server_cluster_attributes}}
{{/unless}}
{{/unless}}
{{/unless}}
{{/unless}}
{{/unless}}
{{/unless}}
{{/unless}}
{{/chip_client_clusters}}

@end
65 changes: 8 additions & 57 deletions src/darwin/Framework/CHIP/templates/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,6 @@ const ChipTypesHelper = require('../../../../../src/app/zap-templates/common/Chi
const StringHelper = require('../../../../../src/app/zap-templates/common/StringHelper.js');
const appHelper = require('../../../../../src/app/zap-templates/templates/app/helper.js');

// Ideally those clusters clusters endpoints should be retrieved from the
// descriptor cluster.
function asExpectedEndpointForCluster(clusterName)
{
switch (clusterName) {
case 'AccessControl':
case 'AdministratorCommissioning':
case 'Basic':
case 'Descriptor':
case 'DiagnosticLogs':
case 'GeneralCommissioning':
case 'GeneralDiagnostics':
case 'LocalizationConfiguration':
case 'SoftwareDiagnostics':
case 'ThreadNetworkDiagnostics':
case 'EthernetNetworkDiagnostics':
case 'WiFiNetworkDiagnostics':
case 'GroupKeyManagement':
case 'NetworkCommissioning':
case 'OperationalCredentials':
case 'TimeFormatLocalization':
case 'TrustedRootCertificates':
case 'OtaSoftwareUpdateProvider':
case 'OtaSoftwareUpdateRequestor':
case 'PowerSourceConfiguration':
case 'UnitLocalization':
return 0;
}
return 1;
}

async function asTestValue(cluster, options)
{
if (StringHelper.isOctetString(this.type)) {
return `[@"${"Test".substring(0, this.maxLength)}" dataUsingEncoding:NSUTF8StringEncoding]`;
} else if (StringHelper.isCharString(this.type)) {
return `@"${"Test".substring(0, this.maxLength)}"`;
} else if (this.isArray) {
return '[NSArray array]';
} else if (this.isStruct) {
let ourClass = await asObjectiveCClass.call(this, this.type, cluster, options);
return `[[${ourClass} alloc] init]`;
} else {
return `@(${this.min || this.max || 0})`;
}
}

function asObjectiveCBasicType(type, options)
{
if (StringHelper.isOctetString(type)) {
Expand Down Expand Up @@ -200,13 +153,11 @@ function commandHasRequiredField(command)
//
// Module exports
//
exports.asObjectiveCBasicType = asObjectiveCBasicType;
exports.asObjectiveCNumberType = asObjectiveCNumberType;
exports.asExpectedEndpointForCluster = asExpectedEndpointForCluster;
exports.asTestIndex = asTestIndex;
exports.asTestValue = asTestValue;
exports.asObjectiveCClass = asObjectiveCClass;
exports.asObjectiveCType = asObjectiveCType;
exports.asStructPropertyName = asStructPropertyName;
exports.asGetterName = asGetterName;
exports.commandHasRequiredField = commandHasRequiredField;
exports.asObjectiveCBasicType = asObjectiveCBasicType;
exports.asObjectiveCNumberType = asObjectiveCNumberType;
exports.asTestIndex = asTestIndex;
exports.asObjectiveCClass = asObjectiveCClass;
exports.asObjectiveCType = asObjectiveCType;
exports.asStructPropertyName = asStructPropertyName;
exports.asGetterName = asGetterName;
exports.commandHasRequiredField = commandHasRequiredField;
Loading

0 comments on commit 2073285

Please sign in to comment.