Coverage Report

Created: 2026-10-24 08:16

/work/auto_tests/scenarios/scenario_message_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
static void alice_script(ToxNode *self, void *ctx)
6
1
{
7
1
    Tox *tox = tox_node_get_tox(self);
8
1
    tox_node_log(self, "Waiting for DHT connection...");
9
1
    WAIT_UNTIL(tox_node_is_self_connected(self));
10
1
    tox_node_log(self, "Connected to DHT. Waiting for friend connection...");
11
1
    WAIT_UNTIL(tox_node_is_friend_connected(self, 0));
12
13
1
    tox_node_log(self, "Sending message to Bob...");
14
1
    uint8_t msg[] = "Hello Bob!";
15
1
    Tox_Err_Friend_Send_Message err;
16
1
    tox_friend_send_message(tox, 0, TOX_MESSAGE_TYPE_NORMAL, msg, sizeof(msg), &err);
17
1
    if (err != TOX_ERR_FRIEND_SEND_MESSAGE_OK) {
18
0
        return;
19
0
    }
20
21
1
    tox_node_log(self, "Waiting for response from Bob...");
22
1
    WAIT_FOR_EVENT(TOX_EVENT_FRIEND_MESSAGE);
23
1
    tox_node_log(self, "Received response from Bob!");
24
1
}
25
26
static void bob_script(ToxNode *self, void *ctx)
27
9
{
28
9
    Tox *tox = tox_node_get_tox(self);
29
9
    tox_node_log(self, "Waiting for DHT connection...");
30
9
    WAIT_UNTIL(tox_node_is_self_connected(self));
31
9
    tox_node_log(self, "Connected to DHT. Waiting for friend connection...");
32
9
    WAIT_UNTIL(tox_node_is_friend_connected(self, 0));
33
34
9
    tox_node_log(self, "Waiting for message from Alice...");
35
9
    WAIT_FOR_EVENT(TOX_EVENT_FRIEND_MESSAGE);
36
9
    tox_node_log(self, "Received message from Alice! Sending response...");
37
38
9
    uint8_t msg[] = "Hello Alice!";
39
9
    Tox_Err_Friend_Send_Message err;
40
9
    tox_friend_send_message(tox, 0, TOX_MESSAGE_TYPE_NORMAL, msg, sizeof(msg), &err);
41
9
}
42
43
int main(int argc, char *argv[])
44
4
{
45
4
    ToxScenario *s = tox_scenario_new(argc, argv, 60000); // 60s virtual timeout
46
47
4
    ToxNode *alice = tox_scenario_add_node(s, "Alice", alice_script, nullptr, 0);
48
4
    ToxNode *bob = tox_scenario_add_node(s, "Bob", bob_script, nullptr, 0);
49
50
4
    tox_node_bootstrap(bob, alice);
51
4
    tox_node_friend_add(alice, bob);
52
4
    tox_node_friend_add(bob, alice);
53
54
4
    tox_scenario_log(s, "Starting scenario...");
55
4
    ToxScenarioStatus res = tox_scenario_run(s);
56
57
4
    if (res == TOX_SCENARIO_DONE) {
58
4
        tox_scenario_log(s, "Scenario completed successfully!");
59
4
    } else {
60
0
        tox_scenario_log(s, "Scenario failed with status: %u", res);
61
0
    }
62
63
4
    tox_scenario_free(s);
64
4
    return (res == TOX_SCENARIO_DONE) ? 0 : 1;
65
4
}