/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 | 463k | { |
11 | 463k | const uint64_t *clock = (const uint64_t *)user_data; |
12 | 463k | return *clock; |
13 | 463k | } |
14 | | |
15 | | int main(void) |
16 | 39 | { |
17 | 39 | setvbuf(stdout, nullptr, _IONBF, 0); |
18 | | |
19 | 39 | Tox *tox1 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true); |
20 | 39 | Tox *tox2 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true); |
21 | 39 | ck_assert(tox1 != nullptr); |
22 | 17 | ck_assert(tox2 != nullptr); |
23 | | |
24 | 10 | uint64_t clock = current_time_monotonic(tox1->mono_time); |
25 | 10 | Mono_Time *mono_time; |
26 | | |
27 | 10 | mono_time = tox1->mono_time; |
28 | 10 | mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &clock); |
29 | | |
30 | 10 | mono_time = tox2->mono_time; |
31 | 10 | mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &clock); |
32 | | |
33 | 10 | printf("Waiting for LAN discovery. This loop will attempt to run until successful."); |
34 | | |
35 | 1.13k | do { |
36 | 1.13k | printf("."); |
37 | 1.13k | fflush(stdout); |
38 | | |
39 | 1.13k | tox_iterate(tox1, nullptr); |
40 | 1.13k | tox_iterate(tox2, nullptr); |
41 | 1.13k | c_sleep(5); |
42 | 1.13k | clock += 100; |
43 | 1.13k | } while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || |
44 | 1.13k | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE); |
45 | | |
46 | 10 | printf(" %d <-> %d\n", |
47 | 10 | tox_self_get_connection_status(tox1), |
48 | 10 | tox_self_get_connection_status(tox2)); |
49 | | |
50 | 10 | tox_kill(tox2); |
51 | 10 | tox_kill(tox1); |
52 | 10 | return 0; |
53 | 17 | } |