diff --git a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m index 0b396b377d145c..947d18b98c5fdb 100644 --- a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m +++ b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m @@ -6451,6 +6451,71 @@ - (void)testSendClusterTest_TC_DM_1_1_000017_ReadAttribute [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; } +- (void)testSendClusterTest_TC_EMR_1_1_000000_ReadAttribute +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"read the global attribute: ClusterRevision"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestElectricalMeasurement * cluster = [[CHIPTestElectricalMeasurement alloc] initWithDevice:device endpoint:1 queue:queue]; + XCTAssertNotNil(cluster); + + [cluster readAttributeClusterRevisionWithResponseHandler:^(NSError * err, NSDictionary * values) { + NSLog(@"read the global attribute: ClusterRevision Error: %@", err); + + XCTAssertEqual(err.code, 0); + + XCTAssertEqual([values[@"value"] unsignedShortValue], 3U); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} +- (void)testSendClusterTest_TC_EMR_1_1_000001_WriteAttribute +{ + XCTestExpectation * expectation = + [self expectationWithDescription:@"write the default values to mandatory global attribute: ClusterRevision"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestElectricalMeasurement * cluster = [[CHIPTestElectricalMeasurement alloc] initWithDevice:device endpoint:1 queue:queue]; + XCTAssertNotNil(cluster); + + uint16_t clusterRevisionArgument = 1U; + [cluster + writeAttributeClusterRevisionWithValue:clusterRevisionArgument + responseHandler:^(NSError * err, NSDictionary * values) { + NSLog(@"write the default values to mandatory global attribute: ClusterRevision Error: %@", err); + + XCTAssertEqual(err.code, 1); + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} +- (void)testSendClusterTest_TC_EMR_1_1_000002_ReadAttribute +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"reads back global attribute: ClusterRevision"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestElectricalMeasurement * cluster = [[CHIPTestElectricalMeasurement alloc] initWithDevice:device endpoint:1 queue:queue]; + XCTAssertNotNil(cluster); + + [cluster readAttributeClusterRevisionWithResponseHandler:^(NSError * err, NSDictionary * values) { + NSLog(@"reads back global attribute: ClusterRevision Error: %@", err); + + XCTAssertEqual(err.code, 0); + + XCTAssertEqual([values[@"value"] unsignedShortValue], 3U); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} + - (void)testSendClusterTest_TC_FLW_1_1_000000_WriteAttribute { XCTestExpectation * expectation = diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index 85eab70e541b24..756016ae754f4b 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -10309,6 +10309,151 @@ class Test_TC_DM_3_1 : public TestCommand // }; +class Test_TC_EMR_1_1 : public TestCommand +{ +public: + Test_TC_EMR_1_1() : TestCommand("Test_TC_EMR_1_1"), mTestIndex(0) {} + + /////////// TestCommand Interface ///////// + void NextTest() override + { + CHIP_ERROR err = CHIP_NO_ERROR; + + if (0 == mTestIndex) + { + ChipLogProgress(chipTool, " **** Test Start: Test_TC_EMR_1_1\n"); + } + + if (mTestCount == mTestIndex) + { + ChipLogProgress(chipTool, " **** Test Complete: Test_TC_EMR_1_1\n"); + SetCommandExitStatus(CHIP_NO_ERROR); + return; + } + + Wait(); + + // Ensure we increment mTestIndex before we start running the relevant + // command. That way if we lose the timeslice after we send the message + // but before our function call returns, we won't end up with an + // incorrect mTestIndex value observed when we get the response. + switch (mTestIndex++) + { + case 0: + ChipLogProgress(chipTool, " ***** Test Step 0 : read the global attribute: ClusterRevision\n"); + err = TestReadTheGlobalAttributeClusterRevision_0(); + break; + case 1: + ChipLogProgress(chipTool, + " ***** Test Step 1 : write the default values to mandatory global attribute: ClusterRevision\n"); + err = TestWriteTheDefaultValuesToMandatoryGlobalAttributeClusterRevision_1(); + break; + case 2: + ChipLogProgress(chipTool, " ***** Test Step 2 : reads back global attribute: ClusterRevision\n"); + err = TestReadsBackGlobalAttributeClusterRevision_2(); + break; + } + + if (CHIP_NO_ERROR != err) + { + ChipLogError(chipTool, " ***** Test Failure: %s\n", chip::ErrorStr(err)); + SetCommandExitStatus(err); + } + } + +private: + std::atomic_uint16_t mTestIndex; + const uint16_t mTestCount = 3; + + chip::Callback::Callback mOnFailureCallback_0{ OnFailureCallback_0, this }; + chip::Callback::Callback mOnSuccessCallback_0{ OnSuccessCallback_0, this }; + chip::Callback::Callback mOnFailureCallback_1{ OnFailureCallback_1, this }; + chip::Callback::Callback mOnSuccessCallback_1{ OnSuccessCallback_1, this }; + chip::Callback::Callback mOnFailureCallback_2{ OnFailureCallback_2, this }; + chip::Callback::Callback mOnSuccessCallback_2{ OnSuccessCallback_2, this }; + + static void OnFailureCallback_0(void * context, uint8_t status) + { + (static_cast(context))->OnFailureResponse_0(status); + } + + static void OnSuccessCallback_0(void * context, uint16_t clusterRevision) + { + (static_cast(context))->OnSuccessResponse_0(clusterRevision); + } + + static void OnFailureCallback_1(void * context, uint8_t status) + { + (static_cast(context))->OnFailureResponse_1(status); + } + + static void OnSuccessCallback_1(void * context, uint16_t clusterRevision) + { + (static_cast(context))->OnSuccessResponse_1(clusterRevision); + } + + static void OnFailureCallback_2(void * context, uint8_t status) + { + (static_cast(context))->OnFailureResponse_2(status); + } + + static void OnSuccessCallback_2(void * context, uint16_t clusterRevision) + { + (static_cast(context))->OnSuccessResponse_2(clusterRevision); + } + + // + // Tests methods + // + + CHIP_ERROR TestReadTheGlobalAttributeClusterRevision_0() + { + chip::Controller::ElectricalMeasurementClusterTest cluster; + cluster.Associate(mDevice, 1); + + return cluster.ReadAttributeClusterRevision(mOnSuccessCallback_0.Cancel(), mOnFailureCallback_0.Cancel()); + } + + void OnFailureResponse_0(uint8_t status) { ThrowFailureResponse(); } + + void OnSuccessResponse_0(uint16_t clusterRevision) + { + VerifyOrReturn(CheckValue("clusterRevision", clusterRevision, 3U)); + NextTest(); + } + + CHIP_ERROR TestWriteTheDefaultValuesToMandatoryGlobalAttributeClusterRevision_1() + { + chip::Controller::ElectricalMeasurementClusterTest cluster; + cluster.Associate(mDevice, 1); + + uint16_t clusterRevisionArgument = 1U; + + return cluster.WriteAttributeClusterRevision(mOnSuccessCallback_1.Cancel(), mOnFailureCallback_1.Cancel(), + clusterRevisionArgument); + } + + void OnFailureResponse_1(uint8_t status) { NextTest(); } + + void OnSuccessResponse_1(uint16_t clusterRevision) { ThrowSuccessResponse(); } + + CHIP_ERROR TestReadsBackGlobalAttributeClusterRevision_2() + { + chip::Controller::ElectricalMeasurementClusterTest cluster; + cluster.Associate(mDevice, 1); + + return cluster.ReadAttributeClusterRevision(mOnSuccessCallback_2.Cancel(), mOnFailureCallback_2.Cancel()); + } + + void OnFailureResponse_2(uint8_t status) { ThrowFailureResponse(); } + + void OnSuccessResponse_2(uint16_t clusterRevision) + { + VerifyOrReturn(CheckValue("clusterRevision", clusterRevision, 3U)); + NextTest(); + } +}; + class Test_TC_FLW_1_1 : public TestCommand { public: @@ -24349,6 +24494,7 @@ void registerCommandsTests(Commands & commands) make_unique(), make_unique(), make_unique(), + make_unique(), make_unique(), make_unique(), make_unique(),