From 4023422a65f369b7f5a37f6248bc5c9041491723 Mon Sep 17 00:00:00 2001 From: "Josh V [Apple]" Date: Tue, 14 Dec 2021 21:38:24 -0800 Subject: [PATCH] Update Darwin zap files to handle tet logging. (#13002) --- .../CHIP/templates/clusters-tests.zapt | 10 ++++++ .../CHIP/templates/partials/test_cluster.zapt | 2 +- src/darwin/Framework/CHIP/templates/tests.js | 1 + .../Framework/CHIPTests/CHIPClustersTests.m | 34 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/darwin/Framework/CHIP/templates/clusters-tests.zapt b/src/darwin/Framework/CHIP/templates/clusters-tests.zapt index 153d4c76ee405a..f111d35b765750 100644 --- a/src/darwin/Framework/CHIP/templates/clusters-tests.zapt +++ b/src/darwin/Framework/CHIP/templates/clusters-tests.zapt @@ -39,6 +39,16 @@ void WaitForMs(XCTestExpectation * expectation, dispatch_queue_t queue, unsigned }); } +void Log(XCTestExpectation * expectation, dispatch_queue_t queue, NSString * message){ + NSLog(@"%@", message); + [expectation fulfill]; +} + +// Stub for User Prompts for XCTests to run. +void UserPrompt(XCTestExpectation * expectation, dispatch_queue_t queue, NSString * message) { + [expectation fulfill]; +} + void WaitForCommissionee(XCTestExpectation * expectation, dispatch_queue_t queue) { CHIPDeviceController * controller = [CHIPDeviceController sharedController]; diff --git a/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt b/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt index edd4515f47cb81..22546e86d60d4b 100644 --- a/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt +++ b/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt @@ -24,7 +24,7 @@ ResponseHandler {{> subscribeDataCallback}} = nil; {{#if (isTestOnlyCluster cluster)}} dispatch_queue_t queue = dispatch_get_main_queue(); - {{command}}(expectation, queue{{#chip_tests_item_parameters}}, {{definedValue}}{{/chip_tests_item_parameters}}); + {{command}}(expectation, queue{{#chip_tests_item_parameters}}, {{#if (isString type)}}@"{{/if}}{{definedValue}}{{#if (isString type)}}"{{/if}}{{/chip_tests_item_parameters}}); {{else}} CHIPDevice * device = GetConnectedDevice(); dispatch_queue_t queue = dispatch_get_main_queue(); diff --git a/src/darwin/Framework/CHIP/templates/tests.js b/src/darwin/Framework/CHIP/templates/tests.js index 1a2eaed22404d2..b718df0d8f4e30 100644 --- a/src/darwin/Framework/CHIP/templates/tests.js +++ b/src/darwin/Framework/CHIP/templates/tests.js @@ -170,6 +170,7 @@ function getTests() 'TestBasicInformation', 'TestGroupsCluster', 'TestIdentifyCluster', + 'TestLogCommands', 'TestOperationalCredentialsCluster', 'TestModeSelectCluster', ]; diff --git a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m index 4fd3677cd01583..ab8d0f2e1c5d3d 100644 --- a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m +++ b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m @@ -56,6 +56,15 @@ void WaitForMs(XCTestExpectation * expectation, dispatch_queue_t queue, unsigned }); } +void Log(XCTestExpectation * expectation, dispatch_queue_t queue, NSString * message) +{ + NSLog(@"%@", message); + [expectation fulfill]; +} + +// Stub for User Prompts for XCTests to run. +void UserPrompt(XCTestExpectation * expectation, dispatch_queue_t queue, NSString * message) { [expectation fulfill]; } + void WaitForCommissionee(XCTestExpectation * expectation, dispatch_queue_t queue) { CHIPDeviceController * controller = [CHIPDeviceController sharedController]; @@ -30969,6 +30978,31 @@ - (void)testSendClusterTestIdentifyCluster_000001_Identify [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; } +- (void)testSendClusterTestLogCommands_000000_WaitForCommissionee +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"Wait for the commissioned device to be retrieved"]; + + dispatch_queue_t queue = dispatch_get_main_queue(); + WaitForCommissionee(expectation, queue); + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} +- (void)testSendClusterTestLogCommands_000001_Log +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"Log a simple message"]; + + dispatch_queue_t queue = dispatch_get_main_queue(); + Log(expectation, queue, @"This is a simple message"); + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} +- (void)testSendClusterTestLogCommands_000002_UserPrompt +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"Do a simple user prompt message"]; + + dispatch_queue_t queue = dispatch_get_main_queue(); + UserPrompt(expectation, queue, @"This is a simple message"); + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} + - (void)testSendClusterTestOperationalCredentialsCluster_000000_WaitForCommissionee { XCTestExpectation * expectation = [self expectationWithDescription:@"Wait for the commissioned device to be retrieved"];