Coverage Report

Created: 2026-10-24 08:16

/work/auto_tests/scenarios/scenario_lan_discovery_test.c
Line
Count
Source (jump to first uncovered line)
1
#include "framework/framework.h"
2
#include <stdio.h>
3
4
static void alice_script(ToxNode *self, void *ctx)
5
1
{
6
1
    tox_node_log(self, "Waiting for LAN discovery...");
7
1
    WAIT_UNTIL(tox_node_is_self_connected(self));
8
1
    if (tox_node_is_self_connected(self)) {
9
1
        tox_node_log(self, "Discovered network via LAN!");
10
1
    } else {
11
0
        tox_node_log(self, "Failed to discover network via LAN.");
12
0
    }
13
1
}
14
15
static void bob_script(ToxNode *self, void *ctx)
16
1
{
17
1
    tox_node_log(self, "Waiting for LAN discovery...");
18
1
    WAIT_UNTIL(tox_node_is_self_connected(self));
19
1
    if (tox_node_is_self_connected(self)) {
20
1
        tox_node_log(self, "Discovered network via LAN!");
21
1
    } else {
22
0
        tox_node_log(self, "Failed to discover network via LAN.");
23
0
    }
24
1
}
25
26
int main(int argc, char *argv[])
27
4
{
28
4
    ToxScenario *s = tox_scenario_new(argc, argv, 60000);
29
30
4
    Tox_Options *opts = tox_options_new(nullptr);
31
4
    tox_options_set_ipv6_enabled(opts, false);
32
4
    tox_options_set_local_discovery_enabled(opts, true);
33
34
    // Both nodes have local discovery enabled and NO bootstrap
35
4
    tox_scenario_add_node_ex(s, "Alice", alice_script, nullptr, 0, opts);
36
4
    tox_scenario_add_node_ex(s, "Bob", bob_script, nullptr, 0, opts);
37
38
4
    tox_options_free(opts);
39
40
4
    tox_scenario_log(s, "Starting scenario (LAN Discovery).");
41
4
    ToxScenarioStatus res = tox_scenario_run(s);
42
43
4
    if (res == TOX_SCENARIO_DONE) {
44
4
        tox_scenario_log(s, "Scenario completed successfully!");
45
4
    } else {
46
0
        tox_scenario_log(s, "Scenario failed with status: %u", res);
47
0
    }
48
49
4
    tox_scenario_free(s);
50
4
    return (res == TOX_SCENARIO_DONE) ? 0 : 1;
51
4
}