diff --git a/examples/chip-tool/commands/tests/Commands.h b/examples/chip-tool/commands/tests/Commands.h index dc586d8e4b5a28..3a439e9e96c078 100644 --- a/examples/chip-tool/commands/tests/Commands.h +++ b/examples/chip-tool/commands/tests/Commands.h @@ -346,6 +346,9 @@ class TestCluster : public TestCommand case 100: err = TestSendClusterTestClusterCommandWriteAttribute_100(); break; + case 101: + err = TestSendClusterTestClusterCommandTest_101(); + break; } if (CHIP_NO_ERROR != err) @@ -357,7 +360,7 @@ class TestCluster : public TestCommand private: std::atomic_uint16_t mTestIndex; - const uint16_t mTestCount = 101; + const uint16_t mTestCount = 102; // // Tests methods @@ -7829,6 +7832,75 @@ class TestCluster : public TestCommand runner->NextTest(); } + + // Test Send Test Command to unsupported endpoint + typedef void (*SuccessCallback_101)(void * context); + chip::Callback::Callback * mOnSuccessCallback_101 = nullptr; + chip::Callback::Callback * mOnFailureCallback_101 = nullptr; + bool mIsFailureExpected_101 = 1; + + CHIP_ERROR TestSendClusterTestClusterCommandTest_101() + { + ChipLogProgress(chipTool, "Test Cluster - Send Test Command to unsupported endpoint: Sending command..."); + + mOnFailureCallback_101 = + new chip::Callback::Callback(OnTestSendClusterTestClusterCommandTest_101_FailureResponse, this); + mOnSuccessCallback_101 = + new chip::Callback::Callback(OnTestSendClusterTestClusterCommandTest_101_SuccessResponse, this); + + chip::Controller::TestClusterCluster cluster; + cluster.Associate(mDevice, 200); + + CHIP_ERROR err = CHIP_NO_ERROR; + + err = cluster.Test(mOnSuccessCallback_101->Cancel(), mOnFailureCallback_101->Cancel()); + + if (CHIP_NO_ERROR != err) + { + delete mOnFailureCallback_101; + delete mOnSuccessCallback_101; + } + + return err; + } + + static void OnTestSendClusterTestClusterCommandTest_101_FailureResponse(void * context, uint8_t status) + { + ChipLogProgress(chipTool, "Test Cluster - Send Test Command to unsupported endpoint: Failure Response"); + + TestCluster * runner = reinterpret_cast(context); + + delete runner->mOnFailureCallback_101; + delete runner->mOnSuccessCallback_101; + + if (runner->mIsFailureExpected_101 == false) + { + ChipLogError(chipTool, "Error: The test was expecting a success callback. Got failure callback"); + runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL); + return; + } + + runner->NextTest(); + } + + static void OnTestSendClusterTestClusterCommandTest_101_SuccessResponse(void * context) + { + ChipLogProgress(chipTool, "Test Cluster - Send Test Command to unsupported endpoint: Success Response"); + + TestCluster * runner = reinterpret_cast(context); + + delete runner->mOnFailureCallback_101; + delete runner->mOnSuccessCallback_101; + + if (runner->mIsFailureExpected_101 == true) + { + ChipLogError(chipTool, "Error: The test was expecting a failure callback. Got success callback"); + runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL); + return; + } + + runner->NextTest(); + } }; class Test_3_1_1 : public TestCommand diff --git a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m index 4ac59b6403c8c9..6de836d548b506 100644 --- a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m +++ b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m @@ -2042,6 +2042,23 @@ - (void)testSendClusterTestCluster_000100_WriteAttribute [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; } +- (void)testSendClusterTestCluster_000101_Test +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"Send Test Command to unsupported endpoint"]; + CHIPDevice * device = GetPairedDevice(kDeviceId); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestCluster * cluster = [[CHIPTestCluster alloc] initWithDevice:device endpoint:200 queue:queue]; + XCTAssertNotNil(cluster); + + [cluster test:^(NSError * err, NSDictionary * values) { + NSLog(@"Send Test Command to unsupported endpoint Error: %@", err); + + XCTAssertEqual(err.code, 1); + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} - (void)testSendClusterTest_3_1_1_000000_ReadAttribute {