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