mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Ported some tests to the new api.
This commit is contained in:
parent
ca997bda70
commit
76dfccf2d6
|
@ -50,10 +50,10 @@ START_TEST(test_m_sendmesage)
|
|||
int bad_len = MAX_CRYPTO_PACKET_SIZE;
|
||||
|
||||
|
||||
ck_assert(m_sendmessage(m, -1, (uint8_t *)message, good_len) == 0);
|
||||
ck_assert(m_sendmessage(m, REALLY_BIG_NUMBER, (uint8_t *)message, good_len) == 0);
|
||||
ck_assert(m_sendmessage(m, 17, (uint8_t *)message, good_len) == 0);
|
||||
ck_assert(m_sendmessage(m, friend_id_num, (uint8_t *)message, bad_len) == 0);
|
||||
ck_assert(m_sendmessage(m, -1, (uint8_t *)message, good_len, 0) == -1);
|
||||
ck_assert(m_sendmessage(m, REALLY_BIG_NUMBER, (uint8_t *)message, good_len, 0) == -1);
|
||||
ck_assert(m_sendmessage(m, 17, (uint8_t *)message, good_len, 0) == -1);
|
||||
ck_assert(m_sendmessage(m, friend_id_num, (uint8_t *)message, bad_len, 0) == -2);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
@ -68,10 +68,10 @@ START_TEST(test_m_get_userstatus_size)
|
|||
rc = m_get_statusmessage_size(m, friend_id_num);
|
||||
|
||||
/* this WILL error if the original m_addfriend_norequest() failed */
|
||||
ck_assert_msg((rc > 0 && rc <= MAX_STATUSMESSAGE_LENGTH),
|
||||
"m_get_statusmessage_size is returning out of range values!\n"
|
||||
ck_assert_msg((rc >= 0 && rc <= MAX_STATUSMESSAGE_LENGTH),
|
||||
"m_get_statusmessage_size is returning out of range values! (%i)\n"
|
||||
"(this can be caused by the error of m_addfriend_norequest"
|
||||
" in the beginning of the suite)\n");
|
||||
" in the beginning of the suite)\n", rc);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
|
@ -21,18 +21,18 @@
|
|||
#define c_sleep(x) usleep(1000*x)
|
||||
#endif
|
||||
|
||||
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
|
||||
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
|
||||
{
|
||||
if (*((uint32_t *)userdata) != 974536)
|
||||
return;
|
||||
|
||||
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
|
||||
tox_add_friend_norequest(m, public_key);
|
||||
tox_friend_add_norequest(m, public_key, 0);
|
||||
}
|
||||
}
|
||||
uint32_t messages_received;
|
||||
|
||||
void print_message(Tox *m, int friendnumber, const uint8_t *string, uint16_t length, void *userdata)
|
||||
void print_message(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata)
|
||||
{
|
||||
if (*((uint32_t *)userdata) != 974536)
|
||||
return;
|
||||
|
@ -46,7 +46,7 @@ void print_message(Tox *m, int friendnumber, const uint8_t *string, uint16_t len
|
|||
|
||||
uint32_t name_changes;
|
||||
|
||||
void print_nickchange(Tox *m, int friendnumber, const uint8_t *string, uint16_t length, void *userdata)
|
||||
void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata)
|
||||
{
|
||||
if (*((uint32_t *)userdata) != 974536)
|
||||
return;
|
||||
|
@ -57,7 +57,7 @@ void print_nickchange(Tox *m, int friendnumber, const uint8_t *string, uint16_t
|
|||
|
||||
uint32_t typing_changes;
|
||||
|
||||
void print_typingchange(Tox *m, int friendnumber, uint8_t typing, void *userdata)
|
||||
void print_typingchange(Tox *m, uint32_t friendnumber, bool typing, void *userdata)
|
||||
{
|
||||
if (*((uint32_t *)userdata) != 974536)
|
||||
return;
|
||||
|
@ -144,27 +144,35 @@ void write_file(Tox *m, int friendnumber, uint8_t filenumber, const uint8_t *dat
|
|||
|
||||
START_TEST(test_one)
|
||||
{
|
||||
Tox *tox1 = tox_new(0);
|
||||
Tox *tox2 = tox_new(0);
|
||||
Tox *tox1 = tox_new(0, 0, 0, 0);
|
||||
Tox *tox2 = tox_new(0, 0, 0, 0);
|
||||
|
||||
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(tox1, address);
|
||||
ck_assert_msg(tox_add_friend(tox1, address, (uint8_t *)"m", 1) == TOX_FAERR_OWNKEY, "Adding own address worked.");
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(tox1, address);
|
||||
TOX_ERR_FRIEND_ADD error;
|
||||
uint32_t ret = tox_friend_add(tox1, address, (uint8_t *)"m", 1, &error);
|
||||
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_OWN_KEY, "Adding own address worked.");
|
||||
|
||||
tox_get_address(tox2, address);
|
||||
uint8_t message[TOX_MAX_FRIENDREQUEST_LENGTH + 1];
|
||||
ck_assert_msg(tox_add_friend(tox1, address, NULL, 0) == TOX_FAERR_NOMESSAGE, "Sending request with no message worked.");
|
||||
ck_assert_msg(tox_add_friend(tox1, address, message, sizeof(message)) == TOX_FAERR_TOOLONG,
|
||||
"TOX_MAX_FRIENDREQUEST_LENGTH is too big.");
|
||||
tox_self_get_address(tox2, address);
|
||||
uint8_t message[TOX_MAX_FRIEND_REQUEST_LENGTH + 1];
|
||||
ret = tox_friend_add(tox1, address, NULL, 0, &error);
|
||||
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_NULL, "Sending request with no message worked.");
|
||||
ret = tox_friend_add(tox1, address, message, 0, &error);
|
||||
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_NO_MESSAGE, "Sending request with no message worked.");
|
||||
ret = tox_friend_add(tox1, address, message, sizeof(message), &error);
|
||||
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_TOO_LONG,
|
||||
"TOX_MAX_FRIEND_REQUEST_LENGTH is too big.");
|
||||
|
||||
address[0]++;
|
||||
ck_assert_msg(tox_add_friend(tox1, address, (uint8_t *)"m", 1) == TOX_FAERR_BADCHECKSUM,
|
||||
ret = tox_friend_add(tox1, address, (uint8_t *)"m", 1, &error);
|
||||
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_BAD_CHECKSUM,
|
||||
"Adding address with bad checksum worked.");
|
||||
|
||||
tox_get_address(tox2, address);
|
||||
ck_assert_msg(tox_add_friend(tox1, address, message, TOX_MAX_FRIENDREQUEST_LENGTH) == 0, "Failed to add friend.");
|
||||
ck_assert_msg(tox_add_friend(tox1, address, message, TOX_MAX_FRIENDREQUEST_LENGTH) == TOX_FAERR_ALREADYSENT,
|
||||
"Adding friend twice worked.");
|
||||
tox_self_get_address(tox2, address);
|
||||
ret = tox_friend_add(tox1, address, message, TOX_MAX_FRIEND_REQUEST_LENGTH, &error);
|
||||
ck_assert_msg(ret == 0 && error == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend.");
|
||||
ret = tox_friend_add(tox1, address, message, TOX_MAX_FRIEND_REQUEST_LENGTH, &error);
|
||||
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_ALREADY_SENT, "Adding friend twice worked.");
|
||||
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH];
|
||||
int i;
|
||||
|
@ -173,22 +181,23 @@ START_TEST(test_one)
|
|||
name[i] = rand();
|
||||
}
|
||||
|
||||
tox_set_name(tox1, name, sizeof(name));
|
||||
ck_assert_msg(tox_get_self_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH");
|
||||
tox_self_set_name(tox1, name, sizeof(name), 0);
|
||||
ck_assert_msg(tox_self_get_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH");
|
||||
|
||||
size_t save_size = tox_size(tox1);
|
||||
size_t save_size = tox_save_size(tox1);
|
||||
uint8_t data[save_size];
|
||||
tox_save(tox1, data);
|
||||
|
||||
tox_kill(tox2);
|
||||
tox2 = tox_new(0);
|
||||
ck_assert_msg(tox_load(tox2, data, save_size) == 0, "Load failed");
|
||||
TOX_ERR_NEW err_n;
|
||||
|
||||
size_t length = tox_get_self_name_size(tox2);
|
||||
ck_assert_msg(tox_get_self_name_size(tox2) == sizeof name, "Wrong name size.");
|
||||
tox2 = tox_new(0, data, save_size, &err_n);
|
||||
ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed");
|
||||
|
||||
ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size.");
|
||||
|
||||
uint8_t new_name[TOX_MAX_NAME_LENGTH] = { 0 };
|
||||
ck_assert_msg(tox_get_self_name(tox2, new_name) == TOX_MAX_NAME_LENGTH, "Wrong name length");
|
||||
tox_self_get_name(tox2, new_name);
|
||||
ck_assert_msg(memcmp(name, new_name, TOX_MAX_NAME_LENGTH) == 0, "Wrong name");
|
||||
|
||||
tox_kill(tox1);
|
||||
|
|
|
@ -55,10 +55,10 @@ typedef struct _Status {
|
|||
/* My default settings */
|
||||
static ToxAvCSettings muhcaps;
|
||||
|
||||
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
|
||||
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
|
||||
{
|
||||
if (length == 7 && memcmp("gentoo", data, 7) == 0) {
|
||||
tox_add_friend_norequest(m, public_key);
|
||||
tox_friend_add_norequest(m, public_key, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ void register_callbacks(ToxAv *av, void *data)
|
|||
*/
|
||||
#define CALL_AND_START_LOOP(AliceCallType, BobCallType) \
|
||||
{ int step = 0, running = 1; while (running) {\
|
||||
tox_do(bootstrap_node); tox_do(Alice); tox_do(Bob); \
|
||||
tox_iteration(bootstrap_node); tox_iteration(Alice); tox_iteration(Bob); \
|
||||
toxav_do(status_control.Bob.av); toxav_do(status_control.Alice.av); \
|
||||
switch ( step ) {\
|
||||
case 0: /* Alice */ printf("Alice is calling...\n");\
|
||||
|
@ -250,33 +250,34 @@ if (status_control.Alice.status == Ended && status_control.Bob.status == Ended)
|
|||
START_TEST(test_AV_flows)
|
||||
{
|
||||
long long unsigned int cur_time = time(NULL);
|
||||
Tox *bootstrap_node = tox_new(0);
|
||||
Tox *Alice = tox_new(0);
|
||||
Tox *Bob = tox_new(0);
|
||||
Tox *bootstrap_node = tox_new(0, 0, 0, 0);
|
||||
Tox *Alice = tox_new(0, 0, 0, 0);
|
||||
Tox *Bob = tox_new(0, 0, 0, 0);
|
||||
|
||||
ck_assert_msg(bootstrap_node || Alice || Bob, "Failed to create 3 tox instances");
|
||||
|
||||
uint32_t to_compare = 974536;
|
||||
tox_callback_friend_request(Alice, accept_friend_request, &to_compare);
|
||||
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(Alice, address);
|
||||
int test = tox_add_friend(Bob, address, (uint8_t *)"gentoo", 7);
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(Alice, address);
|
||||
uint32_t test = tox_friend_add(Bob, address, (uint8_t *)"gentoo", 7, 0);
|
||||
|
||||
ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
|
||||
|
||||
uint8_t off = 1;
|
||||
|
||||
while (1) {
|
||||
tox_do(bootstrap_node);
|
||||
tox_do(Alice);
|
||||
tox_do(Bob);
|
||||
tox_iteration(bootstrap_node);
|
||||
tox_iteration(Alice);
|
||||
tox_iteration(Bob);
|
||||
|
||||
if (tox_isconnected(bootstrap_node) && tox_isconnected(Alice) && tox_isconnected(Bob) && off) {
|
||||
if (tox_get_connection_status(bootstrap_node) && tox_get_connection_status(Alice) && tox_get_connection_status(Bob)
|
||||
&& off) {
|
||||
printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
|
||||
off = 0;
|
||||
}
|
||||
|
||||
if (tox_get_friend_connection_status(Alice, 0) == 1 && tox_get_friend_connection_status(Bob, 0) == 1)
|
||||
if (tox_friend_get_connection_status(Alice, 0, 0) && tox_friend_get_connection_status(Bob, 0, 0))
|
||||
break;
|
||||
|
||||
c_sleep(20);
|
||||
|
@ -483,9 +484,9 @@ START_TEST(test_AV_flows)
|
|||
int running = 1;
|
||||
|
||||
while (running) {
|
||||
tox_do(bootstrap_node);
|
||||
tox_do(Alice);
|
||||
tox_do(Bob);
|
||||
tox_iteration(bootstrap_node);
|
||||
tox_iteration(Alice);
|
||||
tox_iteration(Bob);
|
||||
|
||||
switch ( step ) {
|
||||
case 0: /* Alice */
|
||||
|
@ -524,9 +525,9 @@ START_TEST(test_AV_flows)
|
|||
int running = 1;
|
||||
|
||||
while (running) {
|
||||
tox_do(bootstrap_node);
|
||||
tox_do(Alice);
|
||||
tox_do(Bob);
|
||||
tox_iteration(bootstrap_node);
|
||||
tox_iteration(Alice);
|
||||
tox_iteration(Bob);
|
||||
|
||||
toxav_do(status_control.Alice.av);
|
||||
toxav_do(status_control.Bob.av);
|
||||
|
@ -569,9 +570,9 @@ START_TEST(test_AV_flows)
|
|||
int running = 1;
|
||||
|
||||
while (running) {
|
||||
tox_do(bootstrap_node);
|
||||
tox_do(Alice);
|
||||
tox_do(Bob);
|
||||
tox_iteration(bootstrap_node);
|
||||
tox_iteration(Alice);
|
||||
tox_iteration(Bob);
|
||||
|
||||
toxav_do(status_control.Alice.av);
|
||||
toxav_do(status_control.Bob.av);
|
||||
|
|
|
@ -58,10 +58,10 @@ typedef struct _Status {
|
|||
|
||||
Status status_control;
|
||||
|
||||
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
|
||||
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
|
||||
{
|
||||
if (length == 7 && memcmp("gentoo", data, 7) == 0) {
|
||||
tox_add_friend_norequest(m, public_key);
|
||||
tox_friend_add_norequest(m, public_key, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,12 +264,12 @@ START_TEST(test_AV_three_calls)
|
|||
// void test_AV_three_calls()
|
||||
{
|
||||
long long unsigned int cur_time = time(NULL);
|
||||
Tox *bootstrap_node = tox_new(0);
|
||||
Tox *caller = tox_new(0);
|
||||
Tox *bootstrap_node = tox_new(0, 0, 0, 0);
|
||||
Tox *caller = tox_new(0, 0, 0, 0);
|
||||
Tox *callees[3] = {
|
||||
tox_new(0),
|
||||
tox_new(0),
|
||||
tox_new(0),
|
||||
tox_new(0, 0, 0, 0),
|
||||
tox_new(0, 0, 0, 0),
|
||||
tox_new(0, 0, 0, 0),
|
||||
};
|
||||
|
||||
|
||||
|
@ -284,37 +284,37 @@ START_TEST(test_AV_three_calls)
|
|||
for ( i = 0; i < 3; i ++ ) {
|
||||
uint32_t to_compare = 974536;
|
||||
tox_callback_friend_request(callees[i], accept_friend_request, &to_compare);
|
||||
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(callees[i], address);
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
tox_self_get_address(callees[i], address);
|
||||
|
||||
int test = tox_add_friend(caller, address, (uint8_t *)"gentoo", 7);
|
||||
uint32_t test = tox_friend_add(caller, address, (uint8_t *)"gentoo", 7, 0);
|
||||
ck_assert_msg( test == i, "Failed to add friend error code: %i", test);
|
||||
}
|
||||
|
||||
uint8_t off = 1;
|
||||
|
||||
while (1) {
|
||||
tox_do(bootstrap_node);
|
||||
tox_do(caller);
|
||||
tox_iteration(bootstrap_node);
|
||||
tox_iteration(caller);
|
||||
|
||||
for (i = 0; i < 3; i ++) {
|
||||
tox_do(callees[i]);
|
||||
tox_iteration(callees[i]);
|
||||
}
|
||||
|
||||
|
||||
if (tox_isconnected(bootstrap_node) &&
|
||||
tox_isconnected(caller) &&
|
||||
tox_isconnected(callees[0]) &&
|
||||
tox_isconnected(callees[1]) &&
|
||||
tox_isconnected(callees[2]) && off) {
|
||||
if (tox_get_connection_status(bootstrap_node) &&
|
||||
tox_get_connection_status(caller) &&
|
||||
tox_get_connection_status(callees[0]) &&
|
||||
tox_get_connection_status(callees[1]) &&
|
||||
tox_get_connection_status(callees[2]) && off) {
|
||||
printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
|
||||
off = 0;
|
||||
}
|
||||
|
||||
|
||||
if (tox_get_friend_connection_status(caller, 0) == 1 &&
|
||||
tox_get_friend_connection_status(caller, 1) == 1 &&
|
||||
tox_get_friend_connection_status(caller, 2) == 1 )
|
||||
if (tox_friend_get_connection_status(caller, 0, 0) &&
|
||||
tox_friend_get_connection_status(caller, 1, 0) &&
|
||||
tox_friend_get_connection_status(caller, 2, 0) )
|
||||
break;
|
||||
|
||||
c_sleep(20);
|
||||
|
@ -351,11 +351,11 @@ START_TEST(test_AV_three_calls)
|
|||
while (call_running[0] || call_running[1] || call_running[2]) {
|
||||
pthread_mutex_lock(&muhmutex);
|
||||
|
||||
tox_do(bootstrap_node);
|
||||
tox_do(caller);
|
||||
tox_do(callees[0]);
|
||||
tox_do(callees[1]);
|
||||
tox_do(callees[2]);
|
||||
tox_iteration(bootstrap_node);
|
||||
tox_iteration(caller);
|
||||
tox_iteration(callees[0]);
|
||||
tox_iteration(callees[1]);
|
||||
tox_iteration(callees[2]);
|
||||
|
||||
for ( i = 0; i < 3; i++ )
|
||||
toxav_do(status_control.calls[0].Caller.av);
|
||||
|
|
|
@ -491,21 +491,11 @@ static int send_message_generic(Messenger *m, int32_t friendnumber, const uint8_
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Send a text chat message to an online friend.
|
||||
*
|
||||
* return the message id if packet was successfully put into the send queue.
|
||||
* return 0 if it was not.
|
||||
*/
|
||||
int m_sendmessage(Messenger *m, int32_t friendnumber, const uint8_t *message, uint32_t length, uint32_t *message_id)
|
||||
{
|
||||
return send_message_generic(m, friendnumber, message, length, PACKET_ID_MESSAGE, message_id);
|
||||
}
|
||||
|
||||
/* Send an action to an online friend.
|
||||
*
|
||||
* return the message id if packet was successfully put into the send queue.
|
||||
* return 0 if it was not.
|
||||
*/
|
||||
int m_sendaction(Messenger *m, int32_t friendnumber, const uint8_t *action, uint32_t length, uint32_t *message_id)
|
||||
{
|
||||
return send_message_generic(m, friendnumber, action, length, PACKET_ID_ACTION, message_id);
|
||||
|
|
Loading…
Reference in New Issue
Block a user