Skip to content

Commit

Permalink
Add darwin-framework-tool support for min/max constraints with saved …
Browse files Browse the repository at this point in the history
…variables. (#19193)

Adds support for having the expected value in a min/max constraint be
a saveAs value in darwin-framework-tool.

Fixes #19110
  • Loading branch information
bzbarsky-apple authored Jun 6, 2022
1 parent 0cb8fe9 commit 5f0dc86
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
32 changes: 32 additions & 0 deletions examples/darwin-framework-tool/commands/tests/TestCommandBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,38 @@ class TestCommandBridge : public CHIPCommandBridge,
return CheckConstraintNotValue(itemName, currentValue, @(expected));
}

using ConstraintsChecker::CheckConstraintMinValue;

// Used when the minValue is a saved variable, since ConstraintsChecker does
// not expect Core Foundation types.
template <typename T, std::enable_if_t<std::is_signed<T>::value, int> = 0>
bool CheckConstraintMinValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected)
{
return ConstraintsChecker::CheckConstraintMinValue(itemName, current, [expected longLongValue]);
}

template <typename T, std::enable_if_t<!std::is_signed<T>::value, int> = 0>
bool CheckConstraintMinValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected)
{
return ConstraintsChecker::CheckConstraintMinValue(itemName, current, [expected unsignedLongLongValue]);
}

using ConstraintsChecker::CheckConstraintMaxValue;

// Used when the maxValue is a saved variable, since ConstraintsChecker does
// not expect Core Foundation types.
template <typename T, std::enable_if_t<std::is_signed<T>::value, int> = 0>
bool CheckConstraintMaxValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected)
{
return ConstraintsChecker::CheckConstraintMaxValue(itemName, current, [expected longLongValue]);
}

template <typename T, std::enable_if_t<!std::is_signed<T>::value, int> = 0>
bool CheckConstraintMaxValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected)
{
return ConstraintsChecker::CheckConstraintMaxValue(itemName, current, [expected unsignedLongLongValue]);
}

bool CheckValueAsString(const char * _Nonnull itemName, const id _Nonnull current, const NSString * _Nonnull expected)
{
NSString * data = current;
Expand Down
20 changes: 10 additions & 10 deletions src/app/tests/suites/include/ConstraintsChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class ConstraintsChecker
return true;
}

template <typename T, typename U, std::enable_if_t<!std::is_enum<T>::value, int> = 0>
template <typename T, typename U, std::enable_if_t<!std::is_enum<T>::value && !std::is_pointer<U>::value, int> = 0>
bool CheckConstraintMinValue(const char * itemName, T current, U expected)
{
if (current < expected)
Expand All @@ -201,13 +201,13 @@ class ConstraintsChecker
return true;
}

template <typename T, typename U, std::enable_if_t<std::is_enum<T>::value, int> = 0>
template <typename T, typename U, std::enable_if_t<std::is_enum<T>::value && !std::is_pointer<U>::value, int> = 0>
bool CheckConstraintMinValue(const char * itemName, T current, U expected)
{
return CheckConstraintMinValue(itemName, chip::to_underlying(current), expected);
}

template <typename T, typename U>
template <typename T, typename U, std::enable_if_t<!std::is_pointer<U>::value, int> = 0>
bool CheckConstraintMinValue(const char * itemName, chip::BitFlags<T> current, U expected)
{
if (current.Raw() < expected)
Expand All @@ -219,7 +219,7 @@ class ConstraintsChecker
return true;
}

template <typename T, typename U>
template <typename T, typename U, std::enable_if_t<!std::is_pointer<U>::value, int> = 0>
bool CheckConstraintMinValue(const char * itemName, chip::BitMask<T> current, U expected)
{
if (current.Raw() < expected)
Expand All @@ -231,7 +231,7 @@ class ConstraintsChecker
return true;
}

template <typename T, typename U>
template <typename T, typename U, std::enable_if_t<!std::is_pointer<U>::value, int> = 0>
bool CheckConstraintMinValue(const char * itemName, const chip::app::DataModel::Nullable<T> & current, U expected)
{
if (current.IsNull())
Expand All @@ -252,7 +252,7 @@ class ConstraintsChecker
return CheckConstraintMinValue(itemName, current, expected.Value());
}

template <typename T, typename U, std::enable_if_t<!std::is_enum<T>::value, int> = 0>
template <typename T, typename U, std::enable_if_t<!std::is_enum<T>::value && !std::is_pointer<U>::value, int> = 0>
bool CheckConstraintMaxValue(const char * itemName, T current, U expected)
{
if (current > expected)
Expand All @@ -264,13 +264,13 @@ class ConstraintsChecker
return true;
}

template <typename T, typename U, std::enable_if_t<std::is_enum<T>::value, int> = 0>
template <typename T, typename U, std::enable_if_t<std::is_enum<T>::value && !std::is_pointer<U>::value, int> = 0>
bool CheckConstraintMaxValue(const char * itemName, T current, U expected)
{
return CheckConstraintMaxValue(itemName, chip::to_underlying(current), expected);
}

template <typename T, typename U>
template <typename T, typename U, std::enable_if_t<!std::is_pointer<U>::value, int> = 0>
bool CheckConstraintMaxValue(const char * itemName, chip::BitFlags<T> current, U expected)
{
if (current.Raw() > expected)
Expand All @@ -282,7 +282,7 @@ class ConstraintsChecker
return true;
}

template <typename T, typename U>
template <typename T, typename U, std::enable_if_t<!std::is_pointer<U>::value, int> = 0>
bool CheckConstraintMaxValue(const char * itemName, chip::BitMask<T> current, U expected)
{
if (current.Raw() > expected)
Expand All @@ -294,7 +294,7 @@ class ConstraintsChecker
return true;
}

template <typename T, typename U>
template <typename T, typename U, std::enable_if_t<!std::is_pointer<U>::value, int> = 0>
bool CheckConstraintMaxValue(const char * itemName, const chip::app::DataModel::Nullable<T> & current, U expected)
{
if (current.IsNull())
Expand Down

0 comments on commit 5f0dc86

Please sign in to comment.