| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <iostream> | ||
| 2 | #include <thread> | ||
| 3 | #include <chrono> | ||
| 4 | #include <signal.h> | ||
| 5 | #include <zmq.hpp> | ||
| 6 | #include <unistd.h> | ||
| 7 | #include "data_stream_assert.h" | ||
| 8 | |||
| 9 | // Test 1: EAGAIN - Socket is not ready but we try to send a message in non-blocking mode | ||
| 10 | 1 | void test_eagain(zmq::context_t& context) { | |
| 11 |
2/2✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
|
1 | std::cout << "\n1. Test EAGAIN (socket not ready):" << std::endl; |
| 12 | 1 | zmq::send_result_t result; | |
| 13 |
1/1✓ Branch 0 (4→5) taken 1 times.
|
1 | zmq::socket_t push_socket(context, ZMQ_PUSH); |
| 14 |
1/1✓ Branch 0 (5→6) taken 1 times.
|
1 | push_socket.set(zmq::sockopt::linger, -1); |
| 15 |
1/1✓ Branch 0 (6→7) taken 1 times.
|
1 | zmq::message_t msg("test", 4); |
| 16 |
1/1✓ Branch 0 (7→8) taken 1 times.
|
1 | result = push_socket.send(msg, zmq::send_flags::dontwait); |
| 17 | |||
| 18 |
4/4✓ Branch 0 (10→11) taken 1 times.
✓ Branch 2 (13→14) taken 1 times.
✓ Branch 4 (16→17) taken 1 times.
✓ Branch 6 (18→19) taken 1 times.
|
6 | data_stream_assert(!result.has_value()); |
| 19 |
5/5✓ Branch 0 (27→28) taken 1 times.
✓ Branch 2 (30→31) taken 1 times.
✓ Branch 4 (33→34) taken 1 times.
✓ Branch 6 (34→35) taken 1 times.
✓ Branch 8 (35→36) taken 1 times.
|
5 | data_stream_assert(zmq_errno() == EAGAIN); |
| 20 |
6/6✓ Branch 0 (42→43) taken 1 times.
✓ Branch 2 (43→44) taken 1 times.
✓ Branch 4 (44→45) taken 1 times.
✓ Branch 6 (45→46) taken 1 times.
✓ Branch 8 (46→47) taken 1 times.
✓ Branch 10 (47→48) taken 1 times.
|
1 | std::cout << " Error code caught is: " << zmq_errno() << " and should be EAGAIN : " << EAGAIN << std::endl; |
| 21 | 1 | } | |
| 22 | |||
| 23 | // Test 2: ENOTSOCK - Socket closed/invalid | ||
| 24 | 1 | void test_enotsock(zmq::context_t& context) { | |
| 25 |
2/2✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
|
1 | std::cout << "\n2. Test ENOTSOCK (socket closed/invalid):" << std::endl; |
| 26 | 1 | zmq::send_result_t result; | |
| 27 | try { | ||
| 28 |
1/1✓ Branch 0 (4→5) taken 1 times.
|
1 | zmq::socket_t push_socket(context, ZMQ_PUSH); |
| 29 | 1 | push_socket.close(); // Close the socket explicitly | |
| 30 |
1/1✓ Branch 0 (6→7) taken 1 times.
|
1 | zmq::message_t msg("test", 4); |
| 31 |
0/1✗ Branch 0 (7→8) not taken.
|
1 | result = push_socket.send(msg, zmq::send_flags::dontwait); |
| 32 |
1/2✗ Branch 0 (34→35) not taken.
✓ Branch 1 (34→36) taken 1 times.
|
3 | } catch (const zmq::error_t& e) { |
| 33 |
8/8✓ Branch 0 (37→38) taken 1 times.
✓ Branch 2 (39→40) taken 1 times.
✓ Branch 4 (40→41) taken 1 times.
✓ Branch 6 (42→43) taken 1 times.
✓ Branch 8 (43→44) taken 1 times.
✓ Branch 10 (44→45) taken 1 times.
✓ Branch 12 (45→46) taken 1 times.
✓ Branch 14 (46→47) taken 1 times.
|
1 | std::cout << " Exception caught: " << e.what() << " (code: " << e.num() << ")" << " should be ENOTSOCK: " << ENOTSOCK << std::endl; |
| 34 |
4/4✓ Branch 0 (49→50) taken 1 times.
✓ Branch 2 (52→53) taken 1 times.
✓ Branch 4 (55→56) taken 1 times.
✓ Branch 6 (57→58) taken 1 times.
|
5 | data_stream_assert(e.num() == ENOTSOCK); |
| 35 | 1 | } | |
| 36 |
4/4✓ Branch 0 (13→14) taken 1 times.
✓ Branch 2 (16→17) taken 1 times.
✓ Branch 4 (19→20) taken 1 times.
✓ Branch 6 (21→22) taken 1 times.
|
5 | data_stream_assert(!result.has_value()); |
| 37 | 1 | } | |
| 38 | |||
| 39 | // Test 3: ENOTSUP - Operation not supported | ||
| 40 | 1 | void test_enotsup(zmq::context_t& context) { | |
| 41 |
2/2✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
|
1 | std::cout << "\n3. Test ENOTSUP (operation not supported):" << std::endl; |
| 42 | // Note: Modern ZMQ sockets generally support send() | ||
| 43 | // We will test a configuration that might not be supported | ||
| 44 | 1 | zmq::send_result_t result; | |
| 45 | try { | ||
| 46 |
1/1✓ Branch 0 (4→5) taken 1 times.
|
1 | zmq::socket_t sub_socket(context, ZMQ_SUB); |
| 47 |
1/1✓ Branch 0 (5→6) taken 1 times.
|
1 | sub_socket.connect("tcp://127.0.0.1:5552"); |
| 48 | |||
| 49 | // Attempt to send on a SUB socket (normally receive-only) | ||
| 50 |
1/1✓ Branch 0 (6→7) taken 1 times.
|
1 | zmq::message_t msg("test", 4); |
| 51 |
0/1✗ Branch 0 (7→8) not taken.
|
1 | result = sub_socket.send(msg, zmq::send_flags::dontwait); |
| 52 | |||
| 53 |
1/2✗ Branch 0 (34→35) not taken.
✓ Branch 1 (34→36) taken 1 times.
|
3 | } catch (const zmq::error_t& e) { |
| 54 |
7/7✓ Branch 0 (37→38) taken 1 times.
✓ Branch 2 (39→40) taken 1 times.
✓ Branch 4 (40→41) taken 1 times.
✓ Branch 6 (42→43) taken 1 times.
✓ Branch 8 (43→44) taken 1 times.
✓ Branch 10 (44→45) taken 1 times.
✓ Branch 12 (45→46) taken 1 times.
|
1 | std::cout << " Exception caught: " << e.what() << " (code: " << e.num() << ") should be ENOTSUP : " << ENOTSUP << std::endl; |
| 55 |
4/4✓ Branch 0 (48→49) taken 1 times.
✓ Branch 2 (51→52) taken 1 times.
✓ Branch 4 (54→55) taken 1 times.
✓ Branch 6 (56→57) taken 1 times.
|
5 | data_stream_assert(e.num() == ENOTSUP); |
| 56 | 1 | } | |
| 57 |
4/4✓ Branch 0 (13→14) taken 1 times.
✓ Branch 2 (16→17) taken 1 times.
✓ Branch 4 (19→20) taken 1 times.
✓ Branch 6 (21→22) taken 1 times.
|
5 | data_stream_assert(!result.has_value()); |
| 58 | 1 | } | |
| 59 | |||
| 60 | 1 | void testSendErrors() { | |
| 61 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | zmq::context_t context(1); |
| 62 | |||
| 63 |
2/2✓ Branch 0 (3→4) taken 1 times.
✓ Branch 2 (4→5) taken 1 times.
|
1 | std::cout << "=== Test error cases when sending ZMQ messages ===" << std::endl; |
| 64 | |||
| 65 |
1/1✓ Branch 0 (5→6) taken 1 times.
|
1 | test_eagain(context); |
| 66 |
1/1✓ Branch 0 (6→7) taken 1 times.
|
1 | test_enotsock(context); |
| 67 |
1/1✓ Branch 0 (7→8) taken 1 times.
|
1 | test_enotsup(context); |
| 68 | |||
| 69 |
2/2✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (9→10) taken 1 times.
|
1 | std::cout << "\n✓ All sender tests passed" << std::endl; |
| 70 | 1 | } | |
| 71 | |||
| 72 | 1 | int main() { | |
| 73 | 1 | testSendErrors(); | |
| 74 | 1 | return 0; | |
| 75 | } | ||
| 76 |