From 5f0dc8686bbd9e5969e3050a7e52629a80352088 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 6 Jun 2022 14:55:12 -0400 Subject: [PATCH] Add darwin-framework-tool support for min/max constraints with saved variables. (#19193) Adds support for having the expected value in a min/max constraint be a saveAs value in darwin-framework-tool. Fixes https://github.com/project-chip/connectedhomeip/issues/19110 --- .../commands/tests/TestCommandBridge.h | 32 +++++++++++++++++++ .../tests/suites/include/ConstraintsChecker.h | 20 ++++++------ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h b/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h index e657cf9410ee25..c9e4b236e1d7f5 100644 --- a/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h +++ b/examples/darwin-framework-tool/commands/tests/TestCommandBridge.h @@ -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 ::value, int> = 0> + bool CheckConstraintMinValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected) + { + return ConstraintsChecker::CheckConstraintMinValue(itemName, current, [expected longLongValue]); + } + + template ::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 ::value, int> = 0> + bool CheckConstraintMaxValue(const char * _Nonnull itemName, T current, const NSNumber * _Nonnull expected) + { + return ConstraintsChecker::CheckConstraintMaxValue(itemName, current, [expected longLongValue]); + } + + template ::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; diff --git a/src/app/tests/suites/include/ConstraintsChecker.h b/src/app/tests/suites/include/ConstraintsChecker.h index dd824ccfc3ad7a..f728ef2ed502d8 100644 --- a/src/app/tests/suites/include/ConstraintsChecker.h +++ b/src/app/tests/suites/include/ConstraintsChecker.h @@ -189,7 +189,7 @@ class ConstraintsChecker return true; } - template ::value, int> = 0> + template ::value && !std::is_pointer::value, int> = 0> bool CheckConstraintMinValue(const char * itemName, T current, U expected) { if (current < expected) @@ -201,13 +201,13 @@ class ConstraintsChecker return true; } - template ::value, int> = 0> + template ::value && !std::is_pointer::value, int> = 0> bool CheckConstraintMinValue(const char * itemName, T current, U expected) { return CheckConstraintMinValue(itemName, chip::to_underlying(current), expected); } - template + template ::value, int> = 0> bool CheckConstraintMinValue(const char * itemName, chip::BitFlags current, U expected) { if (current.Raw() < expected) @@ -219,7 +219,7 @@ class ConstraintsChecker return true; } - template + template ::value, int> = 0> bool CheckConstraintMinValue(const char * itemName, chip::BitMask current, U expected) { if (current.Raw() < expected) @@ -231,7 +231,7 @@ class ConstraintsChecker return true; } - template + template ::value, int> = 0> bool CheckConstraintMinValue(const char * itemName, const chip::app::DataModel::Nullable & current, U expected) { if (current.IsNull()) @@ -252,7 +252,7 @@ class ConstraintsChecker return CheckConstraintMinValue(itemName, current, expected.Value()); } - template ::value, int> = 0> + template ::value && !std::is_pointer::value, int> = 0> bool CheckConstraintMaxValue(const char * itemName, T current, U expected) { if (current > expected) @@ -264,13 +264,13 @@ class ConstraintsChecker return true; } - template ::value, int> = 0> + template ::value && !std::is_pointer::value, int> = 0> bool CheckConstraintMaxValue(const char * itemName, T current, U expected) { return CheckConstraintMaxValue(itemName, chip::to_underlying(current), expected); } - template + template ::value, int> = 0> bool CheckConstraintMaxValue(const char * itemName, chip::BitFlags current, U expected) { if (current.Raw() > expected) @@ -282,7 +282,7 @@ class ConstraintsChecker return true; } - template + template ::value, int> = 0> bool CheckConstraintMaxValue(const char * itemName, chip::BitMask current, U expected) { if (current.Raw() > expected) @@ -294,7 +294,7 @@ class ConstraintsChecker return true; } - template + template ::value, int> = 0> bool CheckConstraintMaxValue(const char * itemName, const chip::app::DataModel::Nullable & current, U expected) { if (current.IsNull())