From b6aad22c56525b8c2b172ba3e172873aae5ece0c Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 5 Nov 2021 19:51:12 -0400 Subject: [PATCH] Support empty lists in yaml tests. (#11496) --- .../templates/partials/test_cluster.zapt | 2 +- .../partials/test_cluster_command_value.zapt | 5 +- .../tests/suites/TestClusterComplexTypes.yaml | 12 ++ .../chip-tool/zap-generated/test/Commands.h | 113 ++++++++++++------ 4 files changed, 91 insertions(+), 41 deletions(-) diff --git a/examples/chip-tool/templates/partials/test_cluster.zapt b/examples/chip-tool/templates/partials/test_cluster.zapt index 3c6c6818b88631..62d9180f694aaf 100644 --- a/examples/chip-tool/templates/partials/test_cluster.zapt +++ b/examples/chip-tool/templates/partials/test_cluster.zapt @@ -207,7 +207,7 @@ class {{filename}}: public TestCommand {{/if}} VerifyOrReturn(CheckValue {{~#if isList}}AsListLength("{{>itemValue}}", {{>itemValue}}, {{expectedValue.length}}) - {{else if isArray}}AsList("{{>itemValue}}", {{>itemValue}}, {{expectedValue}}) + {{else if isArray}}AsList("{{>itemValue}}", {{>itemValue}}{{#if expectedValue.length}}, {{expectedValue}}{{/if}}) {{else if (isString type)}}AsString("{{>itemValue}}", {{>itemValue}}, "{{expectedValue}}") {{else}}<{{chipType}}>("{{>itemValue}}", {{>itemValue}}, {{expectedValue}}{{asTypeLiteralSuffix type}}) {{/if}} diff --git a/examples/chip-tool/templates/partials/test_cluster_command_value.zapt b/examples/chip-tool/templates/partials/test_cluster_command_value.zapt index 7c8b74e0d07f06..6d3c3c713c9daf 100644 --- a/examples/chip-tool/templates/partials/test_cluster_command_value.zapt +++ b/examples/chip-tool/templates/partials/test_cluster_command_value.zapt @@ -19,12 +19,15 @@ {{! forceNotList=true because we really want the type of a single item here. Similarly, forceNotOptional=true and forceNotNullable=true because we have accounted for those already. }} + {{#if definedValue.length}} {{zapTypeToEncodableClusterObjectType type ns=ns forceNotList=true forceNotNullable=true forceNotOptional=true}} {{asLowerCamelCase label}}List[{{definedValue.length}}]; {{#each definedValue}} {{>commandValue ns=../ns container=(concat (asLowerCamelCase ../label) "List[" @index "]") definedValue=. type=../type ignore=true}} {{/each}} {{container}}{{#unless ignore}}.{{asLowerCamelCase label}}{{/unless}} = {{asLowerCamelCase label}}List; - + {{else}} + {{container}}{{#unless ignore}}.{{asLowerCamelCase label}}{{/unless}} = chip::app::DataModel::List<{{zapTypeToEncodableClusterObjectType type ns=ns forceNotList=true forceNotNullable=true forceNotOptional=true}}>(); + {{/if}} {{else}} {{#if_is_struct type}} diff --git a/src/app/tests/suites/TestClusterComplexTypes.yaml b/src/app/tests/suites/TestClusterComplexTypes.yaml index e8676697c43a84..8241a66258ba69 100644 --- a/src/app/tests/suites/TestClusterComplexTypes.yaml +++ b/src/app/tests/suites/TestClusterComplexTypes.yaml @@ -253,6 +253,18 @@ tests: - name: "arg1" value: [9, 8, 7, 6, 5, 4, 3, 2, 1] + - label: + "Send Test Command With empty List of INT8U and get an empty list back" + command: "testListInt8UReverseRequest" + arguments: + values: + - name: "arg1" + value: [] + response: + values: + - name: "arg1" + value: [] + - label: "Send Test Command With List of Struct Argument and arg1.b of first item is true" diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index eee8515be32114..64f5774eb13181 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -25644,27 +25644,32 @@ class TestClusterComplexTypes : public TestCommand err = TestSendTestCommandWithListOfInt8uAndGetItReversed_4(); break; case 5: - ChipLogProgress( - chipTool, " ***** Test Step 5 : Send Test Command With List of Struct Argument and arg1.b of first item is true\n"); - err = TestSendTestCommandWithListOfStructArgumentAndArg1bOfFirstItemIsTrue_5(); + ChipLogProgress(chipTool, + " ***** Test Step 5 : Send Test Command With empty List of INT8U and get an empty list back\n"); + err = TestSendTestCommandWithEmptyListOfInt8uAndGetAnEmptyListBack_5(); break; case 6: ChipLogProgress( - chipTool, - " ***** Test Step 6 : Send Test Command With List of Struct Argument and arg1.b of first item is false\n"); - err = TestSendTestCommandWithListOfStructArgumentAndArg1bOfFirstItemIsFalse_6(); + chipTool, " ***** Test Step 6 : Send Test Command With List of Struct Argument and arg1.b of first item is true\n"); + err = TestSendTestCommandWithListOfStructArgumentAndArg1bOfFirstItemIsTrue_6(); break; case 7: - ChipLogProgress(chipTool, " ***** Test Step 7 : Send Test Command with optional arg set.\n"); - err = TestSendTestCommandWithOptionalArgSet_7(); + ChipLogProgress( + chipTool, + " ***** Test Step 7 : Send Test Command With List of Struct Argument and arg1.b of first item is false\n"); + err = TestSendTestCommandWithListOfStructArgumentAndArg1bOfFirstItemIsFalse_7(); break; case 8: - ChipLogProgress(chipTool, " ***** Test Step 8 : Send Test Command without its optional arg.\n"); - err = TestSendTestCommandWithoutItsOptionalArg_8(); + ChipLogProgress(chipTool, " ***** Test Step 8 : Send Test Command with optional arg set.\n"); + err = TestSendTestCommandWithOptionalArgSet_8(); break; case 9: - ChipLogProgress(chipTool, " ***** Test Step 9 : Send Test Command with optional arg set to null.\n"); - err = TestSendTestCommandWithOptionalArgSetToNull_9(); + ChipLogProgress(chipTool, " ***** Test Step 9 : Send Test Command without its optional arg.\n"); + err = TestSendTestCommandWithoutItsOptionalArg_9(); + break; + case 10: + ChipLogProgress(chipTool, " ***** Test Step 10 : Send Test Command with optional arg set to null.\n"); + err = TestSendTestCommandWithOptionalArgSetToNull_10(); break; } @@ -25677,7 +25682,7 @@ class TestClusterComplexTypes : public TestCommand private: std::atomic_uint16_t mTestIndex; - const uint16_t mTestCount = 10; + const uint16_t mTestCount = 11; // // Tests methods @@ -25874,7 +25879,37 @@ class TestClusterComplexTypes : public TestCommand NextTest(); } - CHIP_ERROR TestSendTestCommandWithListOfStructArgumentAndArg1bOfFirstItemIsTrue_5() + CHIP_ERROR TestSendTestCommandWithEmptyListOfInt8uAndGetAnEmptyListBack_5() + { + chip::Controller::TestClusterClusterTest cluster; + cluster.Associate(mDevice, 1); + + using requestType = chip::app::Clusters::TestCluster::Commands::TestListInt8UReverseRequest::Type; + using responseType = chip::app::Clusters::TestCluster::Commands::TestListInt8UReverseResponse::DecodableType; + + chip::app::Clusters::TestCluster::Commands::TestListInt8UReverseRequest::Type request; + + request.arg1 = chip::app::DataModel::List(); + + auto success = [](void * context, const responseType & data) { + (static_cast(context))->OnSuccessResponse_5(data.arg1); + }; + + auto failure = [](void * context, EmberAfStatus status) { + (static_cast(context))->OnFailureResponse_5(status); + }; + return cluster.InvokeCommand(request, this, success, failure); + } + + void OnFailureResponse_5(uint8_t status) { ThrowFailureResponse(); } + + void OnSuccessResponse_5(const chip::app::DataModel::DecodableList & arg1) + { + VerifyOrReturn(CheckValueAsList("arg1", arg1)); + NextTest(); + } + + CHIP_ERROR TestSendTestCommandWithListOfStructArgumentAndArg1bOfFirstItemIsTrue_6() { chip::Controller::TestClusterClusterTest cluster; cluster.Associate(mDevice, 1); @@ -25903,24 +25938,24 @@ class TestClusterComplexTypes : public TestCommand request.arg1 = arg1List; auto success = [](void * context, const responseType & data) { - (static_cast(context))->OnSuccessResponse_5(data.value); + (static_cast(context))->OnSuccessResponse_6(data.value); }; auto failure = [](void * context, EmberAfStatus status) { - (static_cast(context))->OnFailureResponse_5(status); + (static_cast(context))->OnFailureResponse_6(status); }; return cluster.InvokeCommand(request, this, success, failure); } - void OnFailureResponse_5(uint8_t status) { ThrowFailureResponse(); } + void OnFailureResponse_6(uint8_t status) { ThrowFailureResponse(); } - void OnSuccessResponse_5(bool value) + void OnSuccessResponse_6(bool value) { VerifyOrReturn(CheckValue("value", value, true)); NextTest(); } - CHIP_ERROR TestSendTestCommandWithListOfStructArgumentAndArg1bOfFirstItemIsFalse_6() + CHIP_ERROR TestSendTestCommandWithListOfStructArgumentAndArg1bOfFirstItemIsFalse_7() { chip::Controller::TestClusterClusterTest cluster; cluster.Associate(mDevice, 1); @@ -25949,24 +25984,24 @@ class TestClusterComplexTypes : public TestCommand request.arg1 = arg1List; auto success = [](void * context, const responseType & data) { - (static_cast(context))->OnSuccessResponse_6(data.value); + (static_cast(context))->OnSuccessResponse_7(data.value); }; auto failure = [](void * context, EmberAfStatus status) { - (static_cast(context))->OnFailureResponse_6(status); + (static_cast(context))->OnFailureResponse_7(status); }; return cluster.InvokeCommand(request, this, success, failure); } - void OnFailureResponse_6(uint8_t status) { ThrowFailureResponse(); } + void OnFailureResponse_7(uint8_t status) { ThrowFailureResponse(); } - void OnSuccessResponse_6(bool value) + void OnSuccessResponse_7(bool value) { VerifyOrReturn(CheckValue("value", value, false)); NextTest(); } - CHIP_ERROR TestSendTestCommandWithOptionalArgSet_7() + CHIP_ERROR TestSendTestCommandWithOptionalArgSet_8() { chip::Controller::TestClusterClusterTest cluster; cluster.Associate(mDevice, 1); @@ -25979,18 +26014,18 @@ class TestClusterComplexTypes : public TestCommand auto success = [](void * context, const responseType & data) { (static_cast(context)) - ->OnSuccessResponse_7(data.wasPresent, data.wasNull, data.value, data.originalValue); + ->OnSuccessResponse_8(data.wasPresent, data.wasNull, data.value, data.originalValue); }; auto failure = [](void * context, EmberAfStatus status) { - (static_cast(context))->OnFailureResponse_7(status); + (static_cast(context))->OnFailureResponse_8(status); }; return cluster.InvokeCommand(request, this, success, failure); } - void OnFailureResponse_7(uint8_t status) { ThrowFailureResponse(); } + void OnFailureResponse_8(uint8_t status) { ThrowFailureResponse(); } - void OnSuccessResponse_7(bool wasPresent, const chip::Optional & wasNull, const chip::Optional & value, + void OnSuccessResponse_8(bool wasPresent, const chip::Optional & wasNull, const chip::Optional & value, const chip::Optional> & originalValue) { VerifyOrReturn(CheckValue("wasPresent", wasPresent, true)); @@ -26007,7 +26042,7 @@ class TestClusterComplexTypes : public TestCommand NextTest(); } - CHIP_ERROR TestSendTestCommandWithoutItsOptionalArg_8() + CHIP_ERROR TestSendTestCommandWithoutItsOptionalArg_9() { chip::Controller::TestClusterClusterTest cluster; cluster.Associate(mDevice, 1); @@ -26019,18 +26054,18 @@ class TestClusterComplexTypes : public TestCommand auto success = [](void * context, const responseType & data) { (static_cast(context)) - ->OnSuccessResponse_8(data.wasPresent, data.wasNull, data.value, data.originalValue); + ->OnSuccessResponse_9(data.wasPresent, data.wasNull, data.value, data.originalValue); }; auto failure = [](void * context, EmberAfStatus status) { - (static_cast(context))->OnFailureResponse_8(status); + (static_cast(context))->OnFailureResponse_9(status); }; return cluster.InvokeCommand(request, this, success, failure); } - void OnFailureResponse_8(uint8_t status) { ThrowFailureResponse(); } + void OnFailureResponse_9(uint8_t status) { ThrowFailureResponse(); } - void OnSuccessResponse_8(bool wasPresent, const chip::Optional & wasNull, const chip::Optional & value, + void OnSuccessResponse_9(bool wasPresent, const chip::Optional & wasNull, const chip::Optional & value, const chip::Optional> & originalValue) { VerifyOrReturn(CheckValue("wasPresent", wasPresent, false)); @@ -26038,7 +26073,7 @@ class TestClusterComplexTypes : public TestCommand NextTest(); } - CHIP_ERROR TestSendTestCommandWithOptionalArgSetToNull_9() + CHIP_ERROR TestSendTestCommandWithOptionalArgSetToNull_10() { chip::Controller::TestClusterClusterTest cluster; cluster.Associate(mDevice, 1); @@ -26051,19 +26086,19 @@ class TestClusterComplexTypes : public TestCommand auto success = [](void * context, const responseType & data) { (static_cast(context)) - ->OnSuccessResponse_9(data.wasPresent, data.wasNull, data.value, data.originalValue); + ->OnSuccessResponse_10(data.wasPresent, data.wasNull, data.value, data.originalValue); }; auto failure = [](void * context, EmberAfStatus status) { - (static_cast(context))->OnFailureResponse_9(status); + (static_cast(context))->OnFailureResponse_10(status); }; return cluster.InvokeCommand(request, this, success, failure); } - void OnFailureResponse_9(uint8_t status) { ThrowFailureResponse(); } + void OnFailureResponse_10(uint8_t status) { ThrowFailureResponse(); } - void OnSuccessResponse_9(bool wasPresent, const chip::Optional & wasNull, const chip::Optional & value, - const chip::Optional> & originalValue) + void OnSuccessResponse_10(bool wasPresent, const chip::Optional & wasNull, const chip::Optional & value, + const chip::Optional> & originalValue) { VerifyOrReturn(CheckValue("wasPresent", wasPresent, true));