diff --git a/examples/chip-tool/commands/tests/TestCommand.cpp b/examples/chip-tool/commands/tests/TestCommand.cpp index 9dcf8d036d7e35..094e5e505db943 100644 --- a/examples/chip-tool/commands/tests/TestCommand.cpp +++ b/examples/chip-tool/commands/tests/TestCommand.cpp @@ -127,7 +127,8 @@ bool TestCommand::CheckValueAsString(const char * itemName, const chip::CharSpan const chip::CharSpan expectedArgument(expected, strlen(expected)); if (!current.data_equal(expectedArgument)) { - Exit(std::string(itemName) + " value mismatch, expecting " + std::string(expected)); + Exit(std::string(itemName) + " value mismatch, expected '" + expected + "' but got '" + + std::string(current.data(), current.size()) + "'"); return false; } diff --git a/examples/chip-tool/commands/tests/TestCommand.h b/examples/chip-tool/commands/tests/TestCommand.h index b13792f2e337d3..0cf358d260a559 100644 --- a/examples/chip-tool/commands/tests/TestCommand.h +++ b/examples/chip-tool/commands/tests/TestCommand.h @@ -117,7 +117,7 @@ class TestCommand : public CHIPCommand template ::value, int> = 0> bool CheckValue(const char * itemName, T current, U expected) { - return CheckValue(itemName, to_underlying(current), expected); + return CheckValue(itemName, chip::to_underlying(current), expected); } /** diff --git a/examples/chip-tool/templates/partials/test_cluster_value_equals.zapt b/examples/chip-tool/templates/partials/test_cluster_value_equals.zapt index cae2a4c1fee2da..9fe0a9af1faf41 100644 --- a/examples/chip-tool/templates/partials/test_cluster_value_equals.zapt +++ b/examples/chip-tool/templates/partials/test_cluster_value_equals.zapt @@ -17,7 +17,16 @@ VerifyOrReturn(CheckNoMoreListItems("{{label}}", iter, {{expected.length}})); {{else}} {{#if_is_struct type}} - {{! NOT SUPPORTED YET }} + {{! Iterate over the actual types in the struct, so we pick up the right + type/optionality/nullability information for them for our recursive + call. }} + {{#zcl_struct_items_by_struct_name type}} + {{#if (expectedValueHasProp ../expected (asLowerCamelCase label))}} + {{>valueEquals label=(concat ../label "." (asLowerCamelCase label)) actual=(concat ../actual "." (asLowerCamelCase label)) expected=(lookup ../expected (asLowerCamelCase label))}} + {{/if}} + {{/zcl_struct_items_by_struct_name}} + {{! Maybe we should add a check for properties in the expected object (other + than "global") that are not present in the struct ? }} {{else}} VerifyOrReturn(CheckValue {{~#if (isString type)}}AsString("{{label}}", {{actual}}, "{{expected}}") diff --git a/src/app/tests/suites/TV_AudioOutputCluster.yaml b/src/app/tests/suites/TV_AudioOutputCluster.yaml index f6116a67fa399f..642f02b61485b8 100644 --- a/src/app/tests/suites/TV_AudioOutputCluster.yaml +++ b/src/app/tests/suites/TV_AudioOutputCluster.yaml @@ -25,9 +25,9 @@ tests: response: value: [ - { index: 1, outputType: 0, name: 12 }, - { index: 2, outputType: 0, name: 12 }, - { index: 3, outputType: 0, name: 12 }, + { index: 1, outputType: 0, name: "exampleName" }, + { index: 2, outputType: 0, name: "exampleName" }, + { index: 3, outputType: 0, name: "exampleName" }, ] - label: "Select Output Command" diff --git a/src/app/tests/suites/TV_MediaInputCluster.yaml b/src/app/tests/suites/TV_MediaInputCluster.yaml index b07076486f99ff..fe7fe12e9a44ce 100644 --- a/src/app/tests/suites/TV_MediaInputCluster.yaml +++ b/src/app/tests/suites/TV_MediaInputCluster.yaml @@ -25,8 +25,18 @@ tests: response: value: [ - { index: 1, inputType: 4, name: 12, description: 19 }, - { index: 2, inputType: 4, name: 12, description: 19 }, + { + index: 1, + inputType: 4, + name: "exampleName", + description: "exampleDescription", + }, + { + index: 2, + inputType: 4, + name: "exampleName", + description: "exampleDescription", + }, ] - label: "Select Input Command" diff --git a/src/app/tests/suites/TV_TargetNavigatorCluster.yaml b/src/app/tests/suites/TV_TargetNavigatorCluster.yaml index 807f3e8010270d..83d85cdfd3723f 100644 --- a/src/app/tests/suites/TV_TargetNavigatorCluster.yaml +++ b/src/app/tests/suites/TV_TargetNavigatorCluster.yaml @@ -23,7 +23,11 @@ tests: command: "readAttribute" attribute: "Target Navigator List" response: - value: [{ identifier: 1, name: 12 }, { identifier: 2, name: 12 }] + value: + [ + { identifier: 1, name: "exampleName" }, + { identifier: 2, name: "exampleName" }, + ] - label: "Navigate Target Command" command: "NavigateTarget" diff --git a/src/app/tests/suites/TV_TvChannelCluster.yaml b/src/app/tests/suites/TV_TvChannelCluster.yaml index 31d92d203696c0..289fb04de607d7 100644 --- a/src/app/tests/suites/TV_TvChannelCluster.yaml +++ b/src/app/tests/suites/TV_TvChannelCluster.yaml @@ -28,16 +28,16 @@ tests: { majorNumber: 1, minorNumber: 2, - name: 12, - callSign: 13, - affiliateCallSign: 13, + name: "exampleName", + callSign: "exampleCSign", + affiliateCallSign: "exampleASign", }, { majorNumber: 2, minorNumber: 3, - name: 12, - callSign: 13, - affiliateCallSign: 13, + name: "exampleName", + callSign: "exampleCSign", + affiliateCallSign: "exampleASign", }, ] # TODO: Enable the test once struct response is supported diff --git a/src/app/zap-templates/common/ClusterTestGeneration.js b/src/app/zap-templates/common/ClusterTestGeneration.js index 79203cc7ce10e2..f67e4c42ff4147 100644 --- a/src/app/zap-templates/common/ClusterTestGeneration.js +++ b/src/app/zap-templates/common/ClusterTestGeneration.js @@ -591,6 +591,11 @@ function isLiteralNull(value, options) return (value === null) || (value instanceof NullObject); } +function expectedValueHasProp(value, name) +{ + return name in value; +} + // // Module exports // @@ -602,3 +607,4 @@ exports.chip_tests_item_response_parameters = chip_tests_item_response_parameter exports.chip_tests_pics = chip_tests_pics; exports.isTestOnlyCluster = isTestOnlyCluster; exports.isLiteralNull = isLiteralNull; +exports.expectedValueHasProp = expectedValueHasProp; diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index 96fdfdf1782de3..e97915bca48643 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -23205,7 +23205,11 @@ class TV_TargetNavigatorCluster : public TestCommand { auto iter = targetNavigatorList.begin(); VerifyOrReturn(CheckNextListItemDecodes("targetNavigatorList", iter, 0)); + VerifyOrReturn(CheckValue<>("targetNavigatorList[0].identifier", iter.GetValue().identifier, 1)); + VerifyOrReturn(CheckValueAsString("targetNavigatorList[0].name", iter.GetValue().name, "exampleName")); VerifyOrReturn(CheckNextListItemDecodes("targetNavigatorList", iter, 1)); + VerifyOrReturn(CheckValue<>("targetNavigatorList[1].identifier", iter.GetValue().identifier, 2)); + VerifyOrReturn(CheckValueAsString("targetNavigatorList[1].name", iter.GetValue().name, "exampleName")); VerifyOrReturn(CheckNoMoreListItems("targetNavigatorList", iter, 2)); NextTest(); } @@ -23332,8 +23336,17 @@ class TV_AudioOutputCluster : public TestCommand { auto iter = audioOutputList.begin(); VerifyOrReturn(CheckNextListItemDecodes("audioOutputList", iter, 0)); + VerifyOrReturn(CheckValue<>("audioOutputList[0].index", iter.GetValue().index, 1)); + VerifyOrReturn(CheckValue<>("audioOutputList[0].outputType", iter.GetValue().outputType, 0)); + VerifyOrReturn(CheckValueAsString("audioOutputList[0].name", iter.GetValue().name, "exampleName")); VerifyOrReturn(CheckNextListItemDecodes("audioOutputList", iter, 1)); + VerifyOrReturn(CheckValue<>("audioOutputList[1].index", iter.GetValue().index, 2)); + VerifyOrReturn(CheckValue<>("audioOutputList[1].outputType", iter.GetValue().outputType, 0)); + VerifyOrReturn(CheckValueAsString("audioOutputList[1].name", iter.GetValue().name, "exampleName")); VerifyOrReturn(CheckNextListItemDecodes("audioOutputList", iter, 2)); + VerifyOrReturn(CheckValue<>("audioOutputList[2].index", iter.GetValue().index, 3)); + VerifyOrReturn(CheckValue<>("audioOutputList[2].outputType", iter.GetValue().outputType, 0)); + VerifyOrReturn(CheckValueAsString("audioOutputList[2].name", iter.GetValue().name, "exampleName")); VerifyOrReturn(CheckNoMoreListItems("audioOutputList", iter, 3)); NextTest(); } @@ -24515,7 +24528,17 @@ class TV_TvChannelCluster : public TestCommand { auto iter = tvChannelList.begin(); VerifyOrReturn(CheckNextListItemDecodes("tvChannelList", iter, 0)); + VerifyOrReturn(CheckValue<>("tvChannelList[0].majorNumber", iter.GetValue().majorNumber, 1U)); + VerifyOrReturn(CheckValue<>("tvChannelList[0].minorNumber", iter.GetValue().minorNumber, 2U)); + VerifyOrReturn(CheckValueAsString("tvChannelList[0].name", iter.GetValue().name, "exampleName")); + VerifyOrReturn(CheckValueAsString("tvChannelList[0].callSign", iter.GetValue().callSign, "exampleCSign")); + VerifyOrReturn(CheckValueAsString("tvChannelList[0].affiliateCallSign", iter.GetValue().affiliateCallSign, "exampleASign")); VerifyOrReturn(CheckNextListItemDecodes("tvChannelList", iter, 1)); + VerifyOrReturn(CheckValue<>("tvChannelList[1].majorNumber", iter.GetValue().majorNumber, 2U)); + VerifyOrReturn(CheckValue<>("tvChannelList[1].minorNumber", iter.GetValue().minorNumber, 3U)); + VerifyOrReturn(CheckValueAsString("tvChannelList[1].name", iter.GetValue().name, "exampleName")); + VerifyOrReturn(CheckValueAsString("tvChannelList[1].callSign", iter.GetValue().callSign, "exampleCSign")); + VerifyOrReturn(CheckValueAsString("tvChannelList[1].affiliateCallSign", iter.GetValue().affiliateCallSign, "exampleASign")); VerifyOrReturn(CheckNoMoreListItems("tvChannelList", iter, 2)); NextTest(); } @@ -24767,7 +24790,15 @@ class TV_MediaInputCluster : public TestCommand { auto iter = mediaInputList.begin(); VerifyOrReturn(CheckNextListItemDecodes("mediaInputList", iter, 0)); + VerifyOrReturn(CheckValue<>("mediaInputList[0].index", iter.GetValue().index, 1)); + VerifyOrReturn(CheckValue<>("mediaInputList[0].inputType", iter.GetValue().inputType, 4)); + VerifyOrReturn(CheckValueAsString("mediaInputList[0].name", iter.GetValue().name, "exampleName")); + VerifyOrReturn(CheckValueAsString("mediaInputList[0].description", iter.GetValue().description, "exampleDescription")); VerifyOrReturn(CheckNextListItemDecodes("mediaInputList", iter, 1)); + VerifyOrReturn(CheckValue<>("mediaInputList[1].index", iter.GetValue().index, 2)); + VerifyOrReturn(CheckValue<>("mediaInputList[1].inputType", iter.GetValue().inputType, 4)); + VerifyOrReturn(CheckValueAsString("mediaInputList[1].name", iter.GetValue().name, "exampleName")); + VerifyOrReturn(CheckValueAsString("mediaInputList[1].description", iter.GetValue().description, "exampleDescription")); VerifyOrReturn(CheckNoMoreListItems("mediaInputList", iter, 2)); NextTest(); } @@ -28484,9 +28515,17 @@ class TestCluster : public TestCommand { auto iter = listStructOctetString.begin(); VerifyOrReturn(CheckNextListItemDecodes("listStructOctetString", iter, 0)); + VerifyOrReturn(CheckValue<>("listStructOctetString[0].fabricIndex", iter.GetValue().fabricIndex, 0ULL)); + VerifyOrReturn(CheckValueAsString("listStructOctetString[0].operationalCert", iter.GetValue().operationalCert, "Test0")); VerifyOrReturn(CheckNextListItemDecodes("listStructOctetString", iter, 1)); + VerifyOrReturn(CheckValue<>("listStructOctetString[1].fabricIndex", iter.GetValue().fabricIndex, 1ULL)); + VerifyOrReturn(CheckValueAsString("listStructOctetString[1].operationalCert", iter.GetValue().operationalCert, "Test1")); VerifyOrReturn(CheckNextListItemDecodes("listStructOctetString", iter, 2)); + VerifyOrReturn(CheckValue<>("listStructOctetString[2].fabricIndex", iter.GetValue().fabricIndex, 2ULL)); + VerifyOrReturn(CheckValueAsString("listStructOctetString[2].operationalCert", iter.GetValue().operationalCert, "Test2")); VerifyOrReturn(CheckNextListItemDecodes("listStructOctetString", iter, 3)); + VerifyOrReturn(CheckValue<>("listStructOctetString[3].fabricIndex", iter.GetValue().fabricIndex, 3ULL)); + VerifyOrReturn(CheckValueAsString("listStructOctetString[3].operationalCert", iter.GetValue().operationalCert, "Test3")); VerifyOrReturn(CheckNoMoreListItems("listStructOctetString", iter, 4)); NextTest(); } @@ -29763,6 +29802,7 @@ class TestDescriptorCluster : public TestCommand { auto iter = deviceList.begin(); VerifyOrReturn(CheckNextListItemDecodes("deviceList", iter, 0)); + VerifyOrReturn(CheckValue<>("deviceList[0].revision", iter.GetValue().revision, 1U)); VerifyOrReturn(CheckNoMoreListItems("deviceList", iter, 1)); NextTest(); } @@ -30494,8 +30534,17 @@ class TestModeSelectCluster : public TestCommand { auto iter = supportedModes.begin(); VerifyOrReturn(CheckNextListItemDecodes("supportedModes", iter, 0)); + VerifyOrReturn(CheckValueAsString("supportedModes[0].label", iter.GetValue().label, "Black")); + VerifyOrReturn(CheckValue<>("supportedModes[0].mode", iter.GetValue().mode, 0)); + VerifyOrReturn(CheckValue<>("supportedModes[0].semanticTag", iter.GetValue().semanticTag, 0UL)); VerifyOrReturn(CheckNextListItemDecodes("supportedModes", iter, 1)); + VerifyOrReturn(CheckValueAsString("supportedModes[1].label", iter.GetValue().label, "Cappuccino")); + VerifyOrReturn(CheckValue<>("supportedModes[1].mode", iter.GetValue().mode, 4)); + VerifyOrReturn(CheckValue<>("supportedModes[1].semanticTag", iter.GetValue().semanticTag, 0UL)); VerifyOrReturn(CheckNextListItemDecodes("supportedModes", iter, 2)); + VerifyOrReturn(CheckValueAsString("supportedModes[2].label", iter.GetValue().label, "Espresso")); + VerifyOrReturn(CheckValue<>("supportedModes[2].mode", iter.GetValue().mode, 7)); + VerifyOrReturn(CheckValue<>("supportedModes[2].semanticTag", iter.GetValue().semanticTag, 0UL)); VerifyOrReturn(CheckNoMoreListItems("supportedModes", iter, 3)); NextTest(); }