Coverage Report

Created: 2026-10-24 08:16

/work/auto_tests/scenarios/scenario_friend_query_test.c
Line
Count
Source (jump to first uncovered line)
1
#include "framework/framework.h"
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <string.h>
5
6
static void alice_script(ToxNode *self, void *ctx)
7
1
{
8
1
    tox_node_wait_for_self_connected(self);
9
1
    tox_node_wait_for_friend_connected(self, 0);
10
11
1
    Tox *tox = tox_node_get_tox(self);
12
13
    // Test tox_friend_exists
14
1
    ck_assert(tox_friend_exists(tox, 0));
15
1
    ck_assert(!tox_friend_exists(tox, 1));
16
17
    // Test tox_friend_get_public_key
18
1
    uint8_t pk[TOX_PUBLIC_KEY_SIZE];
19
1
    Tox_Err_Friend_Get_Public_Key pk_err;
20
1
    bool pk_success = tox_friend_get_public_key(tox, 0, pk, &pk_err);
21
1
    ck_assert(pk_success);
22
1
    ck_assert(pk_err == TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK);
23
24
    // Test tox_friend_by_public_key
25
1
    Tox_Err_Friend_By_Public_Key by_pk_err;
26
1
    uint32_t friend_num = tox_friend_by_public_key(tox, pk, &by_pk_err);
27
1
    ck_assert(by_pk_err == TOX_ERR_FRIEND_BY_PUBLIC_KEY_OK);
28
1
    ck_assert(friend_num == 0);
29
30
    // Test tox_friend_get_last_online
31
1
    Tox_Err_Friend_Get_Last_Online lo_err;
32
1
    uint64_t last_online = tox_friend_get_last_online(tox, 0, &lo_err);
33
1
    ck_assert(lo_err == TOX_ERR_FRIEND_GET_LAST_ONLINE_OK);
34
    // Since they are currently connected, last_online should be recent (non-zero)
35
1
    ck_assert(last_online > 0);
36
37
1
    tox_node_log(self, "Friend query tests passed!");
38
1
}
39
40
static void bob_script(ToxNode *self, void *ctx)
41
6
{
42
6
    tox_node_wait_for_self_connected(self);
43
6
    tox_node_wait_for_friend_connected(self, 0);
44
45
    // Bob stays connected while Alice runs her tests
46
6
    ToxNode *alice = tox_scenario_get_node(tox_node_get_scenario(self), 0);
47
6
    WAIT_UNTIL(tox_node_is_finished(alice));
48
6
}
49
50
int main(int argc, char *argv[])
51
31
{
52
31
    ToxScenario *s = tox_scenario_new(argc, argv, 60000);
53
54
31
    tox_scenario_add_node(s, "Alice", alice_script, nullptr, 0);
55
31
    tox_scenario_add_node(s, "Bob", bob_script, nullptr, 0);
56
57
31
    ToxNode *alice = tox_scenario_get_node(s, 0);
58
31
    ToxNode *bob = tox_scenario_get_node(s, 1);
59
60
31
    tox_node_bootstrap(alice, bob);
61
31
    tox_node_friend_add(alice, bob);
62
31
    tox_node_friend_add(bob, alice);
63
64
31
    ToxScenarioStatus res = tox_scenario_run(s);
65
31
    if (res != TOX_SCENARIO_DONE) {
66
0
        fprintf(stderr, "Scenario failed with status %u\n", res);
67
0
        return 1;
68
0
    }
69
70
31
    tox_scenario_free(s);
71
31
    return 0;
72
31
}