Skip to content

Commit

Permalink
Ported some of the code in testing/ to the new api.
Browse files Browse the repository at this point in the history
  • Loading branch information
irungentoo committed Feb 25, 2015
1 parent 8fa8e9d commit d83efd3
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 879 deletions.
15 changes: 0 additions & 15 deletions testing/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,6 @@ tox_shell_LDADD = $(LIBSODIUM_LDFLAGS) \
-lutil


noinst_PROGRAMS += test_avatars

test_avatars_SOURCES = ../testing/test_avatars.c

test_avatars_CFLAGS = $(LIBSODIUM_CFLAGS) \
$(NACL_CFLAGS)

test_avatars_LDADD = $(LIBSODIUM_LDFLAGS) \
$(NACL_LDFLAGS) \
libtoxcore.la \
$(LIBSODIUM_LIBS) \
$(NACL_OBJECTS) \
$(NACL_LIBS)


noinst_PROGRAMS += irc_syncbot

irc_syncbot_SOURCES = ../testing/irc_syncbot.c
Expand Down
12 changes: 6 additions & 6 deletions testing/Messenger_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@

#endif

void print_message(Messenger *m, int friendnumber, const uint8_t *string, uint16_t length, void *userdata)
void print_message(Messenger *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata)
{
printf("Message with length %u received from %u: %s \n", length, friendnumber, string);
m_sendmessage(m, friendnumber, (uint8_t *)"Test1", 6);
printf("Message with length %lu received from %u: %s \n", length, friendnumber, string);
m_sendmessage(m, friendnumber, (uint8_t *)"Test1", 6, 0);
}

/* FIXME needed as print_request has to match the interface expected by
* networking_requesthandler and so cannot take a Messenger * */
static Messenger *m;

void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
{
printf("Friend request received from: \n");
printf("ClientID: ");
Expand All @@ -79,7 +79,7 @@ void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data,
printf("%hhX", public_key[j]);
}

printf("\nOf length: %u with data: %s \n", length, data);
printf("\nOf length: %lu with data: %s \n", length, data);

if (length != sizeof("Install Gentoo")) {
return;
Expand Down Expand Up @@ -184,7 +184,7 @@ int main(int argc, char *argv[])
getname(m, num, name);
printf("%s\n", name);

m_sendmessage(m, num, (uint8_t *)"Test", 5);
m_sendmessage(m, num, (uint8_t *)"Test", 5, 0);
do_messenger(m);
c_sleep(30);
FILE *file = fopen("Save.bak", "wb");
Expand Down
4 changes: 2 additions & 2 deletions testing/dns3_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ int main(int argc, char *argv[])

for (i = r_len - 1; i != 0 && buffer[i] != '='; --i);

uint8_t tox_id[TOX_FRIEND_ADDRESS_SIZE];
uint8_t tox_id[TOX_ADDRESS_SIZE];

if (tox_decrypt_dns3_TXT(d, tox_id, buffer + i + 1, r_len - (i + 1), request_id) != 0)
return -1;

printf("The Tox id for username %s is:\n", argv[3]);

//unsigned int i;
for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; ++i) {
for (i = 0; i < TOX_ADDRESS_SIZE; ++i) {
printf("%02hhX", tox_id[i]);
}

Expand Down
16 changes: 8 additions & 8 deletions testing/irc_syncbot.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void callback_group_invite(Tox *tox, int fid, uint8_t type, const uint8_t
current_group = tox_join_groupchat(tox, fid, data, length);
}

void callback_friend_message(Tox *tox, int fid, const uint8_t *message, uint16_t length, void *userdata)
void callback_friend_message(Tox *tox, uint32_t fid, const uint8_t *message, size_t length, void *userdata)
{
if (length == 1 && *message == 'c') {
if (tox_del_groupchat(tox, current_group) == 0)
Expand Down Expand Up @@ -203,7 +203,7 @@ void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len)

Tox *init_tox(int argc, char *argv[])
{
uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
uint8_t ipv6enabled = 1; /* x */
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);

if (argvoffset < 0)
Expand All @@ -215,20 +215,20 @@ Tox *init_tox(int argc, char *argv[])
exit(0);
}

Tox *tox = tox_new(0);
Tox *tox = tox_new(0, 0, 0, 0);

if (!tox)
exit(1);

tox_set_name(tox, (uint8_t *)IRC_NAME, sizeof(IRC_NAME) - 1);
tox_self_set_name(tox, (uint8_t *)IRC_NAME, sizeof(IRC_NAME) - 1, 0);
tox_callback_friend_message(tox, &callback_friend_message, 0);
tox_callback_group_invite(tox, &callback_group_invite, 0);
tox_callback_group_message(tox, &copy_groupmessage, 0);
tox_callback_group_action(tox, &copy_groupmessage, 0);

uint16_t port = atoi(argv[argvoffset + 2]);
unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
int res = tox_bootstrap_from_address(tox, argv[argvoffset + 1], port, binary_string);
tox_bootstrap(tox, argv[argvoffset + 1], port, binary_string, 0);
free(binary_string);

char temp_id[128];
Expand All @@ -239,10 +239,10 @@ Tox *init_tox(int argc, char *argv[])
}

uint8_t *bin_id = hex_string_to_bin(temp_id);
int num = tox_add_friend(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo") - 1);
uint32_t num = tox_friend_add(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo") - 1, 0);
free(bin_id);

if (num < 0) {
if (num == UINT32_MAX) {
printf("\nSomething went wrong when adding friend.\n");
exit(1);
}
Expand Down Expand Up @@ -342,7 +342,7 @@ int main(int argc, char *argv[])
}
}

tox_do(tox);
tox_iteration(tox);
usleep(1000 * 50);
}

Expand Down
Loading

0 comments on commit d83efd3

Please sign in to comment.