| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #ifndef __PMOCKBACKEND_IMPL_H__ | ||
| 8 | #define __PMOCKBACKEND_IMPL_H__ | ||
| 9 | |||
| 10 | #include "PMockBackend.h" | ||
| 11 | |||
| 12 | ///Serialize a message from data | ||
| 13 | /** @param[out] msg : message to be filled with the data | ||
| 14 | * @param data : data to be serialized in the message | ||
| 15 | * @return status of the serialization | ||
| 16 | */ | ||
| 17 | template<typename T> | ||
| 18 | 10 | bool socket_serialize_message(PMockSocket::Message & msg, const T & data){ | |
| 19 |
1/1✓ Branch 0 (2→3) taken 10 times.
|
10 | size_t dataSize(data_size<T>(data)); |
| 20 |
1/1✓ Branch 0 (3→4) taken 10 times.
|
10 | msg.resize(dataSize); |
| 21 | 10 | DataStreamIter iter = (DataStreamIter)msg.data(); | |
| 22 |
1/1✓ Branch 0 (5→6) taken 10 times.
|
20 | return data_message_save<T>(iter, data); |
| 23 | } | ||
| 24 | |||
| 25 | |||
| 26 | ///Send data with the socket | ||
| 27 | /** @param data : data to be sent with the socket | ||
| 28 | * @param flag : sending flag (BLOCK, NON_BLOCK) | ||
| 29 | * @return status of the send | ||
| 30 | */ | ||
| 31 | template<typename T> | ||
| 32 | 10 | PSendStatus::PSendStatus PMockSocket::sendData(const T & data, PSendFlag::PSendFlag flag){ | |
| 33 |
1/2✓ Branch 0 (3→4) taken 10 times.
✗ Branch 1 (3→12) not taken.
|
10 | if(p_mock.getIsRecord()){ |
| 34 | 10 | PMockSocket::Message msg; | |
| 35 |
2/3✓ Branch 0 (5→6) taken 10 times.
✓ Branch 2 (6→7) taken 10 times.
✗ Branch 3 (6→9) not taken.
|
10 | if(socket_serialize_message(msg, data)){ |
| 36 |
1/1✓ Branch 0 (7→8) taken 10 times.
|
10 | return sendMsg(msg, flag); |
| 37 | }else{ | ||
| 38 | ✗ | return PSendStatus::CANNOT_SERIALIZE_DATA; | |
| 39 | } | ||
| 40 | 10 | }else{ | |
| 41 | T referenceData; | ||
| 42 | ✗ | PMockSocket::Message referenceMsg; | |
| 43 | ✗ | p_mock.getCurrentValue(referenceMsg); //Let's get the reference message | |
| 44 | ✗ | if(referenceMsg.size() != 0lu){ | |
| 45 | ✗ | DataStreamIter iter = (DataStreamIter)referenceMsg.data(); | |
| 46 | ✗ | check_stream_assert(data_message_load<T>(iter, referenceData)); | |
| 47 | ✗ | std::stringstream index; | |
| 48 | ✗ | index << p_mock.getCurrentIndex(); | |
| 49 | ✗ | check_stream_assert(phoenix_check_stream("mock '"+p_mock.getFileName()+"', [mock index = "+index.str()+"]", data, referenceData)); | |
| 50 | ✗ | } | |
| 51 | ✗ | return PSendStatus::OK; | |
| 52 | ✗ | } | |
| 53 | } | ||
| 54 | |||
| 55 | ///Recieved data with the socket | ||
| 56 | /** @param[out] data : data to be recieved with the socket | ||
| 57 | * @param flag : recieving flag (BLOCK, NON_BLOCK) | ||
| 58 | * @return status of the recv | ||
| 59 | */ | ||
| 60 | template<typename T> | ||
| 61 | 10 | PRecvStatus::PRecvStatus PMockSocket::recvData(T & data, PRecvFlag::PRecvFlag flag){ | |
| 62 | 10 | PRecvStatus::PRecvStatus recvStatus = PRecvStatus::OK; | |
| 63 | 10 | PMockSocket::Message msg; | |
| 64 |
1/2✗ Branch 0 (4→5) not taken.
✓ Branch 1 (4→10) taken 10 times.
|
10 | if(p_mock.getIsRecord()){ |
| 65 | ✗ | if(socket_serialize_message(msg, data)){ | |
| 66 | ✗ | return recvMsg(msg, flag); | |
| 67 | }else{ | ||
| 68 | ✗ | return PRecvStatus::CANNOT_DESERIALIZE_DATA; | |
| 69 | } | ||
| 70 | } | ||
| 71 | else{ | ||
| 72 |
1/1✓ Branch 0 (10→11) taken 10 times.
|
10 | recvStatus = recvMsg(msg, flag); |
| 73 | //If the message is empty we cannot initialise the given data, so, this is an error | ||
| 74 |
1/2✓ Branch 0 (12→13) taken 10 times.
✗ Branch 1 (12→18) not taken.
|
10 | if(msg.size() != 0lu){ |
| 75 | 10 | DataStreamIter iter = (DataStreamIter)msg.data(); | |
| 76 |
2/3✓ Branch 0 (14→15) taken 10 times.
✗ Branch 2 (15→16) not taken.
✓ Branch 3 (15→17) taken 10 times.
|
10 | if(!data_message_load<T>(iter, data)){ |
| 77 | ✗ | recvStatus = PRecvStatus::CANNOT_DESERIALIZE_DATA; | |
| 78 | } | ||
| 79 | }else{ | ||
| 80 | ✗ | recvStatus = PRecvStatus::NO_MESSAGE_RECEIVED; | |
| 81 | } | ||
| 82 | } | ||
| 83 | 10 | return recvStatus; | |
| 84 | 10 | } | |
| 85 | |||
| 86 | #endif | ||
| 87 | |||
| 88 |