Skip to content

Commit

Permalink
Turn on checking of struct fields for YAML tests
Browse files Browse the repository at this point in the history
The CheckValueAsString change is just to show what the actual value
was that does not match the expected value.

The CheckValue (enum version) change is to make it compile, now that
it's actually being used.
  • Loading branch information
bzbarsky-apple committed Nov 9, 2021
1 parent 0ef231d commit aa704b8
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 15 deletions.
3 changes: 2 additions & 1 deletion examples/chip-tool/commands/tests/TestCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class TestCommand : public CHIPCommand
template <typename T, typename U, typename std::enable_if_t<std::is_enum<T>::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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
VerifyOrReturn(CheckNoMoreListItems<decltype({{actual}})>("{{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}}")
Expand Down
6 changes: 3 additions & 3 deletions src/app/tests/suites/TV_AudioOutputCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 12 additions & 2 deletions src/app/tests/suites/TV_MediaInputCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion src/app/tests/suites/TV_TargetNavigatorCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions src/app/tests/suites/TV_TvChannelCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,11 @@ function isLiteralNull(value, options)
return (value === null) || (value instanceof NullObject);
}

function expectedValueHasProp(value, name)
{
return name in value;
}

//
// Module exports
//
Expand All @@ -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;
49 changes: 49 additions & 0 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aa704b8

Please sign in to comment.