##// END OF EJS Templates
Implements validation of variable's range
Alexandre Leroux -
r1197:4a43ae2006c2
parent child
Show More
@@ -8,6 +8,40 Q_LOGGING_CATEGORY(LOG_FuzzingValidators, "FuzzingValidators")
8
8
9 namespace {
9 namespace {
10
10
11 // /////////////// //
12 // RANGE VALIDATOR //
13 // /////////////// //
14
15 /**
16 * Checks that a range of a variable matches the expected range passed as a parameter
17 * @param variable the variable for which to check the range
18 * @param expectedRange the expected range
19 * @param getVariableRangeFun the function to retrieve the range from the variable
20 * @remarks if the variable is null, checks that the expected range is the invalid range
21 */
22 void validateRange(std::shared_ptr<Variable> variable, const SqpRange &expectedRange,
23 std::function<SqpRange(const Variable &)> getVariableRangeFun)
24 {
25 auto compare = [](const auto &range, const auto &expectedRange, const auto &message) {
26 if (range == expectedRange) {
27 qCInfo(LOG_FuzzingValidators()).noquote() << message << "OK";
28 }
29 else {
30 qCInfo(LOG_FuzzingValidators()).noquote()
31 << message << "FAIL (current range:" << range
32 << ", expected range:" << expectedRange << ")";
33 QFAIL("");
34 }
35 };
36
37 if (variable) {
38 compare(getVariableRangeFun(*variable), expectedRange, "Checking variable's range...");
39 }
40 else {
41 compare(INVALID_RANGE, expectedRange, "Checking that there is no range set...");
42 }
43 }
44
11 /**
45 /**
12 * Default implementation of @sa IFuzzingValidator. This validator takes as parameter of its
46 * Default implementation of @sa IFuzzingValidator. This validator takes as parameter of its
13 * construction a function of validation which is called in the validate() method
47 * construction a function of validation which is called in the validate() method
@@ -36,7 +70,8 std::unique_ptr<IFuzzingValidator> FuzzingValidatorFactory::create(FuzzingValida
36 });
70 });
37 case FuzzingValidatorType::RANGE:
71 case FuzzingValidatorType::RANGE:
38 return std::make_unique<FuzzingValidator>([](const VariableState &variableState) {
72 return std::make_unique<FuzzingValidator>([](const VariableState &variableState) {
39 /// @todo: complete
73 auto getVariableRange = [](const Variable &variable) { return variable.range(); };
74 validateRange(variableState.m_Variable, variableState.m_Range, getVariableRange);
40 });
75 });
41 default:
76 default:
42 // Default case returns invalid validator
77 // Default case returns invalid validator
General Comments 0
You need to be logged in to leave comments. Login now