Skip to content

Commit

Permalink
Update generated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Raju Palagummi authored and Raju Palagummi committed Jul 28, 2021
1 parent 40b054e commit 210cb15
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 0 deletions.
173 changes: 173 additions & 0 deletions examples/chip-tool/commands/tests/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -19456,6 +19456,178 @@ class Test_TC_WNCV_2_1 : public TestCommand
}
};

class Test_TC_BI_1_1 : public TestCommand
{
public:
Test_TC_BI_1_1() : TestCommand("Test_TC_BI_1_1"), mTestIndex(0) {}

/////////// TestCommand Interface /////////
void NextTest() override
{
CHIP_ERROR err = CHIP_NO_ERROR;

if (mTestCount == mTestIndex)
{
ChipLogProgress(chipTool, "Test_TC_BI_1_1: Test complete");
SetCommandExitStatus(CHIP_NO_ERROR);
}

// 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:
err = TestSendClusterBinaryInputBasicCommandReadAttribute_0();
break;
case 1:
err = TestSendClusterBinaryInputBasicCommandReadAttribute_1();
break;
}

if (CHIP_NO_ERROR != err)
{
ChipLogProgress(chipTool, "Test_TC_BI_1_1: %s", chip::ErrorStr(err));
SetCommandExitStatus(err);
}
}

private:
std::atomic_uint16_t mTestIndex;
const uint16_t mTestCount = 2;

//
// Tests methods
//

// Test read the global attribute: ClusterRevision
using SuccessCallback_0 = void (*)(void * context, uint16_t clusterRevision);
chip::Callback::Callback<SuccessCallback_0> mOnSuccessCallback_0{
OnTestSendClusterBinaryInputBasicCommandReadAttribute_0_SuccessResponse, this
};
chip::Callback::Callback<DefaultFailureCallback> mOnFailureCallback_0{
OnTestSendClusterBinaryInputBasicCommandReadAttribute_0_FailureResponse, this
};
bool mIsFailureExpected_0 = 0;

CHIP_ERROR TestSendClusterBinaryInputBasicCommandReadAttribute_0()
{
ChipLogProgress(chipTool, "Binary Input (Basic) - read the global attribute: ClusterRevision: Sending command...");

chip::Controller::BinaryInputBasicCluster cluster;
cluster.Associate(mDevice, 1);

CHIP_ERROR err = CHIP_NO_ERROR;

err = cluster.ReadAttributeClusterRevision(mOnSuccessCallback_0.Cancel(), mOnFailureCallback_0.Cancel());

return err;
}

static void OnTestSendClusterBinaryInputBasicCommandReadAttribute_0_FailureResponse(void * context, uint8_t status)
{
ChipLogProgress(chipTool, "Binary Input (Basic) - read the global attribute: ClusterRevision: Failure Response");

Test_TC_BI_1_1 * runner = reinterpret_cast<Test_TC_BI_1_1 *>(context);

if (runner->mIsFailureExpected_0 == false)
{
ChipLogError(chipTool, "Error: The test was expecting a success callback. Got failure callback");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}

runner->NextTest();
}

static void OnTestSendClusterBinaryInputBasicCommandReadAttribute_0_SuccessResponse(void * context, uint16_t clusterRevision)
{
ChipLogProgress(chipTool, "Binary Input (Basic) - read the global attribute: ClusterRevision: Success Response");

Test_TC_BI_1_1 * runner = reinterpret_cast<Test_TC_BI_1_1 *>(context);

if (runner->mIsFailureExpected_0 == true)
{
ChipLogError(chipTool, "Error: The test was expecting a failure callback. Got success callback");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}

if (clusterRevision != 1U)
{
ChipLogError(chipTool, "Error: Value mismatch. Expected: '%s'", "1");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}

runner->NextTest();
}

// Test reads back global attribute: ClusterRevision
using SuccessCallback_1 = void (*)(void * context, uint16_t clusterRevision);
chip::Callback::Callback<SuccessCallback_1> mOnSuccessCallback_1{
OnTestSendClusterBinaryInputBasicCommandReadAttribute_1_SuccessResponse, this
};
chip::Callback::Callback<DefaultFailureCallback> mOnFailureCallback_1{
OnTestSendClusterBinaryInputBasicCommandReadAttribute_1_FailureResponse, this
};
bool mIsFailureExpected_1 = 0;

CHIP_ERROR TestSendClusterBinaryInputBasicCommandReadAttribute_1()
{
ChipLogProgress(chipTool, "Binary Input (Basic) - reads back global attribute: ClusterRevision: Sending command...");

chip::Controller::BinaryInputBasicCluster cluster;
cluster.Associate(mDevice, 1);

CHIP_ERROR err = CHIP_NO_ERROR;

err = cluster.ReadAttributeClusterRevision(mOnSuccessCallback_1.Cancel(), mOnFailureCallback_1.Cancel());

return err;
}

static void OnTestSendClusterBinaryInputBasicCommandReadAttribute_1_FailureResponse(void * context, uint8_t status)
{
ChipLogProgress(chipTool, "Binary Input (Basic) - reads back global attribute: ClusterRevision: Failure Response");

Test_TC_BI_1_1 * runner = reinterpret_cast<Test_TC_BI_1_1 *>(context);

if (runner->mIsFailureExpected_1 == false)
{
ChipLogError(chipTool, "Error: The test was expecting a success callback. Got failure callback");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}

runner->NextTest();
}

static void OnTestSendClusterBinaryInputBasicCommandReadAttribute_1_SuccessResponse(void * context, uint16_t clusterRevision)
{
ChipLogProgress(chipTool, "Binary Input (Basic) - reads back global attribute: ClusterRevision: Success Response");

Test_TC_BI_1_1 * runner = reinterpret_cast<Test_TC_BI_1_1 *>(context);

if (runner->mIsFailureExpected_1 == true)
{
ChipLogError(chipTool, "Error: The test was expecting a failure callback. Got success callback");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}

if (clusterRevision != 1U)
{
ChipLogError(chipTool, "Error: Value mismatch. Expected: '%s'", "1");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}

runner->NextTest();
}
};

void registerCommandsTests(Commands & commands)
{
const char * clusterName = "Tests";
Expand Down Expand Up @@ -19483,6 +19655,7 @@ void registerCommandsTests(Commands & commands)
make_unique<Test_TC_CC_7>(),
make_unique<Test_TC_WNCV_1_1>(),
make_unique<Test_TC_WNCV_2_1>(),
make_unique<Test_TC_BI_1_1>(),
};

commands.Register(clusterName, clusterCommands);
Expand Down
37 changes: 37 additions & 0 deletions src/darwin/Framework/CHIPTests/CHIPClustersTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -3350,6 +3350,43 @@ - (void)testSendClusterTest_TC_WNCV_2_1_000010_ReadAttribute
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

- (void)testSendClusterTest_TC_BI_1_1_000000_ReadAttribute
{
XCTestExpectation * expectation = [self expectationWithDescription:@"read the global attribute: ClusterRevision"];
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
CHIPBinaryInputBasic * cluster = [[CHIPBinaryInputBasic 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], 1);
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}
- (void)testSendClusterTest_TC_BI_1_1_000001_ReadAttribute
{
XCTestExpectation * expectation = [self expectationWithDescription:@"reads back global attribute: ClusterRevision"];
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
CHIPBinaryInputBasic * cluster = [[CHIPBinaryInputBasic 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], 1);
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

- (void)testSendClusterAccountLoginReadAttributeClusterRevisionWithResponseHandler
{
XCTestExpectation * expectation =
Expand Down

0 comments on commit 210cb15

Please sign in to comment.