Skip to content

Commit

Permalink
[matter_yamltests] Update minLength/maxLength constraints to allow nu…
Browse files Browse the repository at this point in the history
…ll values (#27312)
  • Loading branch information
vivien-apple authored and pull[bot] committed Nov 7, 2023
1 parent a605c49 commit 114913c
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 74 deletions.
6 changes: 4 additions & 2 deletions scripts/py_matter_yamltests/matter_yamltests/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ def _is_double(self, value):

class _ConstraintMinLength(BaseConstraint):
def __init__(self, context, min_length):
super().__init__(context, types=[str, bytes, list])
super().__init__(context, types=[
str, bytes, list], is_null_allowed=True)
self._min_length = min_length

def check_response(self, value, value_type_name) -> bool:
Expand All @@ -547,7 +548,8 @@ def get_reason(self, value, value_type_name) -> str:

class _ConstraintMaxLength(BaseConstraint):
def __init__(self, context, max_length):
super().__init__(context, types=[str, bytes, list])
super().__init__(context, types=[
str, bytes, list], is_null_allowed=True)
self._max_length = max_length

def check_response(self, value, value_type_name) -> bool:
Expand Down
28 changes: 28 additions & 0 deletions src/app/tests/suites/TestConstraints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,34 @@ tests:
arguments:
value: ""

# Tests for NULLABLE_CHAR_STRING attribute

- label: "Write attribute NULLABLE_CHAR_STRING Value"
command: "writeAttribute"
attribute: "nullable_char_string"
arguments:
value: null

- label: "Read attribute NULLABLE_CHAR_STRING Value MinLength Constraints"
command: "readAttribute"
attribute: "nullable_char_string"
response:
constraints:
minLength: 5

- label: "Read attribute NULLABLE_CHAR_STRING Value MaxLength Constraints"
command: "readAttribute"
attribute: "nullable_char_string"
response:
constraints:
maxLength: 20

- label: "Write attribute NULLABLE_CHAR_STRING Value Back to Default Value"
command: "writeAttribute"
attribute: "nullable_char_string"
arguments:
value: ""

# Tests for hasValue attribute

- label: "Read attribute NULLABLE_INT8U Default Value"
Expand Down
24 changes: 24 additions & 0 deletions src/app/tests/suites/include/ConstraintsChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,36 @@ class ConstraintsChecker
return CheckConstraintMinLength(itemName, current.size(), expected);
}

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

return CheckConstraintMinLength(itemName, current.Value(), expected);
}

template <typename T>
bool CheckConstraintMaxLength(const char * itemName, const chip::Span<T> & current, uint64_t expected)
{
return CheckConstraintMaxLength(itemName, current.size(), expected);
}

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

return CheckConstraintMaxLength(itemName, current.Value(), expected);
}

template <typename T>
bool CheckConstraintMinLength(const char * itemName, const chip::app::DataModel::DecodableList<T> & current, uint64_t expected)
{
Expand Down
119 changes: 84 additions & 35 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 114913c

Please sign in to comment.