| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | #include <iostream> | ||
| 7 | |||
| 8 | #include "data_stream_assert.h" | ||
| 9 | #include "data_stream_check_value.h" | ||
| 10 | #include "PMockBackend.h" | ||
| 11 | |||
| 12 | ///Test mock backend with no messages loaded for send/recv functions | ||
| 13 | 2 | void testMockBackendNoMessages(){ | |
| 14 |
1/1✓ Branch 0 (2→3) taken 2 times.
|
2 | PMockBackend::Socket socket; |
| 15 |
2/2✓ Branch 0 (5→6) taken 2 times.
✓ Branch 2 (6→7) taken 2 times.
|
2 | socket.setMockPrefix("no_messages_"); |
| 16 |
1/1✓ Branch 0 (9→10) taken 2 times.
|
2 | socket.setIsMockRecord(false); |
| 17 | |||
| 18 | // Test with a socket without loaded messages | ||
| 19 | 2 | PMockBackend::Message msg; | |
| 20 |
1/1✓ Branch 0 (11→12) taken 2 times.
|
2 | msg.push_back(42); |
| 21 | #ifdef SEND | ||
| 22 | // This should fail because no message is loaded | ||
| 23 |
8/10✓ Branch 0 (14→15) taken 1 times.
✓ Branch 2 (17→18) taken 1 times.
✓ Branch 4 (20→21) taken 1 times.
✗ Branch 6 (21→22) not taken.
✗ Branch 8 (22→23) not taken.
✓ Branch 10 (32→33) taken 1 times.
✓ Branch 12 (35→36) taken 1 times.
✓ Branch 14 (38→39) taken 1 times.
✓ Branch 16 (39→40) taken 1 times.
✓ Branch 18 (76→30) taken 1 times.
|
12 | PHOENIX_ASSERT_EXCEPTION(data_stream_assert(socket.sendMsg(msg, PSendFlag::BLOCK) != PSendStatus::OK)); |
| 24 | #endif | ||
| 25 | #ifdef RECV | ||
| 26 |
8/10✓ Branch 0 (14→15) taken 1 times.
✓ Branch 2 (17→18) taken 1 times.
✓ Branch 4 (20→21) taken 1 times.
✗ Branch 6 (21→22) not taken.
✗ Branch 8 (22→23) not taken.
✓ Branch 10 (32→33) taken 1 times.
✓ Branch 12 (35→36) taken 1 times.
✓ Branch 14 (38→39) taken 1 times.
✓ Branch 16 (39→40) taken 1 times.
✓ Branch 18 (76→30) taken 1 times.
|
12 | PHOENIX_ASSERT_EXCEPTION(data_stream_assert(socket.recvMsg(msg, PRecvFlag::BLOCK) != PRecvStatus::OK)); |
| 27 | #endif | ||
| 28 | 2 | } | |
| 29 | |||
| 30 | ///Test mock backend empty message for send function | ||
| 31 | 2 | void testMockBackendEmptyMessage(){ | |
| 32 | // Test lines 140-142: send with empty vecMessage | ||
| 33 |
1/1✓ Branch 0 (2→3) taken 2 times.
|
2 | PMockBackend::Socket emptySocket; |
| 34 |
1/1✓ Branch 0 (3→4) taken 2 times.
|
2 | emptySocket.setIsMockRecord(false); // Read mode |
| 35 | 2 | PMockBackend::Message testMsg; | |
| 36 |
1/1✓ Branch 0 (5→6) taken 2 times.
|
2 | testMsg.push_back(0x01); |
| 37 | #ifdef SEND | ||
| 38 |
8/10✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (11→12) taken 1 times.
✓ Branch 4 (14→15) taken 1 times.
✗ Branch 6 (15→16) not taken.
✗ Branch 8 (16→17) not taken.
✓ Branch 10 (26→27) taken 1 times.
✓ Branch 12 (29→30) taken 1 times.
✓ Branch 14 (32→33) taken 1 times.
✓ Branch 16 (33→34) taken 1 times.
✓ Branch 18 (64→24) taken 1 times.
|
12 | PHOENIX_ASSERT_EXCEPTION(data_stream_assert(emptySocket.sendMsg(testMsg, PSendFlag::BLOCK) != PSendStatus::OK)); |
| 39 | #endif | ||
| 40 | #ifdef RECV | ||
| 41 | 1 | PMockBackend::Message recvMsg; | |
| 42 |
8/10✓ Branch 0 (9→10) taken 1 times.
✓ Branch 2 (12→13) taken 1 times.
✓ Branch 4 (15→16) taken 1 times.
✗ Branch 6 (16→17) not taken.
✗ Branch 8 (17→18) not taken.
✓ Branch 10 (27→28) taken 1 times.
✓ Branch 12 (30→31) taken 1 times.
✓ Branch 14 (33→34) taken 1 times.
✓ Branch 16 (34→35) taken 1 times.
✓ Branch 18 (66→25) taken 1 times.
|
12 | PHOENIX_ASSERT_EXCEPTION(data_stream_assert(emptySocket.recvMsg(recvMsg, PRecvFlag::BLOCK) != PRecvStatus::OK)); |
| 43 | #endif | ||
| 44 | 2 | } | |
| 45 | |||
| 46 | ///Test mock backend empty message for recv function | ||
| 47 | 1 | void testMockBackendEmptyMessageRecv(){ | |
| 48 | // Test lines 145-146: recv with empty vecMessage | ||
| 49 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | PMockBackend::Socket emptySocket; |
| 50 |
1/1✓ Branch 0 (3→4) taken 1 times.
|
1 | emptySocket.setIsMockRecord(false); // Read mode |
| 51 | 1 | PMockBackend::Message recvMsg; | |
| 52 |
8/10✓ Branch 0 (7→8) taken 1 times.
✓ Branch 2 (10→11) taken 1 times.
✓ Branch 4 (13→14) taken 1 times.
✗ Branch 6 (14→15) not taken.
✗ Branch 8 (15→16) not taken.
✓ Branch 10 (25→26) taken 1 times.
✓ Branch 12 (28→29) taken 1 times.
✓ Branch 14 (31→32) taken 1 times.
✓ Branch 16 (32→33) taken 1 times.
✓ Branch 18 (62→23) taken 1 times.
|
12 | PHOENIX_ASSERT_EXCEPTION(data_stream_assert(emptySocket.recvMsg(recvMsg, PRecvFlag::BLOCK) != PRecvStatus::OK)); |
| 53 | 1 | } | |
| 54 | |||
| 55 | ///Test sending a mismatched message | ||
| 56 | 1 | void testSendMismatch(){ | |
| 57 | // Send a different message - this should fail | ||
| 58 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | PMockBackend::Socket readSocket; |
| 59 |
1/1✓ Branch 0 (3→4) taken 1 times.
|
1 | readSocket.setIsMockRecord(false); |
| 60 |
2/2✓ Branch 0 (6→7) taken 1 times.
✓ Branch 2 (7→8) taken 1 times.
|
1 | readSocket.setMockPrefix("mismatch_"); |
| 61 | 1 | PMockBackend::Message differentMsg; | |
| 62 |
1/1✓ Branch 0 (11→12) taken 1 times.
|
1 | differentMsg.push_back(3lu); |
| 63 |
1/1✓ Branch 0 (12→13) taken 1 times.
|
1 | differentMsg.push_back(4lu); |
| 64 |
8/10✓ Branch 0 (15→16) taken 1 times.
✓ Branch 2 (18→19) taken 1 times.
✓ Branch 4 (21→22) taken 1 times.
✗ Branch 6 (22→23) not taken.
✗ Branch 8 (23→24) not taken.
✓ Branch 10 (33→34) taken 1 times.
✓ Branch 12 (36→37) taken 1 times.
✓ Branch 14 (39→40) taken 1 times.
✓ Branch 16 (40→41) taken 1 times.
✓ Branch 18 (78→31) taken 1 times.
|
12 | PHOENIX_ASSERT_EXCEPTION(data_stream_assert(readSocket.sendMsg(differentMsg, PSendFlag::BLOCK) != PSendStatus::OK)); |
| 65 | 1 | } | |
| 66 | |||
| 67 | 6 | int main(int argc, char **argv){ | |
| 68 | #ifdef NO_MESSAGE | ||
| 69 | 2 | testMockBackendNoMessages(); | |
| 70 | #endif | ||
| 71 | #ifdef EMPTY_MESSAGE | ||
| 72 | 2 | testMockBackendEmptyMessage(); | |
| 73 | #endif | ||
| 74 | #ifdef TEST_EMPTY_MESSAGE_RECV | ||
| 75 | 1 | testMockBackendEmptyMessageRecv(); | |
| 76 | #endif | ||
| 77 | #ifdef TEST_SEND_MISMATCH | ||
| 78 | 1 | testSendMismatch(); | |
| 79 | #endif | ||
| 80 | 6 | return 0; | |
| 81 | } | ||
| 82 | |||
| 83 |