Skip to content

Commit

Permalink
Tests add test tc bi 1 1 (#8659)
Browse files Browse the repository at this point in the history
* Add Test_TC_BI_1_1.yaml to the tree and update the appropriate templates

* Update generated tests
  • Loading branch information
raju-apple authored and pull[bot] committed Sep 1, 2021
1 parent e00647d commit 98df1c8
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 2 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 @@ -19587,6 +19587,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 @@ -19614,6 +19786,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
3 changes: 2 additions & 1 deletion examples/chip-tool/templates/tests-commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "TestCommand.h"

{{>test_cluster tests="TV_TargetNavigatorCluster, TV_AudioOutputCluster, TV_ApplicationLauncherCluster, TV_KeypadInputCluster, TV_AccountLoginCluster, TV_ApplicationBasicCluster, TV_MediaPlaybackCluster, TV_TvChannelCluster, TV_LowPowerCluster, TV_MediaInputCluster, TestCluster, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1"}}
{{>test_cluster tests="TV_TargetNavigatorCluster, TV_AudioOutputCluster, TV_ApplicationLauncherCluster, TV_KeypadInputCluster, TV_AccountLoginCluster, TV_ApplicationBasicCluster, TV_MediaPlaybackCluster, TV_TvChannelCluster, TV_LowPowerCluster, TV_MediaInputCluster, TestCluster, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1"}}

void registerCommandsTests(Commands & commands)
{
Expand Down Expand Up @@ -33,6 +33,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
43 changes: 43 additions & 0 deletions src/app/tests/suites/Test_TC_BI_1_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: 12.1.1. [TC-BI-1.1] Global attributes with server as DUT

config:
cluster: "Binary Input (Basic)"
endpoint: 1

tests:
- label: "read the global attribute: ClusterRevision"
command: "readAttribute"
attribute: "Cluster Revision"
response:
value: 1

- label:
"write the default values to mandatory global attribute:
ClusterRevision"
disabled: true
command: "writeAttribute"
attribute: "Cluster Revision"
arguments:
value: 1
response:
error: 1

- label: "reads back global attribute: ClusterRevision"
command: "readAttribute"
attribute: "Cluster Revision"
response:
value: 1
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/templates/clusters-tests.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ CHIPDevice * GetPairedDevice(uint64_t deviceId)
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

{{>test_cluster tests="TestCluster, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1"}}
{{>test_cluster tests="TestCluster, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1"}}

{{#chip_client_clusters}}
{{#unless (isStrEqual "Test Cluster" name)}}
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 @@ -3393,6 +3393,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 98df1c8

Please sign in to comment.