diff --git a/plugins/amda/tests/FuzzingValidators.cpp b/plugins/amda/tests/FuzzingValidators.cpp index d3db344..ff602f1 100644 --- a/plugins/amda/tests/FuzzingValidators.cpp +++ b/plugins/amda/tests/FuzzingValidators.cpp @@ -8,6 +8,40 @@ Q_LOGGING_CATEGORY(LOG_FuzzingValidators, "FuzzingValidators") namespace { +// /////////////// // +// RANGE VALIDATOR // +// /////////////// // + +/** + * Checks that a range of a variable matches the expected range passed as a parameter + * @param variable the variable for which to check the range + * @param expectedRange the expected range + * @param getVariableRangeFun the function to retrieve the range from the variable + * @remarks if the variable is null, checks that the expected range is the invalid range + */ +void validateRange(std::shared_ptr variable, const SqpRange &expectedRange, + std::function getVariableRangeFun) +{ + auto compare = [](const auto &range, const auto &expectedRange, const auto &message) { + if (range == expectedRange) { + qCInfo(LOG_FuzzingValidators()).noquote() << message << "OK"; + } + else { + qCInfo(LOG_FuzzingValidators()).noquote() + << message << "FAIL (current range:" << range + << ", expected range:" << expectedRange << ")"; + QFAIL(""); + } + }; + + if (variable) { + compare(getVariableRangeFun(*variable), expectedRange, "Checking variable's range..."); + } + else { + compare(INVALID_RANGE, expectedRange, "Checking that there is no range set..."); + } +} + /** * Default implementation of @sa IFuzzingValidator. This validator takes as parameter of its * construction a function of validation which is called in the validate() method @@ -36,7 +70,8 @@ std::unique_ptr FuzzingValidatorFactory::create(FuzzingValida }); case FuzzingValidatorType::RANGE: return std::make_unique([](const VariableState &variableState) { - /// @todo: complete + auto getVariableRange = [](const Variable &variable) { return variable.range(); }; + validateRange(variableState.m_Variable, variableState.m_Range, getVariableRange); }); default: // Default case returns invalid validator