GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixSocket/src/PGenericSocket_impl.h
Date: 2025-06-03 16:44:11
Exec Total Coverage
Lines: 57 66 86.4%
Branches: 28 40 70.0%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #ifndef __PGENERIC_SOCKET_H_IMPL__
8 #define __PGENERIC_SOCKET_H_IMPL__
9
10 #include "PGenericSocket.h"
11
12 ///Default constructor of PGenericSocket
13 /** @param mode : Mode of the Socket (no mock, mock, mock_record)
14 */
15 template<typename _TBackend, typename _TMockBackend>
16 10 PGenericSocket<_TBackend, _TMockBackend>::PGenericSocket(PSocketMode::PSocketMode mode){
17 10 initialisationPGenericSocket(mode);
18 10 }
19
20 ///Destructor of PGenericSocket
21 template<typename _TBackend, typename _TMockBackend>
22 40 PGenericSocket<_TBackend, _TMockBackend>::~PGenericSocket(){
23 20 close();
24 40 }
25
26 ///Create a client socket
27 /** @param param : extra customisable parameters for the creation of the socket (depends on the backend)
28 * @param mockParam : parameters of mock backend
29 * @return true if the socket has been created, false otherwise
30 */
31 template<typename _TBackend, typename _TMockBackend>
32 5 bool PGenericSocket<_TBackend, _TMockBackend>::createClientSocket(const typename _TBackend::Param & param, const typename _TMockBackend::Param & mockParam){
33 5 bool b(true);
34
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
5 if(p_mode != PSocketMode::NO_MOCK){
35 3 b &= _TMockBackend::createClientSocket(p_mockSocket, mockParam);
36 }
37
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if(p_mode != PSocketMode::MOCK){
38 2 b &= _TBackend::createClientSocket(p_socket, param);
39 }
40 5 return b;
41 }
42
43 ///Create a server socket
44 /** @param param : extra customisable parameters for the creation of the socket (depends on the backend)
45 * @param mockParam : parameters of mock backend
46 * @return true if the socket has been created, false otherwise
47 */
48 template<typename _TBackend, typename _TMockBackend>
49 5 bool PGenericSocket<_TBackend, _TMockBackend>::createServerSocket(const typename _TBackend::Param & param, const typename _TMockBackend::Param & mockParam){
50 5 bool b(true);
51
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
5 if(p_mode != PSocketMode::NO_MOCK){
52 3 b &= _TMockBackend::createServerSocket(p_mockSocket, mockParam);
53 }
54
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if(p_mode != PSocketMode::MOCK){
55 2 b &= _TBackend::createServerSocket(p_socket, param);
56 }
57 5 return b;
58 }
59
60 ///Send message on the given socket
61 /** @param msg : message to be sent
62 * @param flag : flags to be used to send the message (BLOCK, NON_BLOCK, etc)
63 * @return true on success, false otherwise
64 */
65 template<typename _TBackend, typename _TMockBackend>
66 20 bool PGenericSocket<_TBackend, _TMockBackend>::sendMsg(typename _TBackend::Message & msg, PSendFlag::PSendFlag flag){
67 20 bool b(true);
68 //This is normal to call the mock backend on a send, because it will check if the send message is the expected one
69 //by respected to the recorded mock
70
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if(p_mode != PSocketMode::NO_MOCK){
71 10 typename _TMockBackend::Message vecTmp;
72
1/1
✓ Branch 1 taken 10 times.
10 _TBackend::msgToMock(vecTmp, msg);
73
1/1
✓ Branch 1 taken 10 times.
10 b &= _TMockBackend::send(p_mockSocket, vecTmp, flag);
74 10 }
75
76 // If we dont test if b is true, we will always send the message even if the mock backend is not connected
77 // I don't know if it is a good idea to do so
78 // If we do that, we might have somme issues if the user tries to end a message. The mock may give an error that will not be catch
79 // Because the boolean value is not checked. So the real backend could have sent corretly the message and the mock not....
80
81
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
20 if(p_mode != PSocketMode::MOCK && b){
82 10 b &= _TBackend::send(p_socket, msg, flag);
83 }
84 20 return b;
85 }
86
87 ///Recieve message from the given socket
88 /** @param msg : message to be recieved
89 * @param flag : flags to be used to send the message (BLOCK, NON_BLOCK, etc)
90 * @return true on success, false otherwise
91 */
92 template<typename _TBackend, typename _TMockBackend>
93 20 bool PGenericSocket<_TBackend, _TMockBackend>::recvMsg(typename _TBackend::Message & msg, PRecvFlag::PRecvFlag flag){
94 20 bool b(true);
95
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if(p_mode == PSocketMode::NO_MOCK){ //Normal mode
96 10 b &= _TBackend::recv(p_socket, msg, flag);
97
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 }else if(p_mode == PSocketMode::MOCK){ //Mock mode
98 10 typename _TMockBackend::Message msgMock;
99
1/1
✓ Branch 1 taken 10 times.
10 b &= _TMockBackend::recv(p_mockSocket, msgMock, flag);
100
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(b){
101
1/1
✓ Branch 1 taken 10 times.
10 _TBackend::mockToMsg(msg, msgMock);
102 }
103 10 }else{ //Mock record mode
104 b &= _TBackend::recv(p_socket, msg, flag);
105 if(b){
106 typename _TMockBackend::Message msgMock;
107 _TBackend::msgToMock(msgMock, msg);
108 b &= _TMockBackend::recv(p_mockSocket, msgMock, flag);
109 }
110 else {
111 typename _TMockBackend::Message empty_msg;
112 b &= _TMockBackend::recv(p_mockSocket, empty_msg, flag);
113 }
114 }
115 20 return b;
116 }
117
118 ///Close the socket
119 template<typename _TBackend, typename _TMockBackend>
120 10 void PGenericSocket<_TBackend, _TMockBackend>::close(){
121
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
10 if(p_mode == PSocketMode::MOCK){
122 6 _TMockBackend::close(p_mockSocket);
123
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 }else if(p_mode == PSocketMode::NO_MOCK){
124 4 _TBackend::close(p_socket);
125 }else{
126 _TMockBackend::close(p_mockSocket);
127 _TBackend::close(p_socket);
128 }
129 10 }
130
131 ///Say if the Socket is connected
132 /** @return true if the current socket is connected (or both in record mode)
133 */
134 template<typename _TBackend, typename _TMockBackend>
135 4 bool PGenericSocket<_TBackend, _TMockBackend>::isConnected() const{
136 4 bool b(true);
137
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if(p_mode != PSocketMode::NO_MOCK){
138 2 b &= _TMockBackend::isConnected(p_mockSocket);
139 }
140
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if(p_mode != PSocketMode::MOCK){
141 2 b &= _TBackend::isConnected(p_socket);
142 }
143 4 return b;
144 }
145
146 ///Initialisation function of the class PGenericSocket
147 /** @param mode : Mode of the Socket (no mock, mock, mock_record)
148 */
149 template<typename _TBackend, typename _TMockBackend>
150 10 void PGenericSocket<_TBackend, _TMockBackend>::initialisationPGenericSocket(PSocketMode::PSocketMode mode){
151 10 p_mode = mode;
152 10 }
153
154
155 #endif
156
157
158
159