diff --git a/examples/chip-tool/templates/tests/partials/checks/maybeCheckExpectedConstraints.zapt b/examples/chip-tool/templates/tests/partials/checks/maybeCheckExpectedConstraints.zapt index b7a574e380173a..8250c27ba03230 100644 --- a/examples/chip-tool/templates/tests/partials/checks/maybeCheckExpectedConstraints.zapt +++ b/examples/chip-tool/templates/tests/partials/checks/maybeCheckExpectedConstraints.zapt @@ -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}})); @@ -53,4 +65,3 @@ {{/unless}} {{/if}} {{/if}} - diff --git a/src/app/tests/suites/include/ConstraintsChecker.h b/src/app/tests/suites/include/ConstraintsChecker.h index f728ef2ed502d8..f988b057ecdfa4 100644 --- a/src/app/tests/suites/include/ConstraintsChecker.h +++ b/src/app/tests/suites/include/ConstraintsChecker.h @@ -510,4 +510,52 @@ class ConstraintsChecker return true; } + + template + 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 + bool CheckConstraintHasMasksSet(const char * itemName, const chip::BitMask & current, const U & expected) + { + if (current.Has(static_cast(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 + 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 + bool CheckConstraintHasMasksClear(const char * itemName, const chip::BitMask & current, const U & expected) + { + if (!current.Has(static_cast(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; + } };