/work/auto_tests/scenarios/scenario_netprof_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 | | #include <inttypes.h> |
6 | | #include "../../toxcore/tox_private.h" |
7 | | |
8 | | static void alice_script(ToxNode *self, void *ctx) |
9 | 1 | { |
10 | 1 | tox_node_wait_for_self_connected(self); |
11 | 1 | tox_node_wait_for_friend_connected(self, 0); |
12 | | |
13 | 257 | for (int i = 0; i < 256; i++) { |
14 | 256 | tox_friend_send_message(tox_node_get_tox(self), 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"test", 4, nullptr); |
15 | 256 | tox_scenario_yield(self); |
16 | 256 | } |
17 | | |
18 | | // Wait for Bob to also send his messages and for them to arrive. |
19 | 101 | for (int i = 0; i < 100; i++) { |
20 | 100 | tox_scenario_yield(self); |
21 | 100 | } |
22 | | |
23 | 1 | const Tox *tox = tox_node_get_tox(self); |
24 | 1 | uint64_t udp_sent = tox_netprof_get_packet_total_count(tox, TOX_NETPROF_PACKET_TYPE_UDP, TOX_NETPROF_DIRECTION_SENT); |
25 | 1 | uint64_t udp_recv = tox_netprof_get_packet_total_count(tox, TOX_NETPROF_PACKET_TYPE_UDP, TOX_NETPROF_DIRECTION_RECV); |
26 | | |
27 | 1 | tox_node_log(self, "UDP Sent: %" PRIu64 ", Received: %" PRIu64, udp_sent, udp_recv); |
28 | | |
29 | 1 | ck_assert(udp_sent >= 256); |
30 | 1 | ck_assert(udp_recv >= 1); |
31 | 1 | } |
32 | | |
33 | | static void bob_script(ToxNode *self, void *ctx) |
34 | 1 | { |
35 | 1 | tox_node_wait_for_self_connected(self); |
36 | 1 | tox_node_wait_for_friend_connected(self, 0); |
37 | | |
38 | 257 | for (int i = 0; i < 256; i++) { |
39 | 256 | tox_friend_send_message(tox_node_get_tox(self), 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"test", 4, nullptr); |
40 | 256 | tox_scenario_yield(self); |
41 | 256 | } |
42 | 1 | } |
43 | | |
44 | | int main(int argc, char *argv[]) |
45 | 31 | { |
46 | 31 | ToxScenario *s = tox_scenario_new(argc, argv, 60000); |
47 | 31 | ToxNode *alice = tox_scenario_add_node(s, "Alice", alice_script, nullptr, 0); |
48 | 31 | ToxNode *bob = tox_scenario_add_node(s, "Bob", bob_script, nullptr, 0); |
49 | | |
50 | 31 | tox_node_bootstrap(alice, bob); |
51 | 31 | tox_node_friend_add(alice, bob); |
52 | 31 | tox_node_friend_add(bob, alice); |
53 | | |
54 | 31 | ToxScenarioStatus res = tox_scenario_run(s); |
55 | 31 | if (res != TOX_SCENARIO_DONE) { |
56 | 0 | return 1; |
57 | 0 | } |
58 | | |
59 | 31 | tox_scenario_free(s); |
60 | 31 | return 0; |
61 | 31 | } |