Coverage Report

Created: 2026-10-24 08:16

/work/testing/support/public/tox_network.hh
Line
Count
Source (jump to first uncovered line)
1
/* SPDX-License-Identifier: GPL-3.0-or-later
2
 * Copyright © 2026 The TokTok team.
3
 */
4
5
#ifndef C_TOXCORE_TESTING_SUPPORT_TOX_NETWORK_H
6
#define C_TOXCORE_TESTING_SUPPORT_TOX_NETWORK_H
7
8
#include <memory>
9
#include <utility>
10
#include <vector>
11
12
#include "../../../toxcore/attributes.h"
13
#include "simulation.hh"
14
#include "tox_runner.hh"
15
16
namespace tox::test {
17
18
struct ConnectedFriend {
19
    std::unique_ptr<SimulatedNode> node;
20
    std::unique_ptr<ToxRunner> runner;
21
    uint32_t friend_number;
22
23
    ConnectedFriend(std::unique_ptr<SimulatedNode> node_in, std::unique_ptr<ToxRunner> runner_in,
24
        uint32_t friend_number_in)
25
        : node(std::move(node_in))
26
        , runner(std::move(runner_in))
27
        , friend_number(friend_number_in)
28
0
    {
29
0
    }
30
31
0
    ConnectedFriend(ConnectedFriend &&) = default;
32
    ConnectedFriend &operator=(ConnectedFriend &&) = default;
33
    ~ConnectedFriend();
34
};
35
36
/**
37
 * @brief Sets up a network of connected Tox instances.
38
 *
39
 * This function creates num_friends Tox instances, adds them as friends to main_tox,
40
 * and bootstraps them to main_node. It then runs the simulation until all friends
41
 * are connected to main_tox.
42
 *
43
 * @param sim The simulation to run.
44
 * @param main_tox The main Tox instance to which friends will connect.
45
 * @param main_node The simulated node hosting the main Tox instance.
46
 * @param num_friends The number of friends to create and connect.
47
 * @param options Optional Tox_Options to use for the friend Tox instances.
48
 * @return A vector of ConnectedFriend structures, each representing a friend.
49
 */
50
std::vector<ConnectedFriend> setup_connected_friends(Simulation &sim, Tox *_Nonnull main_tox,
51
    SimulatedNode &main_node, int num_friends, const Tox_Options *_Nullable options = nullptr,
52
    bool verbose = false);
53
54
/**
55
 * @brief Connects two existing Tox instances as friends.
56
 *
57
 * This function adds each Tox instance as a friend to the other, bootstraps
58
 * them to each other, and runs the simulation until they are connected.
59
 *
60
 * @param sim The simulation to run.
61
 * @param node1 The simulated node hosting the first Tox instance.
62
 * @param tox1 The first Tox instance.
63
 * @param node2 The simulated node hosting the second Tox instance.
64
 * @param tox2 The second Tox instance.
65
 * @return True if connected successfully, false otherwise.
66
 */
67
bool connect_friends(Simulation &sim, SimulatedNode &node1, Tox *_Nonnull tox1,
68
    SimulatedNode &node2, Tox *_Nonnull tox2);
69
70
/**
71
 * @brief Sets up a group and has all friends join it.
72
 *
73
 * This function creates a new public group on main_tox, invites all friends in the
74
 * provided vector, and runs the simulation until all friends have joined and
75
 * main_tox sees all of them.
76
 *
77
 * @param sim The simulation to run.
78
 * @param main_tox The main Tox instance that creates the group.
79
 * @param friends The friends to invite to the group.
80
 * @return The group number on the main Tox instance, or UINT32_MAX on failure.
81
 */
82
uint32_t setup_connected_group(
83
    Simulation &sim, Tox *_Nonnull main_tox, const std::vector<ConnectedFriend> &friends);
84
85
}  // namespace tox::test
86
87
#endif  // C_TOXCORE_TESTING_SUPPORT_TOX_NETWORK_H