summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/network_test.c3
-rw-r--r--auto_tests/tox_test.c50
-rw-r--r--toxcore/Messenger.c22
-rw-r--r--toxcore/tox.h6
4 files changed, 66 insertions, 15 deletions
diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c
index bf6ef17a..3b4b50cd 100644
--- a/auto_tests/network_test.c
+++ b/auto_tests/network_test.c
@@ -112,7 +112,8 @@ START_TEST(test_ip_equal)
112 ip2.ip6.uint32[2] = htonl(0xFFFF); 112 ip2.ip6.uint32[2] = htonl(0xFFFF);
113 ip2.ip6.uint32[3] = htonl(0x7F000001); 113 ip2.ip6.uint32[3] = htonl(0x7F000001);
114 114
115 ck_assert_msg(IN6_IS_ADDR_V4MAPPED(&ip2.ip6.in6_addr) != 0, "IN6_IS_ADDR_V4MAPPED(::ffff:127.0.0.1): expected != 0, got 0."); 115 ck_assert_msg(IN6_IS_ADDR_V4MAPPED(&ip2.ip6.in6_addr) != 0,
116 "IN6_IS_ADDR_V4MAPPED(::ffff:127.0.0.1): expected != 0, got 0.");
116 117
117 res = ip_equal(&ip1, &ip2); 118 res = ip_equal(&ip1, &ip2);
118 ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::ffff:127.0.0.1} ): expected result != 0, got 0."); 119 ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::ffff:127.0.0.1} ): expected result != 0, got 0.");
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index 06e8e257..def9e5df 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -49,6 +49,19 @@ void print_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length
49 ++name_changes; 49 ++name_changes;
50} 50}
51 51
52uint32_t typing_changes;
53
54void print_typingchange(Tox *m, int friendnumber, int typing, void *userdata)
55{
56 if (*((uint32_t *)userdata) != 974536)
57 return;
58
59 if (!typing)
60 typing_changes = 1;
61 else
62 typing_changes = 2;
63}
64
52START_TEST(test_few_clients) 65START_TEST(test_few_clients)
53{ 66{
54 long long unsigned int cur_time = time(NULL); 67 long long unsigned int cur_time = time(NULL);
@@ -118,6 +131,43 @@ START_TEST(test_few_clients)
118 uint8_t temp_name[sizeof("Gentoo")]; 131 uint8_t temp_name[sizeof("Gentoo")];
119 tox_get_name(tox3, 0, temp_name); 132 tox_get_name(tox3, 0, temp_name);
120 ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct"); 133 ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct");
134
135 tox_callback_typing_change(tox2, &print_typingchange, &to_compare);
136 tox_set_user_is_typing(tox3, 0, 1);
137
138 while (1) {
139 typing_changes = 0;
140 tox_do(tox1);
141 tox_do(tox2);
142 tox_do(tox3);
143
144
145 if (typing_changes == 2)
146 break;
147 else
148 ck_assert_msg(typing_changes == 0, "Typing fail");
149
150 c_sleep(50);
151 }
152
153 ck_assert_msg(tox_get_is_typing(tox2, 0) == 1, "Typing fail");
154 tox_set_user_is_typing(tox3, 0, 0);
155
156 while (1) {
157 typing_changes = 0;
158 tox_do(tox1);
159 tox_do(tox2);
160 tox_do(tox3);
161
162 if (typing_changes == 1)
163 break;
164 else
165 ck_assert_msg(typing_changes == 0, "Typing fail");
166
167 c_sleep(50);
168 }
169
170 ck_assert_msg(tox_get_is_typing(tox2, 0) == 0, "Typing fail");
121 printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time); 171 printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
122} 172}
123END_TEST 173END_TEST
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index cca397d7..69bc845a 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -622,13 +622,13 @@ int m_set_usertyping(Messenger *m, int friendnumber, uint8_t is_typing)
622 if (is_typing != 0 && is_typing != 1) { 622 if (is_typing != 0 && is_typing != 1) {
623 return -1; 623 return -1;
624 } 624 }
625 625
626 if (friend_not_valid(m, friendnumber)) 626 if (friend_not_valid(m, friendnumber))
627 return -1; 627 return -1;
628 628
629 m->friendlist[friendnumber].user_istyping = is_typing; 629 m->friendlist[friendnumber].user_istyping = is_typing;
630 m->friendlist[friendnumber].user_istyping_sent = 0; 630 m->friendlist[friendnumber].user_istyping_sent = 0;
631 631
632 return 0; 632 return 0;
633} 633}
634 634
@@ -636,7 +636,7 @@ int m_get_istyping(Messenger *m, int friendnumber)
636{ 636{
637 if (friend_not_valid(m, friendnumber)) 637 if (friend_not_valid(m, friendnumber))
638 return -1; 638 return -1;
639 639
640 return m->friendlist[friendnumber].is_typing; 640 return m->friendlist[friendnumber].is_typing;
641} 641}
642 642
@@ -1863,7 +1863,7 @@ void do_friends(Messenger *m)
1863 if (send_userstatus(m, i, m->userstatus)) 1863 if (send_userstatus(m, i, m->userstatus))
1864 m->friendlist[i].userstatus_sent = 1; 1864 m->friendlist[i].userstatus_sent = 1;
1865 } 1865 }
1866 1866
1867 if (m->friendlist[i].user_istyping_sent == 0) { 1867 if (m->friendlist[i].user_istyping_sent == 0) {
1868 if (send_user_istyping(m, i, m->friendlist[i].user_istyping)) 1868 if (send_user_istyping(m, i, m->friendlist[i].user_istyping))
1869 m->friendlist[i].user_istyping_sent = 1; 1869 m->friendlist[i].user_istyping_sent = 1;
@@ -1929,18 +1929,18 @@ void do_friends(Messenger *m)
1929 set_friend_userstatus(m, i, status); 1929 set_friend_userstatus(m, i, status);
1930 break; 1930 break;
1931 } 1931 }
1932 1932
1933 case PACKET_ID_TYPING: { 1933 case PACKET_ID_TYPING: {
1934 if (data_length != 1) 1934 if (data_length != 1)
1935 break; 1935 break;
1936 1936
1937 uint8_t typing = data[0]; 1937 uint8_t typing = data[0];
1938 1938
1939 if (m->friend_typingchange) 1939 if (m->friend_typingchange)
1940 m->friend_typingchange(m, i, typing, m->friend_typingchange_userdata); 1940 m->friend_typingchange(m, i, typing, m->friend_typingchange_userdata);
1941 1941
1942 set_friend_typing(m, i, typing); 1942 set_friend_typing(m, i, typing);
1943 break; 1943 break;
1944 } 1944 }
1945 1945
1946 case PACKET_ID_MESSAGE: { 1946 case PACKET_ID_MESSAGE: {
diff --git a/toxcore/tox.h b/toxcore/tox.h
index c95a4fd3..1db5c46e 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -280,7 +280,7 @@ int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen);
280 */ 280 */
281TOX_USERSTATUS tox_get_user_status(Tox *tox, int friendnumber); 281TOX_USERSTATUS tox_get_user_status(Tox *tox, int friendnumber);
282TOX_USERSTATUS tox_get_self_user_status(Tox *tox); 282TOX_USERSTATUS tox_get_self_user_status(Tox *tox);
283 283
284/* Set our typing status for a friend. 284/* Set our typing status for a friend.
285 * You are responsible for turning it on or off. 285 * You are responsible for turning it on or off.
286 * 286 *
@@ -288,7 +288,7 @@ TOX_USERSTATUS tox_get_self_user_status(Tox *tox);
288 * returns -1 on failure. 288 * returns -1 on failure.
289 */ 289 */
290int tox_set_user_is_typing(Tox *tox, int friendnumber, uint8_t is_typing); 290int tox_set_user_is_typing(Tox *tox, int friendnumber, uint8_t is_typing);
291 291
292/* Get the typing status of a friend. 292/* Get the typing status of a friend.
293 * 293 *
294 * returns 0 if friend is not typing. 294 * returns 0 if friend is not typing.
@@ -350,7 +350,7 @@ void tox_callback_status_message(Tox *tox, void (*function)(Tox *tox, int, uint8
350 * function(int friendnumber, USERSTATUS kind) 350 * function(int friendnumber, USERSTATUS kind)
351 */ 351 */
352void tox_callback_user_status(Tox *tox, void (*function)(Tox *tox, int, TOX_USERSTATUS, void *), void *userdata); 352void tox_callback_user_status(Tox *tox, void (*function)(Tox *tox, int, TOX_USERSTATUS, void *), void *userdata);
353 353
354/* Set the callback for typing changes. 354/* Set the callback for typing changes.
355 * function (int friendnumber, int is_typing) 355 * function (int friendnumber, int is_typing)
356 */ 356 */