Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/tests/InternalTest.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file InternalTest.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Mar 2025
17
///
18
// Class used for internal tests
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <string>
24
#include <vector>
25
#include <map>
26
27
#include <utils/foxtools/fxheader.h>
28
29
// ===========================================================================
30
// class declaration
31
// ===========================================================================
32
33
class InternalTestStep;
34
35
// ===========================================================================
36
// class definitions
37
// ===========================================================================
38
39
class InternalTest : public FXObject {
40
41
public:
42
/// @brief view position
43
class ViewPosition {
44
45
public:
46
/// @brief default constructor
47
ViewPosition();
48
49
/// @brief parameter constructor (string)
50
ViewPosition(const int xValue, const int yValue);
51
52
/// @brief parameter constructor
53
ViewPosition(const std::string& xValue, const std::string& yValue);
54
55
/// @brief get x value
56
int getX() const;
57
58
/// @brief get y value
59
int getY() const;
60
61
private:
62
/// @brief x value
63
int myX = 0;
64
65
/// @brief y value
66
int myY = 0;
67
};
68
69
/// @brief contextual menu
70
struct ContextualMenu {
71
72
public:
73
/// @brief default constructor
74
ContextualMenu();
75
76
/// @brief constructor
77
ContextualMenu(const std::string& mainMenuValue, const std::string& subMenuAValue,
78
const std::string& subMenuBValue);
79
80
/// @brief get main menu position
81
int getMainMenuPosition() const;
82
83
/// @brief get submenu A position
84
int getSubMenuAPosition() const;
85
86
/// @brief get submenu B position
87
int getSubMenuBPosition() const;
88
89
private:
90
/// @brief main manue
91
int myMainMenu = 0;
92
93
/// @brief submenu A
94
int mySubMenuA = 0;
95
96
/// @brief submenu B
97
int mySubMenuB = 0;
98
};
99
100
/// @brief view position
101
class Movement {
102
103
public:
104
/// @brief default constructor
105
Movement();
106
107
/// @brief constructor
108
Movement(const std::string& up, const std::string& down,
109
const std::string& left, const std::string& right);
110
111
/// @brief get up value
112
int getUp() const;
113
114
/// @brief get down value
115
int getDown() const;
116
117
/// @brief get left value
118
int getLeft() const;
119
120
/// @brief get right value
121
int getRight() const;
122
123
private:
124
/// @brief up value
125
int myUp = 0;
126
127
/// @brief down value
128
int myDown = 0;
129
130
/// @brief left value
131
int myLeft = 0;
132
133
/// @brief right value
134
int myRight = 0;
135
};
136
137
/// @brief constructor
138
InternalTest(const std::string& testFile);
139
140
/// @brief destructor
141
~InternalTest();
142
143
/// @name functions related with test steps
144
/// @{
145
146
/// @brief add test steps
147
void addTestSteps(InternalTestStep* internalTestStep);
148
149
/// @brief get current step
150
InternalTestStep* getCurrentStep() const;
151
152
/// @brief get current step and set next step
153
InternalTestStep* setNextStep();
154
155
/// @}
156
157
/// @brief check if test is running
158
bool isRunning() const;
159
160
/// @brief stop tests
161
void stopTests();
162
163
/// @brief get currentTime
164
FXint getTime() const;
165
166
/// @brief get map with attributesEnum jump steps
167
const std::map<std::string, int>& getAttributesEnum() const;
168
169
/// @brief get map with contextual menu operation jump steps
170
const std::map<std::string, InternalTest::ContextualMenu>& getContextualMenuOperations() const;
171
172
/// @brief get map with view position pairs
173
const std::map<std::string, InternalTest::ViewPosition>& getViewPositions() const;
174
175
/// @brief get map with movement pairs
176
const std::map<std::string, InternalTest::Movement>& getMovements() const;
177
178
/// @brief get last moved position
179
const InternalTest::ViewPosition& getLastMovedPosition() const;
180
181
/// @brief update last moved position
182
void updateLastMovedPosition(const int x, const int y);
183
184
/// @brief interpolate view positions
185
std::vector<InternalTest::ViewPosition> interpolateViewPositions(
186
const InternalTest::ViewPosition& viewStartPosition,
187
const int offsetStartX, const int offsetStartY,
188
const InternalTest::ViewPosition& viewEndPosition,
189
const int offsetEndX, const int offsetEndY) const;
190
191
protected:
192
/// @brief initial test steps
193
InternalTestStep* myInitialTestStep = nullptr;
194
195
/// @brief last test steps
196
InternalTestStep* myLastTestStep = nullptr;
197
198
/// @brief current test step
199
InternalTestStep* myCurrentTestStep = nullptr;
200
201
/// @brief flag to indicate if test is running
202
bool myRunning = false;
203
204
/// @brief flag to check if test was finished
205
bool myTestFinished = false;
206
207
/// @brief vector with attributesEnum jump steps
208
std::map<std::string, int> myAttributesEnum;
209
210
/// @brief vector with contextual menu operation jump steps
211
std::map<std::string, InternalTest::ContextualMenu> myContextualMenuOperations;
212
213
/// @brief vector with view positions
214
std::map<std::string, InternalTest::ViewPosition> myViewPositions;
215
216
/// @brief vector with movements
217
std::map<std::string, InternalTest::Movement> myMovements;
218
219
/// @brief last moved position
220
InternalTest::ViewPosition myLastMovedPosition;
221
222
/// @brief parse attributesEnum file
223
std::map<std::string, int> parseAttributesEnumFile(const std::string filePath) const;
224
225
/// @brief parse attributesEnum file
226
std::map<std::string, InternalTest::ContextualMenu> parseContextualMenuOperationsFile(const std::string filePath) const;
227
228
/// @brief parse viewPositions file
229
std::map<std::string, InternalTest::ViewPosition> parseViewPositionsFile(const std::string filePath) const;
230
231
/// @brief parse movements file
232
std::map<std::string, InternalTest::Movement> parseMovementsFile(const std::string filePath) const;
233
234
/// @brief clear lines
235
std::vector<std::string> cleanLines(const std::vector<std::pair<bool, std::string> >& linesRaw) const;
236
237
/// @brief check if the given string start with
238
bool startWith(const std::string& str, const std::string& prefix) const;
239
240
private:
241
/// @brief invalidate default constructor
242
InternalTest() = delete;
243
244
/// @brief Invalidated copy constructor.
245
InternalTest(const InternalTest&) = delete;
246
247
/// @brief Invalidated assignment operator
248
InternalTest& operator=(const InternalTest& src) = delete;
249
};
250
251