diff options
-rw-r--r-- | auto_tests/tox_test.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 1901a2f8..7e2e455e 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c | |||
@@ -26,6 +26,27 @@ void accept_friend_request(uint8_t *public_key, uint8_t *data, uint16_t length, | |||
26 | if (length == 7 && memcmp("Gentoo", data, 7) == 0) | 26 | if (length == 7 && memcmp("Gentoo", data, 7) == 0) |
27 | tox_add_friend_norequest(t, public_key); | 27 | tox_add_friend_norequest(t, public_key); |
28 | } | 28 | } |
29 | uint32_t messages_received; | ||
30 | |||
31 | void print_message(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) | ||
32 | { | ||
33 | if (*((uint32_t *)userdata) != 974536) | ||
34 | return; | ||
35 | |||
36 | if (length == sizeof("Install Gentoo") && memcmp(string, "Install Gentoo", sizeof("Install Gentoo")) == 0) | ||
37 | ++messages_received; | ||
38 | } | ||
39 | |||
40 | uint32_t name_changes; | ||
41 | |||
42 | void print_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) | ||
43 | { | ||
44 | if (*((uint32_t *)userdata) != 974536) | ||
45 | return; | ||
46 | |||
47 | if (length == sizeof("Gentoo") && memcmp(string, "Gentoo", sizeof("Gentoo")) == 0) | ||
48 | ++name_changes; | ||
49 | } | ||
29 | 50 | ||
30 | START_TEST(test_few_clients) | 51 | START_TEST(test_few_clients) |
31 | { | 52 | { |
@@ -51,6 +72,43 @@ START_TEST(test_few_clients) | |||
51 | c_sleep(50); | 72 | c_sleep(50); |
52 | } | 73 | } |
53 | 74 | ||
75 | printf("tox clients connected\n"); | ||
76 | uint32_t to_compare = 974536; | ||
77 | tox_callback_friend_message(tox3, print_message, &to_compare); | ||
78 | tox_send_message(tox2, 0, "Install Gentoo", sizeof("Install Gentoo")); | ||
79 | |||
80 | while (1) { | ||
81 | messages_received = 0; | ||
82 | tox_do(tox1); | ||
83 | tox_do(tox2); | ||
84 | tox_do(tox3); | ||
85 | |||
86 | if (messages_received) | ||
87 | break; | ||
88 | |||
89 | c_sleep(50); | ||
90 | } | ||
91 | |||
92 | printf("tox clients messaging succeeded\n"); | ||
93 | |||
94 | tox_callback_name_change(tox3, print_nickchange, &to_compare); | ||
95 | tox_set_name(tox2, "Gentoo", sizeof("Gentoo")); | ||
96 | |||
97 | while (1) { | ||
98 | name_changes = 0; | ||
99 | tox_do(tox1); | ||
100 | tox_do(tox2); | ||
101 | tox_do(tox3); | ||
102 | |||
103 | if (name_changes) | ||
104 | break; | ||
105 | |||
106 | c_sleep(50); | ||
107 | } | ||
108 | |||
109 | uint8_t temp_name[sizeof("Gentoo")]; | ||
110 | tox_get_name(tox3, 0, temp_name); | ||
111 | ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct"); | ||
54 | printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time); | 112 | printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time); |
55 | } | 113 | } |
56 | END_TEST | 114 | END_TEST |