Skip to content

Commit

Permalink
[chip-tool] Add support for the constraints contains/excludes for bit…
Browse files Browse the repository at this point in the history
…maps
  • Loading branch information
vivien-apple committed Jul 8, 2022
1 parent bc72c83 commit 7ffa562
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
{{/chip_tests_iterate_expected_list}}
{{/if}}

{{~#if (hasProperty expectedConstraints "hasMasksSet")}}
{{#chip_tests_iterate_expected_list expectedConstraints.hasMasksSet}}
VerifyOrReturn(CheckConstraintHasMasksSet("{{asPropertyValue}}", {{asPropertyValue}}, {{asTypedLiteral value type}}));
{{/chip_tests_iterate_expected_list}}
{{/if}}

{{~#if (hasProperty expectedConstraints "hasMasksClear")}}
{{#chip_tests_iterate_expected_list expectedConstraints.hasMasksClear}}
VerifyOrReturn(CheckConstraintHasMasksClear("{{asPropertyValue}}", {{asPropertyValue}}, {{asTypedLiteral value type}}));
{{/chip_tests_iterate_expected_list}}
{{/if}}

{{~#if (hasProperty expectedConstraints "notValue")}}
{{#if (isLiteralNull expectedConstraints.notValue)}}
VerifyOrReturn(CheckValueNonNull("{{asPropertyValue}}", {{asPropertyValue}}));
Expand All @@ -53,4 +65,3 @@
{{/unless}}
{{/if}}
{{/if}}

48 changes: 48 additions & 0 deletions src/app/tests/suites/include/ConstraintsChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,52 @@ class ConstraintsChecker

return true;
}

template <typename T, typename U>
bool CheckConstraintHasMasksSet(const char * itemName, const T & current, const U & expected)
{
if (current & expected)
{
return true;
}

Exit(std::string(itemName) + " expects the field with value " + std::to_string(expected) + " to be set but it is not.");
return false;
}

template <typename T, typename U>
bool CheckConstraintHasMasksSet(const char * itemName, const chip::BitMask<T> & current, const U & expected)
{
if (current.Has(static_cast<T>(expected)))
{
return true;
}

Exit(std::string(itemName) + " expects the field with value " + std::to_string(expected) + " to be set but it is not.");
return false;
}

template <typename T, typename U>
bool CheckConstraintHasMasksClear(const char * itemName, const T & current, const U & expected)
{
if ((current & expected) == 0)
{
return true;
}

Exit(std::string(itemName) + " expects the field with value " + std::to_string(expected) + " to not be set but it is.");
return false;
}

template <typename T, typename U>
bool CheckConstraintHasMasksClear(const char * itemName, const chip::BitMask<T> & current, const U & expected)
{
if (!current.Has(static_cast<T>(expected)))
{
return true;
}

Exit(std::string(itemName) + " expects the field with value " + std::to_string(expected) + " to not be set but it is.");
return false;
}
};

0 comments on commit 7ffa562

Please sign in to comment.