Fix the minLength/maxLength constraint checks on Darwin for nullables. (#27355)
This is the darwin-framework-tool equivalent of
https://github.com/project-chip/connectedhomeip/pull/27312
Also fixes a similar issue for minValue/maxValue.
diff --git a/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h b/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h
index 4457589..b3d08ec 100644
--- a/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h
+++ b/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h
@@ -396,25 +396,37 @@
using ConstraintsChecker::CheckConstraintMinLength;
- bool CheckConstraintMinLength(const char * _Nonnull itemName, NSString * _Nonnull current, uint64_t expected)
+ bool CheckConstraintMinLength(const char * _Nonnull itemName, NSString * _Nullable current, uint64_t expected)
{
+ if (current == nil) {
+ return true;
+ }
return CheckConstraintMinLength(itemName, [current length], expected);
}
- bool CheckConstraintMinLength(const char * _Nonnull itemName, NSArray * _Nonnull current, uint64_t expected)
+ bool CheckConstraintMinLength(const char * _Nonnull itemName, NSArray * _Nullable current, uint64_t expected)
{
+ if (current == nil) {
+ return true;
+ }
return CheckConstraintMinLength(itemName, [current count], expected);
}
using ConstraintsChecker::CheckConstraintMaxLength;
- bool CheckConstraintMaxLength(const char * _Nonnull itemName, NSString * _Nonnull current, uint64_t expected)
+ bool CheckConstraintMaxLength(const char * _Nonnull itemName, NSString * _Nullable current, uint64_t expected)
{
+ if (current == nil) {
+ return true;
+ }
return CheckConstraintMaxLength(itemName, [current length], expected);
}
- bool CheckConstraintMaxLength(const char * _Nonnull itemName, NSArray * _Nonnull current, uint64_t expected)
+ bool CheckConstraintMaxLength(const char * _Nonnull itemName, NSArray * _Nullable current, uint64_t expected)
{
+ if (current == nil) {
+ return true;
+ }
return CheckConstraintMaxLength(itemName, [current count], expected);
}
@@ -423,20 +435,29 @@
// 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_integral<T>::value && std::is_signed<T>::value, int> = 0>
- bool CheckConstraintMinValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected)
+ bool CheckConstraintMinValue(const char * _Nonnull itemName, T current, const NSNumber * _Nullable expected)
{
+ if (expected == nil) {
+ return true;
+ }
return ConstraintsChecker::CheckConstraintMinValue(itemName, current, [expected longLongValue]);
}
template <typename T, std::enable_if_t<std::is_integral<T>::value && !std::is_signed<T>::value, int> = 0>
- bool CheckConstraintMinValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected)
+ bool CheckConstraintMinValue(const char * _Nonnull itemName, T current, const NSNumber * _Nullable expected)
{
+ if (expected == nil) {
+ return true;
+ }
return ConstraintsChecker::CheckConstraintMinValue(itemName, current, [expected unsignedLongLongValue]);
}
template <typename T, std::enable_if_t<std::is_floating_point<T>::value, int> = 0>
- bool CheckConstraintMinValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected)
+ bool CheckConstraintMinValue(const char * _Nonnull itemName, T current, const NSNumber * _Nullable expected)
{
+ if (expected == nil) {
+ return true;
+ }
return ConstraintsChecker::CheckConstraintMinValue(itemName, current, [expected doubleValue]);
}
@@ -445,20 +466,29 @@
// 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_integral<T>::value && std::is_signed<T>::value, int> = 0>
- bool CheckConstraintMaxValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected)
+ bool CheckConstraintMaxValue(const char * _Nonnull itemName, T current, const NSNumber * _Nullable expected)
{
+ if (expected == nil) {
+ return true;
+ }
return ConstraintsChecker::CheckConstraintMaxValue(itemName, current, [expected longLongValue]);
}
template <typename T, std::enable_if_t<std::is_integral<T>::value && !std::is_signed<T>::value, int> = 0>
- bool CheckConstraintMaxValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected)
+ bool CheckConstraintMaxValue(const char * _Nonnull itemName, T current, const NSNumber * _Nullable expected)
{
+ if (expected == nil) {
+ return true;
+ }
return ConstraintsChecker::CheckConstraintMaxValue(itemName, current, [expected unsignedLongLongValue]);
}
template <typename T, std::enable_if_t<std::is_floating_point<T>::value, int> = 0>
- bool CheckConstraintMaxValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected)
+ bool CheckConstraintMaxValue(const char * _Nonnull itemName, T current, const NSNumber * _Nullable expected)
{
+ if (expected == nil) {
+ return true;
+ }
return ConstraintsChecker::CheckConstraintMaxValue(itemName, current, [expected doubleValue]);
}