|
| 1 | +#include <check.h> |
| 2 | +#include <check_extras.h> |
| 3 | + |
| 4 | +#include <curvecpr/messager.h> |
| 5 | + |
| 6 | +long long test_timeout = -1LL; |
| 7 | + |
| 8 | +static struct curvecpr_block static_block = { |
| 9 | + .id = 0, |
| 10 | + .clock = 0, |
| 11 | + .eof = CURVECPR_BLOCK_STREAM, |
| 12 | + .data_len = 7, |
| 13 | + .data = "Hello!" |
| 14 | +}; |
| 15 | + |
| 16 | +static unsigned char t_q_is_full (struct curvecpr_messager *messager) |
| 17 | +{ |
| 18 | + return 0; |
| 19 | +} |
| 20 | + |
| 21 | +static unsigned char t_q_is_empty (struct curvecpr_messager *messager) |
| 22 | +{ |
| 23 | + return 1; |
| 24 | +} |
| 25 | + |
| 26 | +static int t_recvmarkq_get_nth_unacknowledged (struct curvecpr_messager *messager, unsigned int n, struct curvecpr_block **block_stored) |
| 27 | +{ |
| 28 | + return 1; |
| 29 | +} |
| 30 | + |
| 31 | +static int t_sendmarkq_head (struct curvecpr_messager *messager, struct curvecpr_block **block_stored) |
| 32 | +{ |
| 33 | + return 1; |
| 34 | +} |
| 35 | + |
| 36 | +static int t_sendq_head (struct curvecpr_messager *messager, struct curvecpr_block **block_stored) |
| 37 | +{ |
| 38 | + *block_stored = &static_block; |
| 39 | + return 0; |
| 40 | +} |
| 41 | + |
| 42 | +static int t_send (struct curvecpr_messager *messager, const unsigned char *buf, size_t num) |
| 43 | +{ |
| 44 | + return 0; |
| 45 | +} |
| 46 | + |
| 47 | +static int t_sendq_move_to_sendmarkq (struct curvecpr_messager *messager, const struct curvecpr_block *block, struct curvecpr_block **block_stored) |
| 48 | +{ |
| 49 | + return 0; |
| 50 | +} |
| 51 | + |
| 52 | +static void t_put_next_timeout (struct curvecpr_messager *messager, long long timeout) |
| 53 | +{ |
| 54 | + test_timeout = timeout; |
| 55 | +} |
| 56 | + |
| 57 | +START_TEST (test_timeout_callback_fires) |
| 58 | +{ |
| 59 | + struct curvecpr_messager messager; |
| 60 | + struct curvecpr_messager_cf cf = { |
| 61 | + .ops = { |
| 62 | + .sendq_is_empty = t_q_is_empty, |
| 63 | + .sendmarkq_is_full = t_q_is_full, |
| 64 | + .recvmarkq_is_empty = t_q_is_empty, |
| 65 | + .recvmarkq_get_nth_unacknowledged = t_recvmarkq_get_nth_unacknowledged, |
| 66 | + .sendmarkq_head = t_sendmarkq_head, |
| 67 | + .sendq_head = t_sendq_head, |
| 68 | + .send = t_send, |
| 69 | + .sendq_move_to_sendmarkq = t_sendq_move_to_sendmarkq, |
| 70 | + .put_next_timeout = t_put_next_timeout |
| 71 | + } |
| 72 | + }; |
| 73 | + |
| 74 | + curvecpr_messager_new(&messager, &cf, 1); |
| 75 | + |
| 76 | + fail_unless(test_timeout >= 0); |
| 77 | + test_timeout = -1LL; |
| 78 | + |
| 79 | + curvecpr_messager_process_sendq(&messager); |
| 80 | + |
| 81 | + fail_unless(test_timeout >= 0); |
| 82 | +} |
| 83 | +END_TEST |
| 84 | + |
| 85 | +RUN_TEST (test_timeout_callback_fires) |
0 commit comments