##// END OF EJS Templates
Creates validators for range and data
Alexandre Leroux -
r1227:60a45a0d7167
parent child
Show More
@@ -1,26 +1,49
1 1 #include "FuzzingValidators.h"
2 2
3 #include <QTest>
4
3 5 #include <functional>
4 6
5 7 Q_LOGGING_CATEGORY(LOG_FuzzingValidators, "FuzzingValidators")
6 8
7 9 namespace {
8 10
9 11 /**
10 12 * Default implementation of @sa IFuzzingValidator. This validator takes as parameter of its
11 13 * construction a function of validation which is called in the validate() method
12 14 */
13 15 class FuzzingValidator : public IFuzzingValidator {
14 16 public:
15 17 /// Signature of a validation function
16 18 using ValidationFunction = std::function<void(const VariableState &variableState)>;
17 19
18 20 explicit FuzzingValidator(ValidationFunction fun) : m_Fun(std::move(fun)) {}
19 21
20 22 void validate(const VariableState &variableState) const override { m_Fun(variableState); }
21 23
22 24 private:
23 25 ValidationFunction m_Fun;
24 26 };
25 27
26 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 1 #ifndef SCIQLOP_FUZZINGVALIDATORS_H
2 2 #define SCIQLOP_FUZZINGVALIDATORS_H
3 3
4 4 #include <QLoggingCategory>
5 5
6 6 Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingValidators)
7 7
8 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 17 * Struct that represents a validator. A validator checks if the state of a variable is valid at the
12 18 * moment it is called during a fuzzing test
13 19 */
14 20 struct IFuzzingValidator {
15 21 virtual ~IFuzzingValidator() noexcept = default;
16 22
17 23 /// Validates the variable's state passed in parameter
18 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 33 #endif // SCIQLOP_FUZZINGVALIDATORS_H
General Comments 0
You need to be logged in to leave comments. Login now