/work/auto_tests/conference_double_invite_test.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include <stdbool.h> |
2 | | #include <stdint.h> |
3 | | |
4 | | typedef struct State { |
5 | | bool self_online; |
6 | | bool friend_online; |
7 | | |
8 | | bool joined; |
9 | | uint32_t conference; |
10 | | } State; |
11 | | |
12 | | #include "auto_test_support.h" |
13 | | |
14 | | static void handle_conference_invite( |
15 | | Tox *tox, const Tox_Event_Conference_Invite *event, void *user_data) |
16 | 16 | { |
17 | 16 | const AutoTox *autotox = (AutoTox *)user_data; |
18 | 16 | State *state = (State *)autotox->state; |
19 | | |
20 | 16 | const uint32_t friend_number = tox_event_conference_invite_get_friend_number(event); |
21 | 16 | const Tox_Conference_Type type = tox_event_conference_invite_get_type(event); |
22 | 16 | const uint8_t *cookie = tox_event_conference_invite_get_cookie(event); |
23 | 16 | const size_t length = tox_event_conference_invite_get_cookie_length(event); |
24 | | |
25 | 16 | fprintf(stderr, "handle_conference_invite(#%u, %u, %d, uint8_t[%u], _)\n", |
26 | 16 | autotox->index, friend_number, type, (unsigned)length); |
27 | 16 | fprintf(stderr, "tox%u joining conference\n", autotox->index); |
28 | | |
29 | 16 | ck_assert_msg(!state->joined, "invitation callback generated for already joined conference"); |
30 | | |
31 | 16 | if (friend_number != -1) { |
32 | 16 | Tox_Err_Conference_Join err; |
33 | 16 | state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); |
34 | 16 | ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, |
35 | 16 | "attempting to join the conference returned with an error: %d", err); |
36 | 14 | fprintf(stderr, "tox%u joined conference %u\n", autotox->index, state->conference); |
37 | 14 | state->joined = true; |
38 | 14 | } |
39 | 16 | } |
40 | | |
41 | | static void conference_double_invite_test(AutoTox *autotoxes) |
42 | 25 | { |
43 | | // Conference callbacks. |
44 | 25 | tox_events_callback_conference_invite(autotoxes[0].dispatch, handle_conference_invite); |
45 | 25 | tox_events_callback_conference_invite(autotoxes[1].dispatch, handle_conference_invite); |
46 | | |
47 | 25 | State *state[2]; |
48 | 25 | state[0] = (State *)autotoxes[0].state; |
49 | 25 | state[1] = (State *)autotoxes[1].state; |
50 | | |
51 | 25 | { |
52 | | // Create new conference, tox0 is the founder. |
53 | 25 | Tox_Err_Conference_New err; |
54 | 25 | state[0]->conference = tox_conference_new(autotoxes[0].tox, &err); |
55 | 25 | state[0]->joined = true; |
56 | 25 | ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, |
57 | 25 | "attempting to create a new conference returned with an error: %d", err); |
58 | 23 | fprintf(stderr, "Created conference: index=%u\n", state[0]->conference); |
59 | 23 | } |
60 | | |
61 | 0 | { |
62 | | // Invite friend. |
63 | 23 | Tox_Err_Conference_Invite err; |
64 | 23 | tox_conference_invite(autotoxes[0].tox, 0, state[0]->conference, &err); |
65 | 23 | ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, |
66 | 23 | "attempting to invite a friend returned with an error: %d", err); |
67 | 22 | fprintf(stderr, "tox0 invited tox1\n"); |
68 | 22 | } |
69 | | |
70 | 0 | fprintf(stderr, "Waiting for invitation to arrive\n"); |
71 | | |
72 | 52 | do { |
73 | 52 | iterate_all_wait(autotoxes, 2, ITERATION_INTERVAL); |
74 | 52 | } while (!state[0]->joined || !state[1]->joined); |
75 | | |
76 | 22 | fprintf(stderr, "Invitations accepted\n"); |
77 | | |
78 | 22 | fprintf(stderr, "Sending second invitation; should be ignored\n"); |
79 | 22 | tox_conference_invite(autotoxes[0].tox, 0, state[0]->conference, nullptr); |
80 | | |
81 | 22 | iterate_all_wait(autotoxes, 2, ITERATION_INTERVAL); |
82 | 22 | } |
83 | | |
84 | | int main(void) |
85 | 721 | { |
86 | 721 | setvbuf(stdout, nullptr, _IONBF, 0); |
87 | | |
88 | 721 | Run_Auto_Options options = default_run_auto_options(); |
89 | 721 | options.graph = GRAPH_LINEAR; |
90 | | |
91 | 721 | run_auto_test(nullptr, 2, conference_double_invite_test, sizeof(State), &options); |
92 | | |
93 | 721 | return 0; |
94 | 721 | } |