Coverage Report

Created: 2026-10-24 08:16

/work/auto_tests/scenarios/scenario_overflow_sendq_test.c
Line
Count
Source (jump to first uncovered line)
1
#include "framework/framework.h"
2
#include <stdio.h>
3
#include <string.h>
4
5
40.0k
#define NUM_MSGS 40000
6
7
static void alice_script(ToxNode *self, void *ctx)
8
1
{
9
1
    tox_node_wait_for_self_connected(self);
10
1
    tox_node_wait_for_friend_connected(self, 0);
11
12
1
    const uint8_t message[] = {0};
13
1
    bool errored = false;
14
1
    Tox *tox = tox_node_get_tox(self);
15
16
40.0k
    for (uint32_t i = 0; i < NUM_MSGS; i++) {
17
40.0k
        Tox_Err_Friend_Send_Message err;
18
40.0k
        tox_friend_send_message(tox, 0, TOX_MESSAGE_TYPE_NORMAL, message, sizeof(message), &err);
19
20
40.0k
        if (err != TOX_ERR_FRIEND_SEND_MESSAGE_OK) {
21
7.23k
            errored = true;
22
7.23k
        }
23
24
40.0k
        if (errored) {
25
7.23k
            ck_assert(err == TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ);
26
32.7k
        } else {
27
32.7k
            ck_assert(err == TOX_ERR_FRIEND_SEND_MESSAGE_OK);
28
32.7k
        }
29
40.0k
    }
30
31
1
    ck_assert(errored);
32
1
    tox_node_log(self, "Success: Send queue overflowed as expected.");
33
1
}
34
35
static void bob_script(ToxNode *self, void *ctx)
36
6
{
37
6
    tox_node_wait_for_self_connected(self);
38
6
    tox_node_wait_for_friend_connected(self, 0);
39
40
6
    ToxNode *alice = tox_scenario_get_node(tox_node_get_scenario(self), 0);
41
6
    WAIT_UNTIL(tox_node_is_finished(alice));
42
6
}
43
44
int main(int argc, char *argv[])
45
31
{
46
31
    ToxScenario *s = tox_scenario_new(argc, argv, 30000);
47
31
    ToxNode *alice = tox_scenario_add_node(s, "Alice", alice_script, nullptr, 0);
48
31
    ToxNode *bob = tox_scenario_add_node(s, "Bob", bob_script, nullptr, 0);
49
50
31
    tox_node_bootstrap(alice, bob);
51
31
    tox_node_friend_add(alice, bob);
52
31
    tox_node_friend_add(bob, alice);
53
54
31
    ToxScenarioStatus res = tox_scenario_run(s);
55
31
    if (res != TOX_SCENARIO_DONE) {
56
0
        return 1;
57
0
    }
58
59
31
    tox_scenario_free(s);
60
31
    return 0;
61
31
}
62
63
#undef NUM_MSGS