##// END OF EJS Templates
Creates validators for range and data
Alexandre Leroux -
r1194:60a45a0d7167
parent child
Show More
@@ -1,26 +1,49
1 #include "FuzzingValidators.h"
1 #include "FuzzingValidators.h"
2
2
3 #include <QTest>
4
3 #include <functional>
5 #include <functional>
4
6
5 Q_LOGGING_CATEGORY(LOG_FuzzingValidators, "FuzzingValidators")
7 Q_LOGGING_CATEGORY(LOG_FuzzingValidators, "FuzzingValidators")
6
8
7 namespace {
9 namespace {
8
10
9 /**
11 /**
10 * Default implementation of @sa IFuzzingValidator. This validator takes as parameter of its
12 * Default implementation of @sa IFuzzingValidator. This validator takes as parameter of its
11 * construction a function of validation which is called in the validate() method
13 * construction a function of validation which is called in the validate() method
12 */
14 */
13 class FuzzingValidator : public IFuzzingValidator {
15 class FuzzingValidator : public IFuzzingValidator {
14 public:
16 public:
15 /// Signature of a validation function
17 /// Signature of a validation function
16 using ValidationFunction = std::function<void(const VariableState &variableState)>;
18 using ValidationFunction = std::function<void(const VariableState &variableState)>;
17
19
18 explicit FuzzingValidator(ValidationFunction fun) : m_Fun(std::move(fun)) {}
20 explicit FuzzingValidator(ValidationFunction fun) : m_Fun(std::move(fun)) {}
19
21
20 void validate(const VariableState &variableState) const override { m_Fun(variableState); }
22 void validate(const VariableState &variableState) const override { m_Fun(variableState); }
21
23
22 private:
24 private:
23 ValidationFunction m_Fun;
25 ValidationFunction m_Fun;
24 };
26 };
25
27
26 } // namespace
28 } // namespace
29
30 std::unique_ptr<IFuzzingValidator> FuzzingValidatorFactory::create(FuzzingValidatorType type)
31 {
32 switch (type) {
33 case FuzzingValidatorType::DATA:
34 return std::make_unique<FuzzingValidator>([](const VariableState &variableState) {
35 /// @todo: complete
36 });
37 case FuzzingValidatorType::RANGE:
38 return std::make_unique<FuzzingValidator>([](const VariableState &variableState) {
39 /// @todo: complete
40 });
41 default:
42 // Default case returns invalid validator
43 break;
44 }
45
46 // Invalid validator
47 return std::make_unique<FuzzingValidator>(
48 [](const VariableState &) { QFAIL("Invalid validator"); });
49 }
@@ -1,21 +1,33
1 #ifndef SCIQLOP_FUZZINGVALIDATORS_H
1 #ifndef SCIQLOP_FUZZINGVALIDATORS_H
2 #define SCIQLOP_FUZZINGVALIDATORS_H
2 #define SCIQLOP_FUZZINGVALIDATORS_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5
5
6 Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingValidators)
6 Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingValidators)
7
7
8 class VariableState;
8 class VariableState;
9
9
10 /// Types of validators that can be defined
11 enum class FuzzingValidatorType {
12 DATA, ///< Validates variable's data
13 RANGE ///< Validates variable's range
14 };
15
10 /**
16 /**
11 * Struct that represents a validator. A validator checks if the state of a variable is valid at the
17 * Struct that represents a validator. A validator checks if the state of a variable is valid at the
12 * moment it is called during a fuzzing test
18 * moment it is called during a fuzzing test
13 */
19 */
14 struct IFuzzingValidator {
20 struct IFuzzingValidator {
15 virtual ~IFuzzingValidator() noexcept = default;
21 virtual ~IFuzzingValidator() noexcept = default;
16
22
17 /// Validates the variable's state passed in parameter
23 /// Validates the variable's state passed in parameter
18 virtual void validate(const VariableState &variableState) const = 0;
24 virtual void validate(const VariableState &variableState) const = 0;
19 };
25 };
20
26
27 /// Factory of @sa IFuzzingValidator
28 struct FuzzingValidatorFactory {
29 /// Creates a validator according to the type passed in parameter
30 static std::unique_ptr<IFuzzingValidator> create(FuzzingValidatorType type);
31 };
32
21 #endif // SCIQLOP_FUZZINGVALIDATORS_H
33 #endif // SCIQLOP_FUZZINGVALIDATORS_H
General Comments 0
You need to be logged in to leave comments. Login now