Astyled and added tests.

This commit is contained in:
irungentoo 2014-02-18 13:49:17 -05:00
parent 472ab51bc5
commit 62ef4ed95d
4 changed files with 66 additions and 15 deletions

View File

@ -112,7 +112,8 @@ START_TEST(test_ip_equal)
ip2.ip6.uint32[2] = htonl(0xFFFF);
ip2.ip6.uint32[3] = htonl(0x7F000001);
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.");
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.");
res = ip_equal(&ip1, &ip2);
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.");

View File

@ -49,6 +49,19 @@ void print_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length
++name_changes;
}
uint32_t typing_changes;
void print_typingchange(Tox *m, int friendnumber, int typing, void *userdata)
{
if (*((uint32_t *)userdata) != 974536)
return;
if (!typing)
typing_changes = 1;
else
typing_changes = 2;
}
START_TEST(test_few_clients)
{
long long unsigned int cur_time = time(NULL);
@ -118,6 +131,43 @@ START_TEST(test_few_clients)
uint8_t temp_name[sizeof("Gentoo")];
tox_get_name(tox3, 0, temp_name);
ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct");
tox_callback_typing_change(tox2, &print_typingchange, &to_compare);
tox_set_user_is_typing(tox3, 0, 1);
while (1) {
typing_changes = 0;
tox_do(tox1);
tox_do(tox2);
tox_do(tox3);
if (typing_changes == 2)
break;
else
ck_assert_msg(typing_changes == 0, "Typing fail");
c_sleep(50);
}
ck_assert_msg(tox_get_is_typing(tox2, 0) == 1, "Typing fail");
tox_set_user_is_typing(tox3, 0, 0);
while (1) {
typing_changes = 0;
tox_do(tox1);
tox_do(tox2);
tox_do(tox3);
if (typing_changes == 1)
break;
else
ck_assert_msg(typing_changes == 0, "Typing fail");
c_sleep(50);
}
ck_assert_msg(tox_get_is_typing(tox2, 0) == 0, "Typing fail");
printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
}
END_TEST

View File

@ -622,13 +622,13 @@ int m_set_usertyping(Messenger *m, int friendnumber, uint8_t is_typing)
if (is_typing != 0 && is_typing != 1) {
return -1;
}
if (friend_not_valid(m, friendnumber))
return -1;
m->friendlist[friendnumber].user_istyping = is_typing;
m->friendlist[friendnumber].user_istyping_sent = 0;
return 0;
}
@ -636,7 +636,7 @@ int m_get_istyping(Messenger *m, int friendnumber)
{
if (friend_not_valid(m, friendnumber))
return -1;
return m->friendlist[friendnumber].is_typing;
}
@ -1863,7 +1863,7 @@ void do_friends(Messenger *m)
if (send_userstatus(m, i, m->userstatus))
m->friendlist[i].userstatus_sent = 1;
}
if (m->friendlist[i].user_istyping_sent == 0) {
if (send_user_istyping(m, i, m->friendlist[i].user_istyping))
m->friendlist[i].user_istyping_sent = 1;
@ -1929,18 +1929,18 @@ void do_friends(Messenger *m)
set_friend_userstatus(m, i, status);
break;
}
case PACKET_ID_TYPING: {
if (data_length != 1)
break;
uint8_t typing = data[0];
if (m->friend_typingchange)
m->friend_typingchange(m, i, typing, m->friend_typingchange_userdata);
set_friend_typing(m, i, typing);
break;
set_friend_typing(m, i, typing);
break;
}
case PACKET_ID_MESSAGE: {

View File

@ -280,7 +280,7 @@ int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen);
*/
TOX_USERSTATUS tox_get_user_status(Tox *tox, int friendnumber);
TOX_USERSTATUS tox_get_self_user_status(Tox *tox);
/* Set our typing status for a friend.
* You are responsible for turning it on or off.
*
@ -288,7 +288,7 @@ TOX_USERSTATUS tox_get_self_user_status(Tox *tox);
* returns -1 on failure.
*/
int tox_set_user_is_typing(Tox *tox, int friendnumber, uint8_t is_typing);
/* Get the typing status of a friend.
*
* returns 0 if friend is not typing.
@ -350,7 +350,7 @@ void tox_callback_status_message(Tox *tox, void (*function)(Tox *tox, int, uint8
* function(int friendnumber, USERSTATUS kind)
*/
void tox_callback_user_status(Tox *tox, void (*function)(Tox *tox, int, TOX_USERSTATUS, void *), void *userdata);
/* Set the callback for typing changes.
* function (int friendnumber, int is_typing)
*/