GCC Code Coverage Report


Directory: ./
File: src/PMockConnector.h
Date: 2024-12-09 11:00:39
Exec Total Coverage
Lines: 35 35 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7
8
9 #ifndef __PMOCKCONNECTOR_H__
10 #define __PMOCKCONNECTOR_H__
11
12 #include <string>
13 #include <vector>
14 #include "PComposeType.h"
15
16 #include "data_all.h"
17
18 ///@brief Content of a mock event with variable (push / pull)
19 class PMockEventVar{
20 public:
21 PMockEventVar();
22 PMockEventVar(const PMockEventVar & other);
23 virtual ~PMockEventVar();
24 PMockEventVar & operator = (const PMockEventVar & other);
25 void setEventId(size_t eventId);
26 void setVecData(const std::vector<char> & vecData);
27 size_t getEventId() const;
28 size_t & getEventId();
29 const std::vector<char> & getVecData() const;
30 std::vector<char> & getVecData();
31
32 ///Load the current PMockEventVar with a stream
33 /** @param[out] ds : stream to be used
34 * @return true on success, false otherwise
35 */
36 template<typename Stream, DataStreamMode::DataStreamMode Mode>
37 502 bool readWriteStream(Stream & ds){
38 502 bool b(true);
39 502 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_eventId);
40 502 b &= DataStream<Stream, Mode, std::vector<char> >::data_stream(ds, p_vecData);
41 502 return b;
42 }
43
44 protected:
45 void copyPMockEventVar(const PMockEventVar & other);
46 private:
47 void initialisationPMockEventVar();
48 ///Id of the current event (used for debuging with mock)
49 size_t p_eventId;
50 ///Vector of data of the current event
51 std::vector<char> p_vecData;
52 };
53
54 ///@brief Generic PMockEventVar serialisation/deserialisation, load/save and size function
55 template<typename Stream, DataStreamMode::DataStreamMode Mode>
56 struct DataStream<Stream, Mode, PMockEventVar>{
57 ///Generic function to load/save/serialise/deserialise PMockEventVar
58 /** @param data : PMockEventVar to be used
59 * @return true on success, false otherwise
60 */
61 502 static bool data_stream(Stream & ds, PMockEventVar & data){
62 502 return data.readWriteStream<Stream, Mode>(ds);
63 }
64 };
65
66
67
68 ///@brief Full mock file content related to a method call (push, pul)
69 class PMockConnectorVar{
70 public:
71 PMockConnectorVar();
72 PMockConnectorVar(const PMockConnectorVar & other);
73 virtual ~PMockConnectorVar();
74 PMockConnectorVar & operator = (const PMockConnectorVar & other);
75 void setFileNameMock(const std::string & fileNameMock);
76 void setIsWriteMode(bool isWriteMode);
77 void setCurrentInputMessageIndex(size_t currentInputMessageIndex);
78 void setType(const PComposeType & type);
79 void setVecEvent(const std::vector<PMockEventVar> & vecEvent);
80 const std::string & getFileNameMock() const;
81 std::string & getFileNameMock();
82 bool getIsWriteMode() const;
83 bool & getIsWriteMode();
84 size_t getCurrentInputMessageIndex() const;
85 size_t & getCurrentInputMessageIndex();
86 const PComposeType & getType() const;
87 PComposeType & getType();
88 const std::vector<PMockEventVar> & getVecEvent() const;
89 std::vector<PMockEventVar> & getVecEvent();
90
91 ///Load the current PMockConnectorVar with a stream
92 /** @param[out] ds : stream to be used
93 * @return true on success, false otherwise
94 */
95 template<typename Stream, DataStreamMode::DataStreamMode Mode>
96 52 bool readWriteStream(Stream & ds){
97 52 bool b(true);
98 52 b &= DataStream<Stream, Mode, std::string >::data_stream(ds, p_fileNameMock);
99 52 b &= DataStream<Stream, Mode, bool >::data_stream(ds, p_isWriteMode);
100 52 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_currentInputMessageIndex);
101 52 b &= DataStream<Stream, Mode, PComposeType >::data_stream(ds, p_type);
102 52 b &= DataStream<Stream, Mode, std::vector<PMockEventVar> >::data_stream(ds, p_vecEvent);
103 52 return b;
104 }
105
106 protected:
107 void copyPMockConnectorVar(const PMockConnectorVar & other);
108 private:
109 void initialisationPMockConnectorVar();
110 ///Name of the mock file (specific for push, pull)
111 std::string p_fileNameMock;
112 ///True if the mock is just written
113 bool p_isWriteMode;
114 ///Index of the current input message
115 size_t p_currentInputMessageIndex;
116 ///Type of the used variable
117 PComposeType p_type;
118 ///Vector of all mock events
119 std::vector<PMockEventVar> p_vecEvent;
120 };
121
122 ///@brief Generic PMockConnectorVar serialisation/deserialisation, load/save and size function
123 template<typename Stream, DataStreamMode::DataStreamMode Mode>
124 struct DataStream<Stream, Mode, PMockConnectorVar>{
125 ///Generic function to load/save/serialise/deserialise PMockConnectorVar
126 /** @param data : PMockConnectorVar to be used
127 * @return true on success, false otherwise
128 */
129 52 static bool data_stream(Stream & ds, PMockConnectorVar & data){
130 52 return data.readWriteStream<Stream, Mode>(ds);
131 }
132 };
133
134
135
136 ///@brief Content of a mock event with method call (call)
137 class PMockEventCall{
138 public:
139 PMockEventCall();
140 PMockEventCall(const PMockEventCall & other);
141 virtual ~PMockEventCall();
142 PMockEventCall & operator = (const PMockEventCall & other);
143 void setEventId(size_t eventId);
144 void setVecParam(const std::vector<std::vector<char> > & vecParam);
145 void setVecResult(const std::vector<std::vector<char> > & vecResult);
146 size_t getEventId() const;
147 size_t & getEventId();
148 const std::vector<std::vector<char> > & getVecParam() const;
149 std::vector<std::vector<char> > & getVecParam();
150 const std::vector<std::vector<char> > & getVecResult() const;
151 std::vector<std::vector<char> > & getVecResult();
152
153 ///Load the current PMockEventCall with a stream
154 /** @param[out] ds : stream to be used
155 * @return true on success, false otherwise
156 */
157 template<typename Stream, DataStreamMode::DataStreamMode Mode>
158 100 bool readWriteStream(Stream & ds){
159 100 bool b(true);
160 100 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_eventId);
161 100 b &= DataStream<Stream, Mode, std::vector<std::vector<char> > >::data_stream(ds, p_vecParam);
162 100 b &= DataStream<Stream, Mode, std::vector<std::vector<char> > >::data_stream(ds, p_vecResult);
163 100 return b;
164 }
165
166 protected:
167 void copyPMockEventCall(const PMockEventCall & other);
168 private:
169 void initialisationPMockEventCall();
170 ///Id of the current event (used for debuging with mock)
171 size_t p_eventId;
172 ///Vector of Message which are used as parameters for a function call of the current event
173 std::vector<std::vector<char> > p_vecParam;
174 ///Vector of Message which are used as result of a function call of the current event
175 std::vector<std::vector<char> > p_vecResult;
176 };
177
178 ///@brief Generic PMockEventCall serialisation/deserialisation, load/save and size function
179 template<typename Stream, DataStreamMode::DataStreamMode Mode>
180 struct DataStream<Stream, Mode, PMockEventCall>{
181 ///Generic function to load/save/serialise/deserialise PMockEventCall
182 /** @param data : PMockEventCall to be used
183 * @return true on success, false otherwise
184 */
185 100 static bool data_stream(Stream & ds, PMockEventCall & data){
186 100 return data.readWriteStream<Stream, Mode>(ds);
187 }
188 };
189
190
191
192 ///@brief Full mock file content related to a method call
193 class PMockConnectorCall{
194 public:
195 PMockConnectorCall();
196 PMockConnectorCall(const PMockConnectorCall & other);
197 virtual ~PMockConnectorCall();
198 PMockConnectorCall & operator = (const PMockConnectorCall & other);
199 void setFileNameMock(const std::string & fileNameMock);
200 void setIsWriteMode(bool isWriteMode);
201 void setCurrentInputMessageIndex(size_t currentInputMessageIndex);
202 void setPrototype(const PFunctionPrototype & prototype);
203 void setVecEvent(const std::vector<PMockEventCall> & vecEvent);
204 const std::string & getFileNameMock() const;
205 std::string & getFileNameMock();
206 bool getIsWriteMode() const;
207 bool & getIsWriteMode();
208 size_t getCurrentInputMessageIndex() const;
209 size_t & getCurrentInputMessageIndex();
210 const PFunctionPrototype & getPrototype() const;
211 PFunctionPrototype & getPrototype();
212 const std::vector<PMockEventCall> & getVecEvent() const;
213 std::vector<PMockEventCall> & getVecEvent();
214
215 ///Load the current PMockConnectorCall with a stream
216 /** @param[out] ds : stream to be used
217 * @return true on success, false otherwise
218 */
219 template<typename Stream, DataStreamMode::DataStreamMode Mode>
220 10 bool readWriteStream(Stream & ds){
221 10 bool b(true);
222 10 b &= DataStream<Stream, Mode, std::string >::data_stream(ds, p_fileNameMock);
223 10 b &= DataStream<Stream, Mode, bool >::data_stream(ds, p_isWriteMode);
224 10 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_currentInputMessageIndex);
225 10 b &= DataStream<Stream, Mode, PFunctionPrototype >::data_stream(ds, p_prototype);
226 10 b &= DataStream<Stream, Mode, std::vector<PMockEventCall> >::data_stream(ds, p_vecEvent);
227 10 return b;
228 }
229
230 protected:
231 void copyPMockConnectorCall(const PMockConnectorCall & other);
232 private:
233 void initialisationPMockConnectorCall();
234 ///Name of the mock file (specific for push, pull, call, etc)
235 std::string p_fileNameMock;
236 ///True if the mock is just written
237 bool p_isWriteMode;
238 ///Index of the current input message
239 size_t p_currentInputMessageIndex;
240 ///Prototype of the function to be used by the PMockConnectorCall
241 PFunctionPrototype p_prototype;
242 ///Vector of all mock events
243 std::vector<PMockEventCall> p_vecEvent;
244 };
245
246 ///@brief Generic PMockConnectorCall serialisation/deserialisation, load/save and size function
247 template<typename Stream, DataStreamMode::DataStreamMode Mode>
248 struct DataStream<Stream, Mode, PMockConnectorCall>{
249 ///Generic function to load/save/serialise/deserialise PMockConnectorCall
250 /** @param data : PMockConnectorCall to be used
251 * @return true on success, false otherwise
252 */
253 5 static bool data_stream(Stream & ds, PMockConnectorCall & data){
254 5 return data.readWriteStream<Stream, Mode>(ds);
255 }
256 };
257
258
259
260
261
262 #endif
263
264