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

[matter_yamltests] Update minLength/maxLength constraints to allow nu… #27312

Merged
Merged
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
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