Merge pull request #505 from sonOfRa/refactor

Fix testing files to fit to API changes
This commit is contained in:
irungentoo 2013-08-20 14:15:58 -07:00
commit 6de3e0607d
5 changed files with 16 additions and 91 deletions

View File

@ -44,6 +44,8 @@
#define c_sleep(x) usleep(1000*x)
#endif
#define PORT 33445
static Messenger *m;
uint8_t *parent_id = NULL;
@ -52,13 +54,13 @@ uint8_t *child_id = NULL;
pid_t child_pid = 0;
int request_flags = 0;
void do_tox(void)
void do_tox(DHT *dht)
{
static int dht_on = 0;
if (!dht_on && DHT_isconnected()) {
if (!dht_on && DHT_isconnected(dht)) {
dht_on = 1;
} else if (dht_on && !DHT_isconnected()) {
} else if (dht_on && !DHT_isconnected(dht)) {
dht_on = 0;
}
@ -77,7 +79,7 @@ void parent_confirm_status(Messenger *m, int num, uint8_t *data, uint16_t length
request_flags |= FIRST_FLAG;
}
int parent_friend_request(void)
int parent_friend_request(DHT *dht)
{
char *message = "Watson, come here, I need you.";
int len = strlen(message);
@ -90,7 +92,7 @@ int parent_friend_request(void)
/* wait on the status change */
for (i = 0; i < WAIT_COUNT; i++) {
do_tox();
do_tox(dht);
if (request_flags & FIRST_FLAG)
break;
@ -123,7 +125,7 @@ void child_got_statuschange(Messenger *m, int friend_num, uint8_t *string, uint1
request_flags |= SECOND_FLAG;
}
int parent_wait_for_message(void)
int parent_wait_for_message(DHT *dht)
{
int i = 0;
@ -131,7 +133,7 @@ int parent_wait_for_message(void)
fflush(stdout);
for (i = 0; i < WAIT_COUNT; i++) {
do_tox();
do_tox(dht);
if (request_flags & SECOND_FLAG)
break;
@ -185,16 +187,16 @@ int main(int argc, char *argv[])
/* wait on the friend request */
while (!(request_flags & FIRST_FLAG))
do_tox();
do_tox(m->dht);
/* wait for the status change */
while (!(request_flags & SECOND_FLAG))
do_tox();
do_tox(m->dht);
for (i = 0; i < 6; i++) {
/* send the message six times, just to be sure */
m_sendmessage(m, 0, (uint8_t *)message, strlen(message));
do_tox();
do_tox(m->dht);
}
cleanupMessenger(m);
@ -220,10 +222,10 @@ int main(int argc, char *argv[])
Messenger_save(m, parent_id);
if (parent_friend_request() == -1)
if (parent_friend_request(m->dht) == -1)
return -1;
if (parent_wait_for_message() == -1)
if (parent_wait_for_message(m->dht) == -1)
return -1;
wait(NULL);

View File

@ -9,7 +9,6 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/crypto_speed_test.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/timer_test.cmake)
if(WIN32)
# include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake)

View File

@ -48,6 +48,7 @@
#include <unistd.h>
#include <arpa/inet.h>
#define c_sleep(x) usleep(1000*x)
#define PORT 33445
#endif
@ -106,7 +107,7 @@ int main(int argc, char *argv[])
IP_Port bootstrap_ip_port;
bootstrap_ip_port.port = htons(atoi(argv[2]));
bootstrap_ip_port.ip.i = inet_addr(argv[1]);
DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
DHT_bootstrap(m->dht, bootstrap_ip_port, hex_string_to_bin(argv[3]));
} else {
FILE *file = fopen(argv[1], "rb");

View File

@ -1,9 +0,0 @@
cmake_minimum_required(VERSION 2.6.0)
project(timer_test C)
set(exe_name timer_test)
add_executable(${exe_name}
timer_test.c)
linkCoreLibraries(${exe_name})

View File

@ -1,68 +0,0 @@
#include "../core/timer.h"
#include <stdio.h>
#ifdef WINDOWS
#include <windows.h>
#else
#include <unistd.h>
#endif
void mssleep(int ms)
{
#ifdef WINDOWS
Sleep(ms);
#else
usleep(ms * 1000);
#endif
}
int callback(timer *t, void *arg)
{
printf("%s\n", (char *)arg);
return 1;
}
int repeating(timer *t, void *arg)
{
printf("%s\n", (char *)arg);
timer_start(t, 3);
return 0;
}
extern void timer_debug_print();
int main(int argc, char **argv)
{
timer_init();
timer_debug_print();
timer *t = new_timer();
timer_setup(t, &callback, "Long setup method, 4 seconds");
timer_start(t, 4);
timer_debug_print();
timer_single(&repeating, (void *)"This repeats every 3 seconds", 3);
timer_debug_print();
timer_single(&callback, "Short method, 4 seconds", 4);
timer_debug_print();
timer_single(&callback, "1 second", 1);
timer_debug_print();
timer_single(&callback, "15 seconds", 15);
timer_debug_print();
timer_single(&callback, "10 seconds", 10);
timer_debug_print();
timer_us(&callback, "100000us", 100000);
timer_us(&callback, "13s", 13 * US_PER_SECOND);
while (true) {
timer_poll();
mssleep(10);
}
return 0;
}