@@ -1,4 +1,5 | |||
|
1 | 1 | #include "FuzzingDefs.h" |
|
2 | 2 | |
|
3 | 3 | const QString NB_MAX_OPERATIONS_PROPERTY = QStringLiteral("component"); |
|
4 | 4 | const QString NB_MAX_VARIABLES_PROPERTY = QStringLiteral("nbMaxVariables"); |
|
5 | const QString AVAILABLE_OPERATIONS_PROPERTY = QStringLiteral("availableOperations"); |
@@ -1,21 +1,24 | |||
|
1 | 1 | #ifndef SCIQLOP_FUZZINGDEFS_H |
|
2 | 2 | #define SCIQLOP_FUZZINGDEFS_H |
|
3 | 3 | |
|
4 | 4 | #include <QString> |
|
5 | 5 | // /////// // |
|
6 | 6 | // Aliases // |
|
7 | 7 | // /////// // |
|
8 | 8 | |
|
9 | 9 | using Properties = QVariantHash; |
|
10 | 10 | |
|
11 | 11 | // ///////// // |
|
12 | 12 | // Constants // |
|
13 | 13 | // ///////// // |
|
14 | 14 | |
|
15 | 15 | /// Max number of operations to generate |
|
16 | 16 | extern const QString NB_MAX_OPERATIONS_PROPERTY; |
|
17 | 17 | |
|
18 | 18 | /// Max number of variables to manipulate through operations |
|
19 | 19 | extern const QString NB_MAX_VARIABLES_PROPERTY; |
|
20 | 20 | |
|
21 | /// Set of operations available for the test | |
|
22 | extern const QString AVAILABLE_OPERATIONS_PROPERTY; | |
|
23 | ||
|
21 | 24 | #endif // SCIQLOP_FUZZINGDEFS_H |
@@ -1,133 +1,153 | |||
|
1 | 1 | #include "FuzzingDefs.h" |
|
2 | 2 | #include "FuzzingOperations.h" |
|
3 | 3 | #include <Network/NetworkController.h> |
|
4 | 4 | #include <SqpApplication.h> |
|
5 | 5 | #include <Time/TimeController.h> |
|
6 | 6 | #include <Variable/VariableController.h> |
|
7 | 7 | |
|
8 | 8 | #include <QLoggingCategory> |
|
9 | 9 | #include <QObject> |
|
10 | 10 | #include <QtTest> |
|
11 | 11 | |
|
12 | 12 | #include <memory> |
|
13 | 13 | |
|
14 | 14 | Q_LOGGING_CATEGORY(LOG_TestAmdaFuzzing, "TestAmdaFuzzing") |
|
15 | 15 | |
|
16 | 16 | namespace { |
|
17 | 17 | |
|
18 | 18 | // /////// // |
|
19 | 19 | // Aliases // |
|
20 | 20 | // /////// // |
|
21 | 21 | |
|
22 | 22 | using VariableId = int; |
|
23 | 23 | |
|
24 | 24 | using OperationsPool = std::set<std::shared_ptr<IFuzzingOperation> >; |
|
25 | 25 | using VariablesPool = std::map<VariableId, std::shared_ptr<Variable> >; |
|
26 | 26 | |
|
27 | 27 | // ///////// // |
|
28 | 28 | // Constants // |
|
29 | 29 | // ///////// // |
|
30 | 30 | |
|
31 | 31 | // Defaults values used when the associated properties have not been set for the test |
|
32 | 32 | const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100; |
|
33 | 33 | const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1; |
|
34 | const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE | |
|
35 | = QVariant::fromValue(OperationsTypes{FuzzingOperationType::CREATE}); | |
|
36 | OperationsPool createOperationsPool(const OperationsTypes &types) | |
|
37 | { | |
|
38 | OperationsPool result{}; | |
|
39 | ||
|
40 | std::transform(types.cbegin(), types.cend(), std::inserter(result, result.end()), | |
|
41 | [](const auto &type) { return FuzzingOperationFactory::create(type); }); | |
|
42 | ||
|
43 | return result; | |
|
44 | } | |
|
45 | ||
|
34 | 46 | /** |
|
35 | 47 | * Class to run random tests |
|
36 | 48 | */ |
|
37 | 49 | class FuzzingTest { |
|
38 | 50 | public: |
|
39 | 51 | explicit FuzzingTest(VariableController &variableController, Properties properties) |
|
40 | 52 | : m_VariableController{variableController}, |
|
41 | 53 | m_Properties{std::move(properties)}, |
|
42 | 54 | m_VariablesPool{} |
|
43 | 55 | { |
|
44 | 56 | // Inits variables pool: at init, all variables are null |
|
45 | 57 | for (auto variableId = 0; variableId < nbMaxVariables(); ++variableId) { |
|
46 | 58 | m_VariablesPool[variableId] = nullptr; |
|
47 | 59 | } |
|
48 | 60 | } |
|
49 | 61 | |
|
50 | 62 | void execute() |
|
51 | 63 | { |
|
52 | 64 | /// @todo: complete |
|
53 | 65 | qCInfo(LOG_TestAmdaFuzzing()) << "Running" << nbMaxOperations() << "operations on" |
|
54 | 66 | << nbMaxVariables() << "variables..."; |
|
55 | 67 | |
|
56 | 68 | qCInfo(LOG_TestAmdaFuzzing()) << "Execution of the test completed."; |
|
57 | 69 | } |
|
58 | 70 | |
|
59 | 71 | private: |
|
60 | 72 | int nbMaxOperations() const |
|
61 | 73 | { |
|
62 | 74 | static auto result |
|
63 | 75 | = m_Properties.value(NB_MAX_OPERATIONS_PROPERTY, NB_MAX_OPERATIONS_DEFAULT_VALUE) |
|
64 | 76 | .toInt(); |
|
65 | 77 | return result; |
|
66 | 78 | } |
|
67 | 79 | |
|
68 | 80 | int nbMaxVariables() const |
|
69 | 81 | { |
|
70 | 82 | static auto result |
|
71 | 83 | = m_Properties.value(NB_MAX_VARIABLES_PROPERTY, NB_MAX_VARIABLES_DEFAULT_VALUE).toInt(); |
|
72 | 84 | return result; |
|
73 | 85 | } |
|
74 | 86 | |
|
87 | OperationsPool operationsPool() const | |
|
88 | { | |
|
89 | static auto result = createOperationsPool( | |
|
90 | m_Properties.value(AVAILABLE_OPERATIONS_PROPERTY, AVAILABLE_OPERATIONS_DEFAULT_VALUE) | |
|
91 | .value<OperationsTypes>()); | |
|
92 | return result; | |
|
93 | } | |
|
94 | ||
|
75 | 95 | VariableController &m_VariableController; |
|
76 | 96 | Properties m_Properties; |
|
77 | 97 | VariablesPool m_VariablesPool; |
|
78 | 98 | }; |
|
79 | 99 | |
|
80 | 100 | } // namespace |
|
81 | 101 | |
|
82 | 102 | class TestAmdaFuzzing : public QObject { |
|
83 | 103 | Q_OBJECT |
|
84 | 104 | |
|
85 | 105 | private slots: |
|
86 | 106 | /// Input data for @sa testFuzzing() |
|
87 | 107 | void testFuzzing_data(); |
|
88 | 108 | void testFuzzing(); |
|
89 | 109 | }; |
|
90 | 110 | |
|
91 | 111 | void TestAmdaFuzzing::testFuzzing_data() |
|
92 | 112 | { |
|
93 | 113 | // ////////////// // |
|
94 | 114 | // Test structure // |
|
95 | 115 | // ////////////// // |
|
96 | 116 | |
|
97 | 117 | QTest::addColumn<Properties>("properties"); // Properties for random test |
|
98 | 118 | |
|
99 | 119 | // ////////// // |
|
100 | 120 | // Test cases // |
|
101 | 121 | // ////////// // |
|
102 | 122 | |
|
103 | 123 | ///@todo: complete |
|
104 | 124 | } |
|
105 | 125 | |
|
106 | 126 | void TestAmdaFuzzing::testFuzzing() |
|
107 | 127 | { |
|
108 | 128 | QFETCH(Properties, properties); |
|
109 | 129 | |
|
110 | 130 | auto &variableController = sqpApp->variableController(); |
|
111 | 131 | auto &timeController = sqpApp->timeController(); |
|
112 | 132 | |
|
113 | 133 | FuzzingTest test{variableController, properties}; |
|
114 | 134 | test.execute(); |
|
115 | 135 | } |
|
116 | 136 | |
|
117 | 137 | int main(int argc, char *argv[]) |
|
118 | 138 | { |
|
119 | 139 | QLoggingCategory::setFilterRules( |
|
120 | 140 | "*.warning=false\n" |
|
121 | 141 | "*.info=false\n" |
|
122 | 142 | "*.debug=false\n" |
|
123 | 143 | "FuzzingOperations.info=true\n" |
|
124 | 144 | "TestAmdaFuzzing.info=true\n"); |
|
125 | 145 | |
|
126 | 146 | SqpApplication app{argc, argv}; |
|
127 | 147 | app.setAttribute(Qt::AA_Use96Dpi, true); |
|
128 | 148 | TestAmdaFuzzing testObject{}; |
|
129 | 149 | QTEST_SET_MAIN_SOURCE_PATH |
|
130 | 150 | return QTest::qExec(&testObject, argc, argv); |
|
131 | 151 | } |
|
132 | 152 | |
|
133 | 153 | #include "TestAmdaFuzzing.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now