Skip to content

Commit

Permalink
YAML : Constraints with nullable types fixed for Min, Max & NotValue (#…
Browse files Browse the repository at this point in the history
…12958)

* Fix: Constraintswith nullable type fixed for Min Max NotValue

* Restyled by clang-format

* DEV: Add constraint checks on nullable

* DEV: Update darwin test_cluster.zapt

* Restyled by prettier-yaml

* Darwin compile remove large integer u64x tests

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Dec 17, 2021
1 parent 34a46d6 commit 1070648
Show file tree
Hide file tree
Showing 6 changed files with 4,394 additions and 2,021 deletions.
27 changes: 27 additions & 0 deletions examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ class TestCommand : public CHIPCommand

return true;
}
template <typename T, typename U>
bool CheckConstraintMinValue(const char * itemName, const chip::app::DataModel::Nullable<T> & current, U expected)
{
if (current.IsNull())
{
return true;
}
return CheckConstraintMinValue(itemName, current.Value(), static_cast<T>(expected));
}
template <typename T>
bool CheckConstraintMaxValue(const char * itemName, T current, T expected)
{
Expand All @@ -104,6 +113,15 @@ class TestCommand : public CHIPCommand
return true;
}
template <typename T, typename U>
bool CheckConstraintMaxValue(const char * itemName, const chip::app::DataModel::Nullable<T> & current, U expected)
{
if (current.IsNull())
{
return true;
}
return CheckConstraintMaxValue(itemName, current.Value(), static_cast<T>(expected));
}
template <typename T, typename U>
bool CheckConstraintNotValue(const char * itemName, T current, U expected)
{
if (current == expected)
Expand All @@ -114,6 +132,15 @@ class TestCommand : public CHIPCommand

return true;
}
template <typename T, typename U>
bool CheckConstraintNotValue(const char * itemName, const chip::app::DataModel::Nullable<T> & current, U expected)
{
if (current.IsNull())
{
return true;
}
return CheckConstraintNotValue(itemName, current.Value(), expected);
}

bool CheckConstraintNotValue(const char * itemName, chip::CharSpan current, chip::CharSpan expected)
{
Expand Down
4 changes: 2 additions & 2 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ class {{filename}}: public TestCommand
{{~#if expectedConstraints.endsWith}}VerifyOrReturn(CheckConstraintEndsWith("{{>item}}", {{>item}}, "{{expectedConstraints.endsWith}}"));{{/if}}
{{~#if expectedConstraints.minLength}}VerifyOrReturn(CheckConstraintMinLength("{{>item}}", {{>item}}.size(), {{expectedConstraints.minLength}}));{{/if}}
{{~#if expectedConstraints.maxLength}}VerifyOrReturn(CheckConstraintMaxLength("{{>item}}", {{>item}}.size(), {{expectedConstraints.maxLength}}));{{/if}}
{{~#if expectedConstraints.minValue}}VerifyOrReturn(CheckConstraintMinValue<{{chipType}}>("{{>item}}", {{>item}}, {{expectedConstraints.minValue}}));{{/if}}
{{~#if expectedConstraints.maxValue}}VerifyOrReturn(CheckConstraintMaxValue<{{chipType}}>("{{>item}}", {{>item}}, {{expectedConstraints.maxValue}}));{{/if}}
{{~#if expectedConstraints.minValue}}VerifyOrReturn(CheckConstraintMinValue<{{chipType}}>("{{>item}}", {{>item}}, {{asTypedLiteral expectedConstraints.minValue type}}));{{/if}}
{{~#if expectedConstraints.maxValue}}VerifyOrReturn(CheckConstraintMaxValue<{{chipType}}>("{{>item}}", {{>item}}, {{asTypedLiteral expectedConstraints.maxValue type}}));{{/if}}
{{~#if expectedConstraints.notValue}}VerifyOrReturn(CheckConstraintNotValue("{{>item}}", {{>item}}, {{asTypedLiteral expectedConstraints.notValue type}}));{{/if}}
{{/if}}

Expand Down
Loading

0 comments on commit 1070648

Please sign in to comment.