Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle [YAML] Allow contains/exclude constraints to be used for bitmaps #20360

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}}

54 changes: 54 additions & 0 deletions src/app/tests/suites/TestConstraints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,60 @@ tests:
arguments:
value: []

# Tests for Bitmap32 attribute

- label: "Read attribute BITMAP32 Default Value"
command: "readAttribute"
attribute: "bitmap32"
response:
value: 0

- label: "Write attribute BITMAP32 with MaskVal1 and MaskVal3"
command: "writeAttribute"
attribute: "bitmap32"
arguments:
value: 5 # MaskVal1 | MaskVal3

- label:
"Read attribute BITMAP32 with MaskVal1 and MaskVal3 and ensure
MaskVal2 is not set"
command: "readAttribute"
attribute: "bitmap32"
response:
value: 5 # MaskVal1 | MaskVal3
constraints:
hasMasksClear: [0x02] # [MaskVal2]

- label:
"Read attribute BITMAP32 with MaskVal1 and MaskVal3 and ensure
MaskVal1 is set"
command: "readAttribute"
attribute: "bitmap32"
response:
value: 5 # MaskVal1 | MaskVal3
constraints:
hasMasksSet: [0x01] # [MaskVal1]

- label:
"Read attribute BITMAP32 with MaskVal1 and MaskVal3 and ensure
MaskVal3 is set"
command: "readAttribute"
attribute: "bitmap32"
response:
value: 5 # MaskVal1 | MaskVal3
constraints:
hasMasksSet: [0x04] # [MaskVal3]

- label:
"Read attribute BITMAP32 with MaskVal1 and MaskVal3 and ensure
Maskval1 and MaskVal3 are set"
command: "readAttribute"
attribute: "bitmap32"
response:
value: 5 # MaskVal1 | MaskVal3
constraints:
hasMasksSet: [0x01, 0x04] # [MaskVal1, MaskVal3]

# Tests for INT32U attribute

- label: "Write attribute INT32U Value"
Expand Down
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;
}
};
Loading