/work/auto_tests/scenarios/scenario_friend_connection_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 | 7 | { |
6 | 7 | tox_node_log(self, "Waiting for DHT connection..."); |
7 | 7 | WAIT_UNTIL(tox_node_is_self_connected(self)); |
8 | 7 | tox_node_log(self, "Connected to DHT. Waiting for friend connection..."); |
9 | | |
10 | 7 | WAIT_UNTIL(tox_node_is_friend_connected(self, 0)); |
11 | 7 | tox_node_log(self, "Connected to Bob!"); |
12 | 7 | } |
13 | | |
14 | | static void bob_script(ToxNode *self, void *ctx) |
15 | 9 | { |
16 | 9 | tox_node_log(self, "Waiting for DHT connection..."); |
17 | 9 | WAIT_UNTIL(tox_node_is_self_connected(self)); |
18 | 9 | tox_node_log(self, "Connected to DHT. Waiting for friend connection..."); |
19 | | |
20 | 9 | WAIT_UNTIL(tox_node_is_friend_connected(self, 0)); |
21 | 9 | tox_node_log(self, "Connected to Alice!"); |
22 | 9 | } |
23 | | |
24 | | int main(int argc, char *argv[]) |
25 | 4 | { |
26 | 4 | ToxScenario *s = tox_scenario_new(argc, argv, 60000); // 60s virtual timeout |
27 | | |
28 | 4 | ToxNode *alice = tox_scenario_add_node(s, "Alice", alice_script, nullptr, 0); |
29 | 4 | ToxNode *bob = tox_scenario_add_node(s, "Bob", bob_script, nullptr, 0); |
30 | | |
31 | 4 | tox_node_bootstrap(bob, alice); |
32 | 4 | tox_node_friend_add(alice, bob); |
33 | 4 | tox_node_friend_add(bob, alice); |
34 | | |
35 | 4 | tox_scenario_log(s, "Starting scenario..."); |
36 | 4 | ToxScenarioStatus res = tox_scenario_run(s); |
37 | | |
38 | 4 | if (res == TOX_SCENARIO_DONE) { |
39 | 4 | tox_scenario_log(s, "Scenario completed successfully!"); |
40 | 4 | } else { |
41 | 0 | tox_scenario_log(s, "Scenario failed with status: %u", res); |
42 | 0 | } |
43 | | |
44 | 4 | tox_scenario_free(s); |
45 | 4 | return (res == TOX_SCENARIO_DONE) ? 0 : 1; |
46 | 4 | } |