##// END OF EJS Templates
Fixes clang-format for resource files
Alexandre Leroux -
r1211:08e858e2cf84
parent child
Show More
@@ -115,6 +115,7 IF(BUILD_TESTS)
115 ${testDirectory}/*.cpp
115 ${testDirectory}/*.cpp
116 ${testDirectory}/*.h)
116 ${testDirectory}/*.h)
117 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
117 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
118 LIST(APPEND testFilesToFormat ${currentTestSources})
118 # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
119 # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
119
120
120 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
121 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
@@ -13,34 +13,44 Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations")
13 namespace {
13 namespace {
14
14
15 struct CreateOperation : public IFuzzingOperation {
15 struct CreateOperation : public IFuzzingOperation {
16 bool canExecute(std::shared_ptr<Variable> variable) const override {
16 bool canExecute(std::shared_ptr<Variable> variable) const override
17 {
17 // A variable can be created only if it doesn't exist yet
18 // A variable can be created only if it doesn't exist yet
18 return variable == nullptr;
19 return variable == nullptr;
19 }
20 }
20
21
21 void execute(std::shared_ptr<Variable>& variable, VariableController &variableController, const Properties &properties) const override{
22 void execute(std::shared_ptr<Variable> &variable, VariableController &variableController,
22 // Retrieves metadata pool from properties, and choose one of the metadata entries to associate it with the variable
23 const Properties &properties) const override
24 {
25 // Retrieves metadata pool from properties, and choose one of the metadata entries to
26 // associate it with the variable
23 auto metaDataPool = properties.value(METADATA_POOL_PROPERTY).value<MetadataPool>();
27 auto metaDataPool = properties.value(METADATA_POOL_PROPERTY).value<MetadataPool>();
24 auto variableMetadata = RandomGenerator::instance().randomChoice(metaDataPool);
28 auto variableMetadata = RandomGenerator::instance().randomChoice(metaDataPool);
25
29
26 // Retrieves provider
30 // Retrieves provider
27 auto variableProvider = properties.value(PROVIDER_PROPERTY).value<std::shared_ptr<IDataProvider>>();
31 auto variableProvider
32 = properties.value(PROVIDER_PROPERTY).value<std::shared_ptr<IDataProvider> >();
28
33
29 auto variableName = QString{"Var_%1"}.arg(QUuid::createUuid().toString());
34 auto variableName = QString{"Var_%1"}.arg(QUuid::createUuid().toString());
30 qCInfo(LOG_FuzzingOperations()) << "Creating variable" << variableName << "(metadata:" << variableMetadata << ")";
35 qCInfo(LOG_FuzzingOperations())
36 << "Creating variable" << variableName << "(metadata:" << variableMetadata << ")";
31
37
32 auto newVariable = variableController.createVariable(variableName, variableMetadata, variableProvider);
38 auto newVariable
39 = variableController.createVariable(variableName, variableMetadata, variableProvider);
33 std::swap(variable, newVariable);
40 std::swap(variable, newVariable);
34 }
41 }
35 };
42 };
36
43
37 struct UnknownOperation : public IFuzzingOperation {
44 struct UnknownOperation : public IFuzzingOperation {
38 bool canExecute(std::shared_ptr<Variable> variable) const override {
45 bool canExecute(std::shared_ptr<Variable> variable) const override
46 {
39 Q_UNUSED(variable);
47 Q_UNUSED(variable);
40 return false;
48 return false;
41 }
49 }
42
50
43 void execute(std::shared_ptr<Variable>& variable, VariableController &variableController, const Properties &properties) const override{
51 void execute(std::shared_ptr<Variable> &variable, VariableController &variableController,
52 const Properties &properties) const override
53 {
44 Q_UNUSED(variable);
54 Q_UNUSED(variable);
45 Q_UNUSED(variableController);
55 Q_UNUSED(variableController);
46 Q_UNUSED(properties);
56 Q_UNUSED(properties);
@@ -53,11 +63,11 struct UnknownOperation : public IFuzzingOperation {
53 std::unique_ptr<IFuzzingOperation> FuzzingOperationFactory::create(FuzzingOperationType type)
63 std::unique_ptr<IFuzzingOperation> FuzzingOperationFactory::create(FuzzingOperationType type)
54 {
64 {
55 switch (type) {
65 switch (type) {
56 case FuzzingOperationType::CREATE:
66 case FuzzingOperationType::CREATE:
57 return std::make_unique<CreateOperation>();
67 return std::make_unique<CreateOperation>();
58 default:
68 default:
59 // Default case returns unknown operation
69 // Default case returns unknown operation
60 break;
70 break;
61 }
71 }
62
72
63 return std::make_unique<UnknownOperation>();
73 return std::make_unique<UnknownOperation>();
@@ -17,22 +17,24 class VariableController;
17 /**
17 /**
18 * Enumeration of types of existing fuzzing operations
18 * Enumeration of types of existing fuzzing operations
19 */
19 */
20 enum class FuzzingOperationType {
20 enum class FuzzingOperationType { CREATE };
21 CREATE
22 };
23
21
24 /// Interface that represents an operation that can be executed during a fuzzing test
22 /// Interface that represents an operation that can be executed during a fuzzing test
25 struct IFuzzingOperation {
23 struct IFuzzingOperation {
26 virtual ~IFuzzingOperation() noexcept = default;
24 virtual ~IFuzzingOperation() noexcept = default;
27
25
28 /// Checks if the operation can be executed according to the current state of the variable passed in parameter
26 /// Checks if the operation can be executed according to the current state of the variable
27 /// passed in parameter
29 virtual bool canExecute(std::shared_ptr<Variable> variable) const = 0;
28 virtual bool canExecute(std::shared_ptr<Variable> variable) const = 0;
30 /// Executes the operation on the variable passed in parameter
29 /// Executes the operation on the variable passed in parameter
31 /// @param variable the variable on which to execute the operation
30 /// @param variable the variable on which to execute the operation
32 /// @param variableController the controller associated to the operation
31 /// @param variableController the controller associated to the operation
33 /// @param properties properties that can be used to configure the operation
32 /// @param properties properties that can be used to configure the operation
34 /// @remarks variable is passed as a reference because, according to the operation, it can be modified (in/out parameter)
33 /// @remarks variable is passed as a reference because, according to the operation, it can be
35 virtual void execute(std::shared_ptr<Variable> &variable, VariableController& variableController, const Properties& properties = {}) const = 0;
34 /// modified (in/out parameter)
35 virtual void execute(std::shared_ptr<Variable> &variable,
36 VariableController &variableController,
37 const Properties &properties = {}) const = 0;
36 };
38 };
37
39
38 /// Factory of @sa IFuzzingOperation
40 /// Factory of @sa IFuzzingOperation
@@ -16,9 +16,10 public:
16 /// Generates a random int between [min, max]
16 /// Generates a random int between [min, max]
17 int generateInt(int min, int max);
17 int generateInt(int min, int max);
18
18
19 /// Returns a random element among the elements of a container. If the container is empty, returns an element built by default
19 /// Returns a random element among the elements of a container. If the container is empty,
20 /// returns an element built by default
20 template <typename T, typename ValueType = typename T::value_type>
21 template <typename T, typename ValueType = typename T::value_type>
21 ValueType randomChoice(const T& container);
22 ValueType randomChoice(const T &container);
22
23
23 private:
24 private:
24 std::mt19937 m_Mt;
25 std::mt19937 m_Mt;
@@ -26,10 +27,10 private:
26 explicit RandomGenerator();
27 explicit RandomGenerator();
27 };
28 };
28
29
29 template<typename T, typename ValueType>
30 template <typename T, typename ValueType>
30 ValueType RandomGenerator::randomChoice(const T &container)
31 ValueType RandomGenerator::randomChoice(const T &container)
31 {
32 {
32 if(container.empty()){
33 if (container.empty()) {
33 return ValueType{};
34 return ValueType{};
34 }
35 }
35
36
@@ -38,4 +39,3 ValueType RandomGenerator::randomChoice(const T &container)
38 }
39 }
39
40
40 #endif // SCIQLOP_FUZZINGUTILS
41 #endif // SCIQLOP_FUZZINGUTILS
41
General Comments 0
You need to be logged in to leave comments. Login now