Skip to content

Commit

Permalink
[YAML] Allow contains/exclude constraints to be used for bitmaps (#20359
Browse files Browse the repository at this point in the history
) (#20483)

Co-authored-by: Vivien Nicolas <vnicolas@apple.com>
  • Loading branch information
woody-apple and vivien-apple authored Jul 8, 2022
1 parent fe30b1a commit 7ff29f5
Show file tree
Hide file tree
Showing 5 changed files with 508 additions and 898 deletions.
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

0 comments on commit 7ff29f5

Please sign in to comment.