/work/auto_tests/lan_discovery_test.c
Line | Count | Source |
1 | | #include <stdio.h> |
2 | | #include <string.h> |
3 | | |
4 | | #include "../testing/misc_tools.h" |
5 | | #include "../toxcore/ccompat.h" |
6 | | #include "../toxcore/tox_struct.h" |
7 | | #include "auto_test_support.h" |
8 | | |
9 | | static uint64_t get_state_clock_callback(void *user_data) |
10 | 442k | { |
11 | 442k | const uint64_t *clock = (const uint64_t *)user_data; |
12 | 442k | return *clock; |
13 | 442k | } |
14 | | |
15 | | int main(void) |
16 | 38 | { |
17 | 38 | setvbuf(stdout, nullptr, _IONBF, 0); |
18 | | |
19 | 38 | Tox *tox1 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true); |
20 | 38 | Tox *tox2 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true); |
21 | 38 | ck_assert(tox1 != nullptr); |
22 | 17 | ck_assert(tox2 != nullptr); |
23 | | |
24 | 9 | uint64_t clock = current_time_monotonic(tox1->mono_time); |
25 | 9 | Mono_Time *mono_time; |
26 | | |
27 | 9 | mono_time = tox1->mono_time; |
28 | 9 | mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &clock); |
29 | | |
30 | 9 | mono_time = tox2->mono_time; |
31 | 9 | mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &clock); |
32 | | |
33 | 9 | printf("Waiting for LAN discovery. This loop will attempt to run until successful."); |
34 | | |
35 | 729 | do { |
36 | 729 | printf("."); |
37 | 729 | fflush(stdout); |
38 | | |
39 | 729 | tox_iterate(tox1, nullptr); |
40 | 729 | tox_iterate(tox2, nullptr); |
41 | 729 | c_sleep(5); |
42 | 729 | clock += 100; |
43 | 729 | } while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || |
44 | 729 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE); |
45 | | |
46 | 9 | printf(" %u <-> %u\n", |
47 | 9 | tox_self_get_connection_status(tox1), |
48 | 9 | tox_self_get_connection_status(tox2)); |
49 | | |
50 | 9 | tox_kill(tox2); |
51 | 9 | tox_kill(tox1); |
52 | 9 | return 0; |
53 | 17 | } |