##// END OF EJS Templates
Fixes clang-format for resource files
Alexandre Leroux -
r1211:08e858e2cf84
parent child
Show More
@@ -1,167 +1,168
1 ## amda - CMakeLists.txt
1 ## amda - CMakeLists.txt
2 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
2 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
3 SET(SQPAMDA_LIBRARY_NAME "${LIBRARY_PREFFIX}_amda${DEBUG_SUFFIX}")
3 SET(SQPAMDA_LIBRARY_NAME "${LIBRARY_PREFFIX}_amda${DEBUG_SUFFIX}")
4 SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
4 SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
5 SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
5 SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
6 SET(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources")
6 SET(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources")
7 SET(TESTS_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests-resources")
7 SET(TESTS_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests-resources")
8
8
9 # Include amda directory
9 # Include amda directory
10 INCLUDE_DIRECTORIES(${INCLUDES_DIR})
10 INCLUDE_DIRECTORIES(${INCLUDES_DIR})
11 INCLUDE_DIRECTORIES(${RESOURCES_DIR})
11 INCLUDE_DIRECTORIES(${RESOURCES_DIR})
12
12
13 #
13 #
14 # Find Qt modules
14 # Find Qt modules
15 #
15 #
16 SCIQLOP_FIND_QT(Core Widgets Network)
16 SCIQLOP_FIND_QT(Core Widgets Network)
17
17
18 #
18 #
19 # Find dependent libraries
19 # Find dependent libraries
20 # ========================
20 # ========================
21
21
22 # sciqlop plugin
22 # sciqlop plugin
23 find_package(sciqlop-plugin)
23 find_package(sciqlop-plugin)
24 INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR})
24 INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR})
25
25
26 # sciqlop core
26 # sciqlop core
27 find_package(sciqlop-core)
27 find_package(sciqlop-core)
28 INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR})
28 INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR})
29 list(APPEND LIBRARIES ${SCIQLOP-CORE_LIBRARIES})
29 list(APPEND LIBRARIES ${SCIQLOP-CORE_LIBRARIES})
30
30
31 # sciqlop gui
31 # sciqlop gui
32 find_package(sciqlop-gui)
32 find_package(sciqlop-gui)
33 INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR})
33 INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR})
34 list(APPEND LIBRARIES ${SCIQLOP-GUI_LIBRARIES})
34 list(APPEND LIBRARIES ${SCIQLOP-GUI_LIBRARIES})
35
35
36 # Description file
36 # Description file
37 FILE (GLOB_RECURSE PLUGIN_FILE ${RESOURCES_DIR}/amda.json)
37 FILE (GLOB_RECURSE PLUGIN_FILE ${RESOURCES_DIR}/amda.json)
38
38
39 # Resources files
39 # Resources files
40 FILE (GLOB_RECURSE PROJECT_RESOURCES ${RESOURCES_DIR}/*.qrc)
40 FILE (GLOB_RECURSE PROJECT_RESOURCES ${RESOURCES_DIR}/*.qrc)
41
41
42 #
42 #
43 # Compile the library
43 # Compile the library
44 #
44 #
45
45
46 ADD_DEFINITIONS(-DAMDA_LIB)
46 ADD_DEFINITIONS(-DAMDA_LIB)
47
47
48 FILE (GLOB_RECURSE MODULE_SOURCES
48 FILE (GLOB_RECURSE MODULE_SOURCES
49 ${INCLUDES_DIR}/*.h
49 ${INCLUDES_DIR}/*.h
50 ${SOURCES_DIR}/*.c
50 ${SOURCES_DIR}/*.c
51 ${SOURCES_DIR}/*.cpp
51 ${SOURCES_DIR}/*.cpp
52 ${SOURCES_DIR}/*.h
52 ${SOURCES_DIR}/*.h
53 ${PLUGIN_FILE})
53 ${PLUGIN_FILE})
54
54
55 QT5_ADD_RESOURCES(RCC_AMDA
55 QT5_ADD_RESOURCES(RCC_AMDA
56 ${PROJECT_RESOURCES}
56 ${PROJECT_RESOURCES}
57 )
57 )
58
58
59 ADD_LIBRARY(${SQPAMDA_LIBRARY_NAME} ${MODULE_SOURCES} ${RCC_AMDA})
59 ADD_LIBRARY(${SQPAMDA_LIBRARY_NAME} ${MODULE_SOURCES} ${RCC_AMDA})
60 set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
60 set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
61 set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
61 set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
62
62
63 INSTALL(TARGETS ${SQPAMDA_LIBRARY_NAME}
63 INSTALL(TARGETS ${SQPAMDA_LIBRARY_NAME}
64 RUNTIME DESTINATION ${INSTALL_BINARY_DIR}
64 RUNTIME DESTINATION ${INSTALL_BINARY_DIR}
65 LIBRARY DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR}
65 LIBRARY DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR}
66 ARCHIVE DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR}
66 ARCHIVE DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR}
67 )
67 )
68
68
69
69
70 TARGET_LINK_LIBRARIES(${SQPAMDA_LIBRARY_NAME} ${LIBRARIES})
70 TARGET_LINK_LIBRARIES(${SQPAMDA_LIBRARY_NAME} ${LIBRARIES})
71 qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets Network)
71 qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets Network)
72
72
73 add_dependencies(${SQPAMDA_LIBRARY_NAME} ${SQPPLUGIN_LIBRARY_NAME} ${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME})
73 add_dependencies(${SQPAMDA_LIBRARY_NAME} ${SQPPLUGIN_LIBRARY_NAME} ${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME})
74
74
75 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
75 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
76 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
76 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
77 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
77 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
78 IF(BUILD_SHARED_LIBS)
78 IF(BUILD_SHARED_LIBS)
79 SET_TARGET_PROPERTIES(${SQPAMDA_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
79 SET_TARGET_PROPERTIES(${SQPAMDA_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
80 ELSE()
80 ELSE()
81 TARGET_COMPILE_DEFINITIONS(${SQPAMDA_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
81 TARGET_COMPILE_DEFINITIONS(${SQPAMDA_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
82 ENDIF()
82 ENDIF()
83
83
84 # Set the variable to parent scope so that the other projects can copy the
84 # Set the variable to parent scope so that the other projects can copy the
85 # dependent shared libraries
85 # dependent shared libraries
86 SCIQLOP_SET_TO_PARENT_SCOPE(SQPAMDA_LIBRARY_NAME)
86 SCIQLOP_SET_TO_PARENT_SCOPE(SQPAMDA_LIBRARY_NAME)
87
87
88 # Copy extern shared libraries to the lib folder
88 # Copy extern shared libraries to the lib folder
89 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPAMDA_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES})
89 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPAMDA_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES})
90
90
91 # Add the files to the list of files to be analyzed
91 # Add the files to the list of files to be analyzed
92 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
92 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
93 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
93 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
94 # Vera++ exclusion files
94 # Vera++ exclusion files
95 LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
95 LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
96 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
96 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
97
97
98 #
98 #
99 # Compile the tests
99 # Compile the tests
100 #
100 #
101 IF(BUILD_TESTS)
101 IF(BUILD_TESTS)
102 INCLUDE_DIRECTORIES(${SOURCES_DIR})
102 INCLUDE_DIRECTORIES(${SOURCES_DIR})
103 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
103 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
104 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
104 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
105 SET( TEST_LIBRARIES ${SQPAMDA_LIBRARY_NAME})
105 SET( TEST_LIBRARIES ${SQPAMDA_LIBRARY_NAME})
106
106
107 FOREACH( testFile ${TESTS_SOURCES} )
107 FOREACH( testFile ${TESTS_SOURCES} )
108 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
108 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
109 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
109 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
110
110
111 # Add to the list of sources files all the sources in the same
111 # Add to the list of sources files all the sources in the same
112 # directory that aren't another test
112 # directory that aren't another test
113 FILE (GLOB currentTestSources
113 FILE (GLOB currentTestSources
114 ${testDirectory}/*.c
114 ${testDirectory}/*.c
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})
121 set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14)
122 set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14)
122 set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON)
123 set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON)
123 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
124 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
124 qt5_use_modules(${testName} Test)
125 qt5_use_modules(${testName} Test)
125
126
126 ADD_TEST( NAME ${testName} COMMAND ${testName} )
127 ADD_TEST( NAME ${testName} COMMAND ${testName} )
127
128
128 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
129 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
129 ENDFOREACH( testFile )
130 ENDFOREACH( testFile )
130
131
131 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
132 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
132 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
133 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
133 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
134 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
134 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
135 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
135
136
136 ADD_DEFINITIONS(-DAMDA_TESTS_RESOURCES_DIR="${TESTS_RESOURCES_DIR}")
137 ADD_DEFINITIONS(-DAMDA_TESTS_RESOURCES_DIR="${TESTS_RESOURCES_DIR}")
137 ENDIF(BUILD_TESTS)
138 ENDIF(BUILD_TESTS)
138
139
139 #
140 #
140 # Set the files that must be formatted by clang-format.
141 # Set the files that must be formatted by clang-format.
141 #
142 #
142 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
143 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
143 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
144 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
144
145
145 #
146 #
146 # Set the directories that doxygen must browse to generate the
147 # Set the directories that doxygen must browse to generate the
147 # documentation.
148 # documentation.
148 #
149 #
149 # Source directories:
150 # Source directories:
150 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
151 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
151 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
152 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
152 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
153 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
153 # Source directories to exclude from the documentation generation
154 # Source directories to exclude from the documentation generation
154 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
155 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
155 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
156 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
156
157
157 #
158 #
158 # Set the directories with the sources to analyze and propagate the
159 # Set the directories with the sources to analyze and propagate the
159 # modification to the parent scope
160 # modification to the parent scope
160 #
161 #
161 # Source directories to analyze:
162 # Source directories to analyze:
162 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
163 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
163 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
164 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
164 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
165 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
165 # Source directories to exclude from the analysis
166 # Source directories to exclude from the analysis
166 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
167 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
167 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
168 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
@@ -1,64 +1,74
1 #include "FuzzingOperations.h"
1 #include "FuzzingOperations.h"
2 #include "FuzzingUtils.h"
2 #include "FuzzingUtils.h"
3
3
4 #include <Data/IDataProvider.h>
4 #include <Data/IDataProvider.h>
5
5
6 #include <Variable/Variable.h>
6 #include <Variable/Variable.h>
7 #include <Variable/VariableController.h>
7 #include <Variable/VariableController.h>
8
8
9 #include <QUuid>
9 #include <QUuid>
10
10
11 Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations")
11 Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations")
12
12
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);
47 // Does nothing
57 // Does nothing
48 }
58 }
49 };
59 };
50
60
51 } // namespace
61 } // namespace
52
62
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>();
64 }
74 }
@@ -1,47 +1,49
1 #ifndef SCIQLOP_FUZZINGOPERATIONS_H
1 #ifndef SCIQLOP_FUZZINGOPERATIONS_H
2 #define SCIQLOP_FUZZINGOPERATIONS_H
2 #define SCIQLOP_FUZZINGOPERATIONS_H
3
3
4 #include "FuzzingDefs.h"
4 #include "FuzzingDefs.h"
5
5
6 #include <memory>
6 #include <memory>
7 #include <set>
7 #include <set>
8
8
9 #include <QLoggingCategory>
9 #include <QLoggingCategory>
10 #include <QMetaType>
10 #include <QMetaType>
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingOperations)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingOperations)
13
13
14 class Variable;
14 class Variable;
15 class VariableController;
15 class VariableController;
16
16
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
39 struct FuzzingOperationFactory {
41 struct FuzzingOperationFactory {
40 /// Creates a fuzzing operation from a type
42 /// Creates a fuzzing operation from a type
41 static std::unique_ptr<IFuzzingOperation> create(FuzzingOperationType type);
43 static std::unique_ptr<IFuzzingOperation> create(FuzzingOperationType type);
42 };
44 };
43
45
44 using OperationsTypes = std::set<FuzzingOperationType>;
46 using OperationsTypes = std::set<FuzzingOperationType>;
45 Q_DECLARE_METATYPE(OperationsTypes)
47 Q_DECLARE_METATYPE(OperationsTypes)
46
48
47 #endif // SCIQLOP_FUZZINGOPERATIONS_H
49 #endif // SCIQLOP_FUZZINGOPERATIONS_H
@@ -1,41 +1,41
1 #ifndef SCIQLOP_FUZZINGUTILS_H
1 #ifndef SCIQLOP_FUZZINGUTILS_H
2 #define SCIQLOP_FUZZINGUTILS_H
2 #define SCIQLOP_FUZZINGUTILS_H
3
3
4 #include <random>
4 #include <random>
5
5
6 /**
6 /**
7 * Class that proposes random utility methods
7 * Class that proposes random utility methods
8 */
8 */
9 class RandomGenerator {
9 class RandomGenerator {
10 public:
10 public:
11 /// @return the unique instance of the random generator
11 /// @return the unique instance of the random generator
12 static RandomGenerator &instance();
12 static RandomGenerator &instance();
13
13
14 /// Generates a random double between [min, max]
14 /// Generates a random double between [min, max]
15 double generateDouble(double min, double max);
15 double generateDouble(double min, double max);
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;
25
26
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
36 auto randomIndex = generateInt(0, container.size() - 1);
37 auto randomIndex = generateInt(0, container.size() - 1);
37 return container.at(randomIndex);
38 return container.at(randomIndex);
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