Directory: | ./ |
---|---|
File: | src/PMockControlBackend.cpp |
Date: | 2024-12-09 11:00:39 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 267 | 301 | 88.7% |
Branches: | 342 | 545 | 62.8% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #include "string_utils.h" | ||
8 | #include "phoenix_mockControlBackend.h" | ||
9 | |||
10 | #include "PMockControlBackend.h" | ||
11 | |||
12 | ///Get the name of the mock file | ||
13 | /** @param mockDirectory : directory where to write or read mock files | ||
14 | * @param hostName : name of the host which owns the variable or function | ||
15 | * @param methodName : name of the method to be used (push, pull, call, etc) | ||
16 | * @param varName : name of the variable managed by the mock | ||
17 | * @return corresponding file name | ||
18 | */ | ||
19 | 26 | std::string phoenix_getControlMockFileVar(const std::string & mockDirectory, const std::string & hostName, const std::string & methodName, const std::string & varName){ | |
20 |
6/6✓ Branch 2 taken 26 times.
✓ Branch 5 taken 26 times.
✓ Branch 8 taken 26 times.
✓ Branch 11 taken 26 times.
✓ Branch 14 taken 26 times.
✓ Branch 17 taken 26 times.
|
52 | return mockDirectory + "/mock_" + hostName + "_" +methodName+"_" + varName + ".pmockvar"; |
21 | } | ||
22 | |||
23 | ///Get the name of the mock file | ||
24 | /** @param mockDirectory : directory where to write or read mock files | ||
25 | * @param hostName : name of the host which owns the variable or function | ||
26 | * @param methodName : name of the method managed by the mock | ||
27 | * @return corresponding file name | ||
28 | */ | ||
29 | 5 | std::string phoenix_getControlMockFileMethod(const std::string & mockDirectory, const std::string & hostName, const std::string & methodName){ | |
30 |
4/4✓ Branch 2 taken 5 times.
✓ Branch 5 taken 5 times.
✓ Branch 8 taken 5 times.
✓ Branch 11 taken 5 times.
|
10 | return mockDirectory + "/mock_" + hostName + "_call_" + methodName + ".pmockmethod"; |
31 | } | ||
32 | |||
33 | ///Create a PMockControlParam | ||
34 | /** @param isMockRecord : True to record the activity of the backend durring real use to make reusable mock | ||
35 | * @param mockDirectory : Directory where to find mock files | ||
36 | * @param logLevel : level of log to be used in the backend | ||
37 | * @return PMockControlParam | ||
38 | */ | ||
39 | 17 | PMockControlParam phoenix_mockControlParam(bool isMockRecord, const std::string & mockDirectory, const std::string & logLevel){ | |
40 | 17 | return phoenix_mockControlParam(isMockRecord, mockDirectory, phoenix_strToLogLevel(logLevel)); | |
41 | } | ||
42 | |||
43 | ///Create a PMockControlParam | ||
44 | /** @param isMockRecord : True to record the activity of the backend durring real use to make reusable mock | ||
45 | * @param mockDirectory : Directory where to find mock files | ||
46 | * @param logLevel : level of log to be used in the backend | ||
47 | * @return PMockControlParam | ||
48 | */ | ||
49 | 45 | PMockControlParam phoenix_mockControlParam(bool isMockRecord, const std::string & mockDirectory, PLog::Level logLevel){ | |
50 | 45 | PMockControlParam param; | |
51 | 45 | param.isMockRecord = isMockRecord; | |
52 |
1/1✓ Branch 1 taken 45 times.
|
45 | param.mockDirectory = mockDirectory; |
53 | 45 | param.logLevel = logLevel; | |
54 | 45 | return param; | |
55 | } | ||
56 | |||
57 | ///Create a PMockManagerParam | ||
58 | /** @param name : name of the manager | ||
59 | * @param isMockRecord : True to record the activity of the backend durring real use to make reusable mock | ||
60 | * @param mockDirectory : Directory where to find mock files | ||
61 | * @param logLevel : level of log to be used in the backend | ||
62 | * @return PMockControlParam | ||
63 | */ | ||
64 | 43 | PMockManagerParam phoenix_mockManagerParam(const std::string & name, bool isMockRecord, const std::string & mockDirectory, PLog::Level logLevel){ | |
65 | 43 | PMockManagerParam param; | |
66 |
1/1✓ Branch 1 taken 43 times.
|
43 | param.name = name; |
67 | 43 | param.isMockRecord = isMockRecord; | |
68 |
1/1✓ Branch 1 taken 43 times.
|
43 | param.mockDirectory = mockDirectory; |
69 | 43 | param.logLevel = logLevel; | |
70 | 43 | return param; | |
71 | } | ||
72 | |||
73 | ///Create a PMockControlParam | ||
74 | /** @param isMockRecord : True to record the activity of the backend durring real use to make reusable mock | ||
75 | * @param logDirectory : Directory where to find mock files | ||
76 | * @param logLevel : level of log to be used in the backend | ||
77 | * @return PMockControlParam | ||
78 | */ | ||
79 | 14 | PMockControlBackend::Param PMockControlBackend::defaultParam(bool isMockRecord, const std::string & logDirectory, PLog::Level logLevel){ | |
80 | 14 | return phoenix_mockControlParam(isMockRecord, logDirectory, logLevel); | |
81 | } | ||
82 | |||
83 | ///Create a PMockControlBackend | ||
84 | /** @param name : name of the manager | ||
85 | * @param isMockRecord : True to record the activity of the backend durring real use to make reusable mock | ||
86 | * @param logDirectory : Directory where to find mock files | ||
87 | * @param logLevel : level of log to be used in the backend | ||
88 | * @return PMockControlParam | ||
89 | */ | ||
90 | 43 | PMockControlBackend::MgrParam PMockControlBackend::defaultMgrParam(const std::string & name, bool isMockRecord, const std::string & logDirectory, PLog::Level logLevel){ | |
91 | 43 | return phoenix_mockManagerParam(name, isMockRecord, logDirectory, logLevel); | |
92 | } | ||
93 | |||
94 | ///Contructor of the Backend | ||
95 | ✗ | PMockControlBackend::PMockControlBackend(){ | |
96 | |||
97 | } | ||
98 | |||
99 | ///Initialise the data manager | ||
100 | /** @param[out] manager : data manager to be initlialised | ||
101 | * @param param : parameters to be used to initialised the manager | ||
102 | * @return true on success, false otherwise | ||
103 | */ | ||
104 | 43 | bool PMockControlBackend::initialiseDataManager(PMockControlBackend::Manager & manager, const PMockControlBackend::MgrParam & param){ | |
105 |
1/1✓ Branch 1 taken 43 times.
|
43 | manager.name = param.name; |
106 | 43 | manager.isMockRecord = param.isMockRecord; | |
107 |
1/1✓ Branch 1 taken 43 times.
|
43 | manager.mockDirectory = param.mockDirectory; |
108 | 43 | manager.eventId = 0lu; | |
109 | 43 | const std::string & mockDirectory = param.mockDirectory; | |
110 |
1/1✓ Branch 1 taken 43 times.
|
43 | createDirectoriesIfNotExist(mockDirectory); |
111 |
1/1✓ Branch 1 taken 43 times.
|
43 | std::string logDirectory(mockDirectory + "/log/"); |
112 |
1/1✓ Branch 1 taken 43 times.
|
43 | createDirectoriesIfNotExist(logDirectory); |
113 | 43 | PLog & logger = manager.logger; | |
114 |
4/4✓ Branch 1 taken 43 times.
✓ Branch 4 taken 43 times.
✓ Branch 7 taken 43 times.
✓ Branch 10 taken 43 times.
|
43 | logger.setFileName(logDirectory + "/manager_"+manager.name+".log"); |
115 |
1/1✓ Branch 1 taken 43 times.
|
43 | logger.setLogLevel(param.logLevel); |
116 |
2/3✓ Branch 1 taken 43 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 43 times.
|
43 | if(!logger.open()){return false;}; |
117 |
7/7✓ Branch 1 taken 43 times.
✓ Branch 4 taken 43 times.
✓ Branch 7 taken 43 times.
✓ Branch 10 taken 43 times.
✓ Branch 13 taken 43 times.
✓ Branch 16 taken 43 times.
✓ Branch 19 taken 43 times.
|
43 | logger.getLogInfo() << "Manager('"<<manager.name<<"') : Log Directory '"<<logDirectory<<"'" << std::endl; |
118 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 42 times.
|
43 | if(manager.isMockRecord){ |
119 |
1/1✓ Branch 1 taken 1 times.
|
1 | std::string mockRecordDirectory(mockDirectory + "/record"); |
120 |
1/1✓ Branch 1 taken 1 times.
|
1 | createDirectoriesIfNotExist(mockRecordDirectory); |
121 |
5/5✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
|
1 | logger.getLogInfo() << "Manager('"<<manager.name<<"') : Mode record activated" << std::endl; |
122 |
7/7✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
|
1 | logger.getLogInfo() << "Manager('"<<manager.name<<"') : Record Directory '"<<mockRecordDirectory<<"'" << std::endl; |
123 |
1/1✓ Branch 1 taken 1 times.
|
1 | manager.mockDirectory = mockRecordDirectory; |
124 | 1 | }else{ | |
125 |
5/5✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
✓ Branch 7 taken 42 times.
✓ Branch 10 taken 42 times.
✓ Branch 13 taken 42 times.
|
42 | logger.getLogInfo() << "Manager('"<<manager.name<<"') : Mode replay activated" << std::endl; |
126 | } | ||
127 | 43 | return true; | |
128 | 43 | } | |
129 | |||
130 | ///Create a client connector | ||
131 | /** @param manager : manager to be used to create the client | ||
132 | * @param[out] connector : connector to be created | ||
133 | * @param address : address of the server, the client has to connect to | ||
134 | * @param param : extra customisable parameters for the creation of the connector (depends on the backend) | ||
135 | * @return true if the connector has been created, false otherwise | ||
136 | */ | ||
137 | 25 | bool PMockControlBackend::createClientConnector(PMockControlBackend::Manager & manager, PMockControlBackend::Connector & connector, const std::string & address, const PMockControlBackend::Param & param){ | |
138 |
2/2✓ Branch 2 taken 25 times.
✓ Branch 5 taken 25 times.
|
25 | return PMockControlBackend::createConnector(manager, connector, "client", address, param); |
139 | } | ||
140 | |||
141 | ///Create a server connector | ||
142 | /** @param manager : manager to be used to create the server | ||
143 | * @param[out] connector : connector to be created | ||
144 | * @param address : address of the server, the client has to connect to | ||
145 | * @param param : extra customisable parameters for the creation of the connector (depends on the backend) | ||
146 | * @return true if the connector has been created, false otherwise | ||
147 | */ | ||
148 | 2 | bool PMockControlBackend::createServerConnector(PMockControlBackend::Manager & manager, PMockControlBackend::Connector & connector, const std::string & address, const PMockControlBackend::Param & param){ | |
149 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
|
2 | return PMockControlBackend::createConnector(manager, connector, "server", address, param); |
150 | } | ||
151 | |||
152 | |||
153 | ///Regiter a variable which can be used by the given connector | ||
154 | /** @param connector : connector to be used | ||
155 | * @param composeVar : variable to be used (can have a complex type) | ||
156 | * @return true on success, false otherwise | ||
157 | */ | ||
158 | 15 | bool PMockControlBackend::registerVar(PMockControlBackend::Connector & connector, const PComposeVar & composeVar){ | |
159 | 15 | bool b(true); | |
160 | 15 | PLog & logger = *connector.logger; | |
161 | 15 | PComposeVar* var = phoenix_findConnectorData(connector.mapRegisterVar, composeVar.getName()); | |
162 |
1/2✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
|
15 | if(var == NULL){ |
163 | 15 | connector.mapRegisterVar[composeVar.getName()] = composeVar; | |
164 |
5/5✓ Branch 4 taken 15 times.
✓ Branch 7 taken 15 times.
✓ Branch 10 taken 15 times.
✓ Branch 13 taken 15 times.
✓ Branch 16 taken 15 times.
|
15 | logger.getLogInfo() << "Register Var '"<<ts_pcomposeVarToStr(composeVar)<<"' to host '"<<connector.hostname<<"'" << std::endl; |
165 | }else{ | ||
166 | ✗ | logger.getLogError() << "Already registered Var '"<<ts_pcomposeVarToStr(composeVar)<<"' to host '"<<connector.hostname<<"'" << std::endl; | |
167 | ✗ | b = false; | |
168 | } | ||
169 | 15 | return b; | |
170 | } | ||
171 | |||
172 | ///Regiter a method which can be called by the given connector | ||
173 | /** @param connector : connector to be used | ||
174 | * @param prototype : prototype of the method to be called | ||
175 | * @return true on success, false otherwise | ||
176 | */ | ||
177 | 3 | bool PMockControlBackend::registerCall(PMockControlBackend::Connector & connector, const PFunctionPrototype & prototype){ | |
178 | 3 | bool b(true); | |
179 | 3 | PLog & logger = *connector.logger; | |
180 | 3 | PFunctionPrototype* function = phoenix_findConnectorData(connector.mapRegisterMethod, prototype.getName()); | |
181 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if(function == NULL){ |
182 | 3 | connector.mapRegisterMethod[prototype.getName()] = prototype; | |
183 |
5/5✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
✓ Branch 16 taken 3 times.
|
3 | logger.getLogInfo() << "Register Call '"<<ts_protoTypeToStr(prototype)<<"' to host '"<<connector.hostname<<"'" << std::endl; |
184 | }else{ | ||
185 | ✗ | logger.getLogError() << "Already registered Method '"<<ts_protoTypeToStr(prototype)<<"' to host '"<<connector.hostname<<"'" << std::endl; | |
186 | ✗ | b = false; | |
187 | } | ||
188 | 3 | return b; | |
189 | } | ||
190 | |||
191 | |||
192 | ///Push a value in the server/client describes by the connector | ||
193 | /** @param connector : connector to be used | ||
194 | * @param varName : name of the variable to be pushed | ||
195 | * @param value : value of the variable to be pushed | ||
196 | * @return true on success, false otherwise | ||
197 | */ | ||
198 | 112 | bool PMockControlBackend::push(PMockControlBackend::Connector & connector, const std::string & varName, const PMockControlBackend::Message & value){ | |
199 | 112 | PLog & logger = *connector.logger; | |
200 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 111 times.
|
112 | if(!checkIfVarIsRegister(connector, varName)){ |
201 | 1 | logger.getLogError() << "push : variable '"<<varName<<"' for host '"<<connector.hostname<<"' not registered" << std::endl; | |
202 | 1 | return false; | |
203 | } | ||
204 | 111 | PMockConnectorVar* var = phoenix_findConnectorData(connector.mapPush, varName); | |
205 |
2/2✓ Branch 0 taken 99 times.
✓ Branch 1 taken 12 times.
|
111 | if(var != NULL){ //If the variable is already known by the Connector we used the corresponding PMockConnectorVar in mapPush |
206 |
2/2✓ Branch 1 taken 54 times.
✓ Branch 2 taken 45 times.
|
99 | if(var->getIsWriteMode()){ |
207 | //Let's append the value in the data | ||
208 | 54 | phoenix_connectorVarAppend(connector, *var, varName, value); | |
209 | }else{ | ||
210 | //If the corresponding mock file does exist we will check if the value is the same as expected | ||
211 | 45 | phoenix_connectorVarCheck(connector, *var, varName, value); | |
212 | } | ||
213 | }else{ //If the var is not known we will create the proper entry | ||
214 |
1/1✓ Branch 1 taken 12 times.
|
12 | PMockConnectorVar tmpVar; |
215 |
2/2✓ Branch 2 taken 12 times.
✓ Branch 5 taken 12 times.
|
24 | std::string mockFileName(phoenix_getControlMockFileVar(connector.mockDirectory, connector.hostname, "push", varName)); |
216 |
1/1✓ Branch 1 taken 12 times.
|
12 | tmpVar.setFileNameMock(mockFileName); |
217 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if(connector.isMockRecord){ |
218 | ✗ | logger.getLogInfo() << "Create Mock for host '"<<connector.hostname<<"' and variable '"<<varName<<"' push will be saved in file '"<<mockFileName<<"'" << std::endl; | |
219 | ✗ | tmpVar.setIsWriteMode(true); | |
220 | ✗ | phoenix_connectorVarAppend(connector, tmpVar, varName, value); | |
221 | }else{ | ||
222 | //If the variable if not known yet we try to find the corresponding mock file | ||
223 |
3/3✓ Branch 1 taken 12 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 7 times.
|
12 | if(data_load(mockFileName, tmpVar)){ |
224 |
9/9✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
✓ Branch 13 taken 5 times.
✓ Branch 16 taken 5 times.
✓ Branch 19 taken 5 times.
✓ Branch 22 taken 5 times.
✓ Branch 25 taken 5 times.
|
5 | logger.getLogInfo() << "Mock file for host '"<<connector.hostname<<"' and variable '"<<varName<<"' push found at '"<<mockFileName<<"'" << std::endl; |
225 | //So we are in read mode in this case | ||
226 |
1/1✓ Branch 1 taken 5 times.
|
5 | tmpVar.setIsWriteMode(false); |
227 | //If the corresponding mock file does exist we will check if the value is the same as expected | ||
228 |
1/1✓ Branch 1 taken 5 times.
|
5 | phoenix_connectorVarCheck(connector, tmpVar, varName, value); |
229 | }else{ | ||
230 | //If the corresponding mock file does not exist we will record the pushed value to create the mock of this variable at the end of the program | ||
231 |
1/1✓ Branch 1 taken 7 times.
|
7 | phoenix_connectorVarAppend(connector, tmpVar, varName, value); |
232 | //We do not forget to say the mock is just beeing written to avoid conflict with the other part of this function | ||
233 |
1/1✓ Branch 1 taken 7 times.
|
7 | tmpVar.setIsWriteMode(true); |
234 | } | ||
235 | } | ||
236 | //Let's add the PMockConnectorVar in the map of push | ||
237 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | connector.mapPush[varName] = tmpVar; |
238 | 12 | } | |
239 | //Let's increment the event id of the connector | ||
240 | 111 | ++connector.eventId; | |
241 | 111 | return true; | |
242 | } | ||
243 | |||
244 | ///Pull value from a server/client | ||
245 | /** @param[out] connector : connector to be used | ||
246 | * @param varName : variable name to pull the value from | ||
247 | * @param[out] value : pulled binary data | ||
248 | * @return true on success, false otherwise | ||
249 | */ | ||
250 | 30 | bool PMockControlBackend::pull(PMockControlBackend::Connector & connector, const std::string & varName, PMockControlBackend::Message & value){ | |
251 | 30 | PLog & logger = *connector.logger; | |
252 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
|
30 | if(!checkIfVarIsRegister(connector, varName)){ |
253 | ✗ | logger.getLogError() << "pull : variable '"<<varName<<"' for host '"<<connector.hostname<<"' not registered" << std::endl; | |
254 | ✗ | return false; | |
255 | } | ||
256 | 30 | PMockConnectorVar* var = phoenix_findConnectorData(connector.mapPull, varName); | |
257 | 30 | bool b(true); | |
258 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3 times.
|
30 | if(var != NULL){ //If the variable is already known by the Connector we used the corresponding PMockConnectorVar in mapPush |
259 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 2 taken 18 times.
|
27 | if(var->getIsWriteMode()){ |
260 | //Let's append the value in the data | ||
261 | 9 | phoenix_connectorVarAppend(connector, *var, varName, value); | |
262 | }else{ | ||
263 | 18 | phoenix_connectorVarRead(connector, *var, varName, value); | |
264 | } | ||
265 | }else{ | ||
266 |
1/1✓ Branch 1 taken 3 times.
|
3 | PMockConnectorVar tmpVar; |
267 |
2/2✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
|
6 | std::string mockFileName(phoenix_getControlMockFileVar(connector.mockDirectory, connector.hostname, "pull", varName)); |
268 |
1/1✓ Branch 1 taken 3 times.
|
3 | tmpVar.setFileNameMock(mockFileName); |
269 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if(connector.isMockRecord){ |
270 |
9/9✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 25 taken 1 times.
|
1 | logger.getLogInfo() << "Create Mock for host '"<<connector.hostname<<"' and variable '"<<varName<<"' pull will be stored to file '"<<mockFileName<<"'" << std::endl; |
271 |
1/1✓ Branch 1 taken 1 times.
|
1 | tmpVar.setIsWriteMode(true); |
272 |
1/1✓ Branch 1 taken 1 times.
|
1 | phoenix_connectorVarAppend(connector, tmpVar, varName, value); |
273 | }else{ | ||
274 |
9/9✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
|
2 | logger.getLogInfo() << "Create Mock for host '"<<connector.hostname<<"' and variable '"<<varName<<"' pull will be loaded from file '"<<mockFileName<<"'" << std::endl; |
275 | //If the variable if not known yet we try to find the corresponding mock file | ||
276 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | if(data_load(mockFileName, tmpVar)){ |
277 |
9/9✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
|
2 | logger.getLogInfo() << "Mock file for host '"<<connector.hostname<<"' and variable '"<<varName<<"' pull found at '"<<mockFileName<<"'" << std::endl; |
278 |
1/1✓ Branch 1 taken 2 times.
|
2 | tmpVar.setIsWriteMode(false); |
279 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | if(tmpVar.getVecEvent().size() != 0lu){ |
280 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
|
2 | value = tmpVar.getVecEvent().front().getVecData(); |
281 |
1/1✓ Branch 1 taken 2 times.
|
2 | tmpVar.setCurrentInputMessageIndex(1lu); //Let's increment the index |
282 | }else{ | ||
283 | ✗ | logger.getLogError() << "Mock file for host '"<<connector.hostname<<"' and variable '"<<varName<<"' pull no events in file '"<<mockFileName<<"'" << std::endl; | |
284 | ✗ | b = false; | |
285 | } | ||
286 | }else{ | ||
287 | ✗ | logger.getLogError() << "Mock file for host '"<<connector.hostname<<"' and variable '"<<varName<<"' pull not found at '"<<mockFileName<<"'" << std::endl; | |
288 | ✗ | b =false; | |
289 | } | ||
290 | } | ||
291 | //Let's add the PMockConnectorVar in the map of push | ||
292 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | connector.mapPull[varName] = tmpVar; |
293 | 3 | } | |
294 | //Let's increment the event id of the connector | ||
295 | 30 | ++connector.eventId; | |
296 | 30 | return b; | |
297 | } | ||
298 | |||
299 | ///Call a method on a remote client/server | ||
300 | /** @param[out] connector : Connector to be used | ||
301 | * @param[out] methodCall : method to be called | ||
302 | * @return true on success, false otherwise | ||
303 | */ | ||
304 | 30 | bool PMockControlBackend::call(PMockControlBackend::Connector & connector, PFunctionCall & methodCall){ | |
305 | 30 | PLog & logger = *connector.logger; | |
306 | 30 | std::string & functionName = methodCall.getPrototype().getName(); | |
307 |
4/4✓ Branch 3 taken 30 times.
✓ Branch 6 taken 30 times.
✓ Branch 10 taken 30 times.
✓ Branch 13 taken 30 times.
|
30 | std::cerr << "PMockControlBackend::call : method = '" << ts_pfunctioncallToStr(methodCall) << "', registerCall = " << connector.mapRegisterMethod.size() << std::endl; |
308 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
|
30 | if(!checkIfMethodIsRegister(connector, functionName)){ |
309 | ✗ | logger.getLogError() << "Call : method '"<<functionName<<"' for host '"<<connector.hostname<<"' not registered" << std::endl; | |
310 | ✗ | return false; | |
311 | } | ||
312 | 30 | std::vector<PMockControlBackend::Message> & vecParam = methodCall.getVecParam(); | |
313 | 30 | std::vector<PMockControlBackend::Message> & vecResult = methodCall.getVecResult(); | |
314 | |||
315 | 30 | bool b(true); | |
316 | 30 | PMockConnectorCall* call = phoenix_findConnectorData(connector.mapCallMethod, functionName); | |
317 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3 times.
|
30 | if(call != NULL){ //If the variable is already known by the Connector we used the corresponding PMockConnectorVar in mapPush |
318 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 2 taken 18 times.
|
27 | if(call->getIsWriteMode()){ |
319 | //Let's append the value in the data | ||
320 | 9 | phoenix_connectorCallAppend(connector, *call, vecResult, functionName, vecParam); | |
321 | }else{ | ||
322 | 18 | phoenix_connectorCallRead(connector, *call, vecResult, functionName, vecParam); | |
323 | } | ||
324 | }else{ | ||
325 |
1/1✓ Branch 1 taken 3 times.
|
3 | PMockConnectorCall tmpCall; |
326 |
1/1✓ Branch 1 taken 3 times.
|
3 | std::string mockFileName(phoenix_getControlMockFileMethod(connector.mockDirectory, connector.hostname, functionName)); |
327 |
1/1✓ Branch 1 taken 3 times.
|
3 | tmpCall.setFileNameMock(mockFileName); |
328 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if(connector.isMockRecord){ |
329 |
9/9✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 25 taken 1 times.
|
1 | logger.getLogInfo() << "Create Mock for host '"<<connector.hostname<<"' and call '"<<functionName<<"' will be stored to file '"<<mockFileName<<"'" << std::endl; |
330 |
1/1✓ Branch 1 taken 1 times.
|
1 | tmpCall.setIsWriteMode(true); |
331 |
1/1✓ Branch 1 taken 1 times.
|
1 | phoenix_connectorCallAppend(connector, tmpCall, vecResult, functionName, vecParam); |
332 | }else{ | ||
333 |
9/9✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
|
2 | logger.getLogInfo() << "Create Mock for host '"<<connector.hostname<<"' and call '"<<functionName<<"' will be loaded from file '"<<mockFileName<<"'" << std::endl; |
334 | //If the call if not known yet we try to find the corresponding mock file | ||
335 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | if(data_load(mockFileName, tmpCall)){ |
336 |
9/9✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
|
2 | logger.getLogInfo() << "Mock file for host '"<<connector.hostname<<"' and call '"<<functionName<<"' found at '"<<mockFileName<<"'" << std::endl; |
337 |
1/1✓ Branch 1 taken 2 times.
|
2 | tmpCall.setIsWriteMode(false); |
338 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | if(tmpCall.getVecEvent().size() != 0lu){ |
339 |
1/1✓ Branch 1 taken 2 times.
|
2 | tmpCall.setCurrentInputMessageIndex(0lu); //Let's increment the index |
340 |
1/1✓ Branch 1 taken 2 times.
|
2 | phoenix_connectorCallRead(connector, tmpCall, vecResult, functionName, vecParam); |
341 | }else{ | ||
342 | ✗ | logger.getLogError() << "Mock file for host '"<<connector.hostname<<"' and call '"<<functionName<<"' no events in file '"<<mockFileName<<"'" << std::endl; | |
343 | ✗ | b = false; | |
344 | } | ||
345 | }else{ | ||
346 | ✗ | logger.getLogError() << "Mock file for host '"<<connector.hostname<<"' and call '"<<functionName<<"' not found at '"<<mockFileName<<"'" << std::endl; | |
347 | ✗ | b =false; | |
348 | } | ||
349 | } | ||
350 | //Let's add the PMockConnectorVar in the map of push | ||
351 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | connector.mapCallMethod[functionName] = tmpCall; |
352 | 3 | } | |
353 | //Let's increment the event id of the connector | ||
354 | 30 | ++connector.eventId; | |
355 | 30 | return b; | |
356 | } | ||
357 | |||
358 | ///Resize a message | ||
359 | /** @param[out] msg : message to be resized | ||
360 | * @param sizeMsg : new size of the message | ||
361 | */ | ||
362 | 60 | void PMockControlBackend::msgResize(PMockControlBackend::Message& msg, size_t sizeMsg){ | |
363 | 60 | msg.resize(sizeMsg); | |
364 | 60 | } | |
365 | |||
366 | |||
367 | ///Get the size of Message in bytes | ||
368 | /** @param msg : given message | ||
369 | * @return size of the given message in bytes | ||
370 | */ | ||
371 | 40 | size_t PMockControlBackend::msgSize(const PMockControlBackend::Message& msg){ | |
372 | 40 | return msg.size(); | |
373 | } | ||
374 | |||
375 | ///Get the data pointer of the given message | ||
376 | /** @param msg : given message | ||
377 | * @return data pointer of the given message | ||
378 | */ | ||
379 | 20 | const char* PMockControlBackend::msgData(const PMockControlBackend::Message& msg){ | |
380 | 20 | return (const char*)msg.data(); | |
381 | } | ||
382 | |||
383 | ///Get the data pointer of the given message | ||
384 | /** @param msg : given message | ||
385 | * @return data pointer of the given message | ||
386 | */ | ||
387 | 132 | char* PMockControlBackend::msgData(PMockControlBackend::Message& msg){ | |
388 | 132 | return (char*)msg.data(); | |
389 | } | ||
390 | |||
391 | ///Close the Connector | ||
392 | /** @param connector : connector to be closed | ||
393 | */ | ||
394 | 27 | void PMockControlBackend::close(PMockControlBackend::Connector & connector){ | |
395 | 27 | PLog & logger = *connector.logger; | |
396 | //Let's save all the mock files in write mode and close the other | ||
397 | // if(connector.isMockRecord){ | ||
398 | // const std::string & mockDirectory = connector.mockDirectory; | ||
399 | // std::string mockStateFileName(phoenix_getControlMockFileVar(mockDirectory, connector.hostname, "", "currentState")); | ||
400 | // if(data_save(mockStateFileName, connector.currentState)){ | ||
401 | // logger.getLogInfo() << "Save mock of current state '"<<mockStateFileName<<"'" << std::endl; | ||
402 | // }else{ | ||
403 | // logger.getLogWarning() << "Cannot save mock of current state '"<<mockStateFileName<<"'" << std::endl; | ||
404 | // } | ||
405 | // } | ||
406 |
2/2✓ Branch 2 taken 27 times.
✓ Branch 5 taken 27 times.
|
27 | phoenix_saveConnectorData(logger, connector.mapPush, "Push"); |
407 |
2/2✓ Branch 2 taken 27 times.
✓ Branch 5 taken 27 times.
|
27 | phoenix_saveConnectorData(logger, connector.mapPull, "Pull"); |
408 |
2/2✓ Branch 2 taken 27 times.
✓ Branch 5 taken 27 times.
|
27 | phoenix_saveConnectorData(logger, connector.mapCallMethod, "CallMethod"); |
409 |
2/2✓ Branch 2 taken 27 times.
✓ Branch 5 taken 27 times.
|
27 | phoenix_saveConnectorData(logger, connector.mapIsConnected, "IsConnected"); |
410 | 27 | logger.getLogInfo() << "Close connection with host '"<<connector.hostname<<"'" << std::endl; | |
411 | 27 | } | |
412 | |||
413 | ///Close the Manager | ||
414 | /** @param manager : manager to be closed | ||
415 | */ | ||
416 | 25 | void PMockControlBackend::closeMgr(PMockControlBackend::Manager & manager){ | |
417 | 25 | PLog & logger = manager.logger; | |
418 |
2/2✓ Branch 2 taken 25 times.
✓ Branch 5 taken 25 times.
|
25 | phoenix_saveConnectorData(logger, manager.mapGetLocalVar, "getLocalVar"); |
419 |
2/2✓ Branch 2 taken 25 times.
✓ Branch 5 taken 25 times.
|
25 | phoenix_saveConnectorData(logger, manager.mapSetLocalVar, "setLocalVar"); |
420 | 25 | logger.getLogInfo() << "Close connection with Manager '"<<manager.name<<"'" << std::endl; | |
421 | 25 | } | |
422 | |||
423 | ///Register a local variable | ||
424 | /** @param[out] manager : Manager to be used | ||
425 | * @param composeVar : description of the local variable | ||
426 | * @return true on success, false otherwise | ||
427 | */ | ||
428 | 3 | bool PMockControlBackend::registerLocalVar(PMockControlBackend::Manager & manager, const PComposeVar & composeVar){ | |
429 | 3 | bool b(true); | |
430 | 3 | PLog & logger = manager.logger; | |
431 | 3 | PComposeVar* var = phoenix_findConnectorData(manager.mapRegisterLocalVar, composeVar.getName()); | |
432 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if(var == NULL){ |
433 | 3 | manager.mapRegisterLocalVar[composeVar.getName()] = composeVar; | |
434 |
5/5✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
✓ Branch 16 taken 3 times.
|
3 | logger.getLogInfo() << "Register Local Var '"<<ts_pcomposeVarToStr(composeVar)<<"' to Manager '"<<manager.name<<"'" << std::endl; |
435 | }else{ | ||
436 | ✗ | logger.getLogError() << "Already registered Local Var '"<<ts_pcomposeVarToStr(composeVar)<<"' to Manager '"<<manager.name<<"'" << std::endl; | |
437 | ✗ | b = false; | |
438 | } | ||
439 | 3 | return b; | |
440 | } | ||
441 | |||
442 | ///Get value of a local variable | ||
443 | /** @param[out] manager : Manager to be used | ||
444 | * @param[out] localVar : variable description to be updated from the message | ||
445 | * @return true on success, false otherwise | ||
446 | */ | ||
447 | 30 | bool PMockControlBackend::getLocalVar(PMockControlBackend::Manager & manager, PComposeVar & localVar){ | |
448 | 30 | PLog & logger = manager.logger; | |
449 | 30 | std::string & varName = localVar.getName(); | |
450 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
|
30 | if(!checkIfLocalVarIsRegister(manager, localVar)){ |
451 | ✗ | logger.getLogError() << "getLocalVar : '"<<varName<<"' of Manager '"<<manager.name<<"' not registered" << std::endl; | |
452 | ✗ | return false; | |
453 | } | ||
454 | 30 | std::vector<char> & value = localVar.getValue(); | |
455 | 30 | PMockConnectorVar* var = phoenix_findConnectorData(manager.mapGetLocalVar, varName); | |
456 | 30 | bool b(true); | |
457 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3 times.
|
30 | if(var != NULL){ //If the variable is already known by the Connector we used the corresponding PMockConnectorVar in mapPush |
458 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 2 taken 18 times.
|
27 | if(var->getIsWriteMode()){ |
459 | //Let's append the value in the data | ||
460 | 9 | phoenix_managerVarAppend(manager, *var, varName, value); | |
461 | }else{ | ||
462 | 18 | phoenix_managerVarRead(manager, *var, varName, value); | |
463 | } | ||
464 | }else{ | ||
465 |
1/1✓ Branch 1 taken 3 times.
|
3 | PMockConnectorVar tmpVar; |
466 |
2/2✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
|
6 | std::string mockFileName(phoenix_getControlMockFileVar(manager.mockDirectory, manager.name, "getLocalVar", varName)); |
467 |
1/1✓ Branch 1 taken 3 times.
|
3 | tmpVar.setFileNameMock(mockFileName); |
468 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if(manager.isMockRecord){ |
469 |
9/9✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 25 taken 1 times.
|
1 | logger.getLogInfo() << "Create Mock for Manager '"<<manager.name<<"' and local variable '"<<varName<<"' getLocalVar will be stored to file '"<<mockFileName<<"'" << std::endl; |
470 |
1/1✓ Branch 1 taken 1 times.
|
1 | tmpVar.setIsWriteMode(true); |
471 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | tmpVar.setType(localVar.getType()); |
472 |
1/1✓ Branch 1 taken 1 times.
|
1 | phoenix_managerVarAppend(manager, tmpVar, varName, value); |
473 | }else{ | ||
474 |
9/9✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
|
2 | logger.getLogInfo() << "Create Mock for Manager '"<<manager.name<<"' and local variable '"<<varName<<"' getLocalVar will be loaded from file '"<<mockFileName<<"'" << std::endl; |
475 | //If the variable if not known yet we try to find the corresponding mock file | ||
476 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | if(data_load(mockFileName, tmpVar)){ |
477 |
9/9✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
|
2 | logger.getLogInfo() << "Mock file for Manager '"<<manager.name<<"' and variable '"<<varName<<"' getLocalVar found at '"<<mockFileName<<"'" << std::endl; |
478 |
1/1✓ Branch 1 taken 2 times.
|
2 | tmpVar.setIsWriteMode(false); |
479 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | if(tmpVar.getVecEvent().size() != 0lu){ |
480 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
|
2 | value = tmpVar.getVecEvent().front().getVecData(); |
481 |
1/1✓ Branch 1 taken 2 times.
|
2 | tmpVar.setCurrentInputMessageIndex(1lu); //Let's increment the index |
482 | }else{ | ||
483 | ✗ | logger.getLogError() << "Mock file for Manager '"<<manager.name<<"' and local variable '"<<varName<<"' getLocalVar no events in file '"<<mockFileName<<"'" << std::endl; | |
484 | ✗ | b = false; | |
485 | } | ||
486 | }else{ | ||
487 | ✗ | logger.getLogError() << "Mock file for Manager '"<<manager.name<<"' and local variable '"<<varName<<"' getLocalVar not found at '"<<mockFileName<<"'" << std::endl; | |
488 | ✗ | b =false; | |
489 | } | ||
490 | } | ||
491 | //Let's add the PMockConnectorVar in the map of push | ||
492 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | manager.mapGetLocalVar[varName] = tmpVar; |
493 | 3 | } | |
494 | //Let's increment the event id of the Manager | ||
495 | 30 | ++manager.eventId; | |
496 | 30 | return b; | |
497 | } | ||
498 | |||
499 | ///Set value of a local variable | ||
500 | /** @param[out] manager : Manager to be used | ||
501 | * @param localVar : variable description to be written into the message | ||
502 | * @return true on success, false otherwise | ||
503 | */ | ||
504 | 30 | bool PMockControlBackend::setLocalVar(PMockControlBackend::Manager & manager, const PComposeVar & localVar){ | |
505 | 30 | PLog & logger = manager.logger; | |
506 | 30 | const std::string & varName = localVar.getName(); | |
507 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
|
30 | if(!checkIfLocalVarIsRegister(manager, localVar)){ |
508 | ✗ | logger.getLogError() << "setLocalVar : '"<<varName<<"' of Manager '"<<manager.name<<"' not registered" << std::endl; | |
509 | ✗ | return false; | |
510 | } | ||
511 | 30 | const std::vector<char> & value = localVar.getValue(); | |
512 | 30 | PMockConnectorVar* var = phoenix_findConnectorData(manager.mapSetLocalVar, varName); | |
513 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3 times.
|
30 | if(var != NULL){ //If the variable is already known by the Connector we used the corresponding PMockConnectorVar in mapPush |
514 |
2/2✓ Branch 1 taken 18 times.
✓ Branch 2 taken 9 times.
|
27 | if(var->getIsWriteMode()){ |
515 | //Let's append the value in the data | ||
516 | 18 | phoenix_managerVarAppend(manager, *var, varName, value); | |
517 | }else{ | ||
518 | //If the corresponding mock file does exist we will check if the value is the same as expected | ||
519 | 9 | phoenix_managerVarCheck(manager, *var, varName, value); | |
520 | } | ||
521 | }else{ //If the var is not known we will create the proper entry | ||
522 |
1/1✓ Branch 1 taken 3 times.
|
3 | PMockConnectorVar tmpVar; |
523 |
2/2✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
|
6 | std::string mockFileName(phoenix_getControlMockFileVar(manager.mockDirectory, manager.name, "setLocalVar", varName)); |
524 |
1/1✓ Branch 1 taken 3 times.
|
3 | tmpVar.setFileNameMock(mockFileName); |
525 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if(manager.isMockRecord){ |
526 |
9/9✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 25 taken 1 times.
|
1 | logger.getLogInfo() << "Create Mock for Manager '"<<manager.name<<"' and local variable '"<<varName<<"' setLocalVar will be saved in file '"<<mockFileName<<"'" << std::endl; |
527 |
1/1✓ Branch 1 taken 1 times.
|
1 | tmpVar.setIsWriteMode(true); |
528 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | tmpVar.setType(localVar.getType()); |
529 |
1/1✓ Branch 1 taken 1 times.
|
1 | phoenix_managerVarAppend(manager, tmpVar, varName, value); |
530 | }else{ | ||
531 | //If the variable if not known yet we try to find the corresponding mock file | ||
532 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
|
2 | if(data_load(mockFileName, tmpVar)){ |
533 |
9/9✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 25 taken 1 times.
|
1 | logger.getLogInfo() << "Mock file for Manager '"<<manager.name<<"' and local variable '"<<varName<<"' setLocalVar found at '"<<mockFileName<<"'" << std::endl; |
534 | //So we are in read mode in this case | ||
535 |
1/1✓ Branch 1 taken 1 times.
|
1 | tmpVar.setIsWriteMode(false); |
536 | //If the corresponding mock file does exist we will check if the value is the same as expected | ||
537 |
1/1✓ Branch 1 taken 1 times.
|
1 | phoenix_managerVarCheck(manager, tmpVar, varName, value); |
538 | }else{ | ||
539 | //If the corresponding mock file does not exist we will record the pushed value to create the mock of this variable at the end of the program | ||
540 |
1/1✓ Branch 1 taken 1 times.
|
1 | phoenix_managerVarAppend(manager, tmpVar, varName, value); |
541 | //We do not forget to say the mock is just beeing written to avoid conflict with the other part of this function | ||
542 |
1/1✓ Branch 1 taken 1 times.
|
1 | tmpVar.setIsWriteMode(true); |
543 | } | ||
544 | } | ||
545 | //Let's add the PMockConnectorVar in the map of push | ||
546 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | manager.mapSetLocalVar[varName] = tmpVar; |
547 | 3 | } | |
548 | //Let's increment the event id of the connector | ||
549 | 30 | ++manager.eventId; | |
550 | 30 | return true; | |
551 | } | ||
552 | |||
553 | ///Create a generic connector | ||
554 | /** @param manager : manager to be used to create the Connector | ||
555 | * @param[out] connector : connector to be created | ||
556 | * @param connectorType : type of the conenctor (client or server) | ||
557 | * @param address : address of the server, the client has to connect to | ||
558 | * @param param : extra customisable parameters for the creation of the connector (depends on the backend) | ||
559 | * @return true if the connector has been created, false otherwise | ||
560 | */ | ||
561 | 27 | bool PMockControlBackend::createConnector(PMockControlBackend::Manager & manager, PMockControlBackend::Connector & connector, const std::string & connectorType, const std::string & address, const Param & param){ | |
562 | 27 | connector.hostname = address; | |
563 | 27 | connector.isMockRecord = param.isMockRecord; | |
564 | // connector.mockDirectory = manager.mockDirectory + "/" + param.mockDirectory; | ||
565 | 27 | connector.mockDirectory = param.mockDirectory; | |
566 | 27 | connector.eventId = manager.eventId; //We start the eventId from where the manager told us to | |
567 | 27 | const std::string & mockDirectory = connector.mockDirectory; | |
568 | 27 | createDirectoriesIfNotExist(mockDirectory); | |
569 | // std::string logDirectory(mockDirectory + "/log/"); | ||
570 | // createDirectoriesIfNotExist(logDirectory); | ||
571 | 27 | connector.logger = &manager.logger; | |
572 | 27 | PLog & logger = *connector.logger; | |
573 | // logger.setFileName(logDirectory + "/"+connectorType+"_"+address+".log"); | ||
574 | // logger.setLogLevel(param.logLevel); | ||
575 | // if(!logger.open()){return false;}; | ||
576 | // logger.getLogInfo() << "Log Directory '"<<logDirectory<<"'" << std::endl; | ||
577 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 24 times.
|
27 | if(connector.isMockRecord){ |
578 |
1/1✓ Branch 1 taken 3 times.
|
3 | std::string mockRecordDirectory(mockDirectory + "/record"); |
579 |
1/1✓ Branch 1 taken 3 times.
|
3 | createDirectoriesIfNotExist(mockRecordDirectory); |
580 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | logger.getLogInfo() << "Mode record activated" << std::endl; |
581 |
5/5✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
|
3 | logger.getLogInfo() << "Record Directory '"<<mockRecordDirectory<<"'" << std::endl; |
582 |
1/1✓ Branch 1 taken 3 times.
|
3 | connector.mockDirectory = mockRecordDirectory; |
583 | 3 | }else{ //If we are not in record mode, we can load input mock | |
584 | //Let's try to open the mock files | ||
585 | //Only those which are not dynamically created by the workflow | ||
586 | //So : current state | ||
587 | |||
588 | } | ||
589 | 27 | return true; | |
590 | } | ||
591 | |||
592 | ///Check if a variable has been registed in the Backend | ||
593 | /** @param[out] connector : connector to be used | ||
594 | * @param varName : name of the variable to be checked | ||
595 | * @return true if the variable was registered, false otherwise | ||
596 | */ | ||
597 | 142 | bool PMockControlBackend::checkIfVarIsRegister(PMockControlBackend::Connector & connector, const std::string & varName){ | |
598 | 142 | return phoenix_isDataExist(connector.mapRegisterVar, varName); | |
599 | } | ||
600 | |||
601 | ///Check if a local variable has been registed in the Backend | ||
602 | /** @param[out] manager : Manager to be used | ||
603 | * @param localVar : local variable to be checked (if its type and name are correct) | ||
604 | * @return true if the local variable was registered, false otherwise | ||
605 | */ | ||
606 | 60 | bool PMockControlBackend::checkIfLocalVarIsRegister(PMockControlBackend::Manager & manager, const PComposeVar & localVar){ | |
607 | 60 | PLog & logger = manager.logger; | |
608 | 60 | bool b(true); | |
609 | // logger.getLogDebug() << "checkIfLocalVarIsRegister localVar = " << ts_pcomposeVarToStr(localVar) << std::endl; | ||
610 | 60 | PComposeVar* var = phoenix_findConnectorData(manager.mapRegisterLocalVar, localVar.getName()); | |
611 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
60 | if(var != NULL){ |
612 |
11/20✓ Branch 1 taken 60 times.
✓ Branch 4 taken 60 times.
✓ Branch 7 taken 60 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 60 times.
✓ Branch 13 taken 60 times.
✓ Branch 17 taken 60 times.
✓ Branch 20 taken 60 times.
✓ Branch 22 taken 60 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 60 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 60 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 60 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
|
60 | if(localVar.getName() == var->getName() && checkValue("checkIfLocalVarIsRegister check var type", localVar.getType(), var->getType())){ |
613 |
2/2✓ Branch 4 taken 60 times.
✓ Branch 7 taken 60 times.
|
60 | logger.getLogDebug() << "checkIfLocalVarIsRegister " << ts_pcomposeVarToStr(localVar) << std::endl; |
614 | }else{ | ||
615 | ✗ | logger.getLogError() << "checkIfLocalVarIsRegister : wrong type, expect '"<<ts_pcomposeVarToStr(*var)<<"' but '"<<ts_pcomposeVarToStr(localVar)<<"' given" << std::endl; | |
616 | ✗ | b = false; | |
617 | } | ||
618 | }else{ | ||
619 | ✗ | logger.getLogError() << "checkIfLocalVarIsRegister : Unknown local variable '"<<ts_pcomposeVarToStr(localVar)<<"'" << std::endl; | |
620 | ✗ | b = false; | |
621 | } | ||
622 | 60 | return b; | |
623 | } | ||
624 | |||
625 | ///Check if a method has been registed in the Backend | ||
626 | /** @param[out] connector : connector to be used | ||
627 | * @param methodName : name of the method to be checked | ||
628 | * @return true if the method was registered, false otherwise | ||
629 | */ | ||
630 | 30 | bool PMockControlBackend::checkIfMethodIsRegister(PMockControlBackend::Connector & connector, const std::string & methodName){ | |
631 | 30 | return phoenix_isDataExist(connector.mapRegisterMethod, methodName); | |
632 | } | ||
633 | |||
634 | |||
635 |