parent
9e8e98f736
commit
128074a2bd
|
@ -86,3 +86,38 @@ endif
|
|||
lib_ecore_libecore_la_LIBADD += @ECORE_LIBS@ @EFL_COV_LIBS@ -lm
|
||||
|
||||
lib_ecore_libecore_la_LDFLAGS = -no-undefined -version-info @version_info@ @release_info@
|
||||
|
||||
### Unit tests
|
||||
|
||||
if EFL_ENABLE_TESTS
|
||||
|
||||
check_PROGRAMS += tests/ecore/ecore_suite
|
||||
|
||||
tests_ecore_ecore_suite_SOURCES = \
|
||||
tests/ecore/ecore_suite.c \
|
||||
tests/ecore/ecore_test_ecore.c \
|
||||
tests/ecore/ecore_test_ecore_con.c \
|
||||
tests/ecore/ecore_test_ecore_x.c \
|
||||
tests/ecore/ecore_suite.h
|
||||
|
||||
tests_ecore_ecore_suite_CPPFLAGS = \
|
||||
-I$(top_srcdir)/src/lib/eina \
|
||||
-I$(top_srcdir)/src/lib/eo \
|
||||
-I$(top_srcdir)/src/lib/ecore \
|
||||
-I$(top_srcdir)/src/lib/ecore_con \
|
||||
-I$(top_srcdir)/src/lib/ecore_x \
|
||||
-I$(top_builddir)/src/lib/eina \
|
||||
-I$(top_builddir)/src/lib/eo \
|
||||
-I$(top_builddir)/src/lib/ecore \
|
||||
-I$(top_builddir)/src/lib/ecore_con \
|
||||
-I$(top_builddir)/src/lib/ecore_x \
|
||||
-DTESTS_SRC_DIR=\"$(top_srcdir)\" \
|
||||
@CHECK_CFLAGS@
|
||||
|
||||
tests_ecore_ecore_suite_LDADD = \
|
||||
lib/ecore_con/libecore_con.la \
|
||||
lib/ecore/libecore.la \
|
||||
lib/eina/libeina.la \
|
||||
@CHECK_LIBS@
|
||||
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Ecore.h>
|
||||
|
||||
#include "ecore_suite.h"
|
||||
|
||||
typedef struct _Ecore_Test_Case Ecore_Test_Case;
|
||||
|
||||
struct _Ecore_Test_Case
|
||||
{
|
||||
const char *test_case;
|
||||
void (*build)(TCase *tc);
|
||||
};
|
||||
|
||||
static const Ecore_Test_Case etc[] = {
|
||||
{ "Ecore", ecore_test_ecore },
|
||||
{ "Ecore_Con", ecore_test_ecore_con },
|
||||
{ "Ecore_X", ecore_test_ecore_x },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
_list_tests(void)
|
||||
{
|
||||
const Ecore_Test_Case *itr;
|
||||
|
||||
itr = etc;
|
||||
fputs("Available Test Cases:\n", stderr);
|
||||
for (; itr->test_case; itr++)
|
||||
fprintf(stderr, "\t%s\n", itr->test_case);
|
||||
}
|
||||
static Eina_Bool
|
||||
_use_test(int argc, const char **argv, const char *test_case)
|
||||
{
|
||||
if (argc < 1)
|
||||
return 1;
|
||||
|
||||
for (; argc > 0; argc--, argv++)
|
||||
if (strcmp(test_case, *argv) == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Suite *
|
||||
ecore_suite_build(int argc, const char **argv)
|
||||
{
|
||||
TCase *tc;
|
||||
Suite *s;
|
||||
int i;
|
||||
|
||||
s = suite_create("Ecore");
|
||||
|
||||
for (i = 0; etc[i].test_case; ++i)
|
||||
{
|
||||
if (!_use_test(argc, argv, etc[i].test_case)) continue;
|
||||
tc = tcase_create(etc[i].test_case);
|
||||
|
||||
etc[i].build(tc);
|
||||
|
||||
suite_add_tcase(s, tc);
|
||||
tcase_set_timeout(tc, 0);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
Suite *s;
|
||||
SRunner *sr;
|
||||
int i, failed_count;
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
if ((strcmp(argv[i], "-h") == 0) ||
|
||||
(strcmp(argv[i], "--help") == 0))
|
||||
{
|
||||
fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
|
||||
argv[0]);
|
||||
_list_tests();
|
||||
return 0;
|
||||
}
|
||||
else if ((strcmp(argv[i], "-l") == 0) ||
|
||||
(strcmp(argv[i], "--list") == 0))
|
||||
{
|
||||
_list_tests();
|
||||
return 0;
|
||||
}
|
||||
|
||||
s = ecore_suite_build(argc - 1, (const char **)argv + 1);
|
||||
sr = srunner_create(s);
|
||||
|
||||
srunner_run_all(sr, CK_ENV);
|
||||
failed_count = srunner_ntests_failed(sr);
|
||||
srunner_free(sr);
|
||||
|
||||
return (failed_count == 0) ? 0 : 255;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef _ECORE_SUITE_H
|
||||
#define _ECORE_SUITE_H
|
||||
|
||||
#include <check.h>
|
||||
|
||||
void ecore_test_ecore(TCase *tc);
|
||||
void ecore_test_ecore_con(TCase *tc);
|
||||
void ecore_test_ecore_x(TCase *tc);
|
||||
|
||||
|
||||
#endif /* _ECORE_SUITE_H */
|
|
@ -0,0 +1,366 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <Eina.h>
|
||||
#include <Ecore.h>
|
||||
|
||||
#include "ecore_suite.h"
|
||||
|
||||
static int _log_dom;
|
||||
#define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__)
|
||||
|
||||
static Eina_Bool
|
||||
_quit_cb(void *data)
|
||||
{
|
||||
Eina_Bool *val = data;
|
||||
*val = EINA_TRUE;
|
||||
ecore_main_loop_quit();
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_dummy_cb(void *data)
|
||||
{
|
||||
return !!data;
|
||||
}
|
||||
|
||||
START_TEST(ecore_test_ecore_init)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ecore_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
ret = ecore_shutdown();
|
||||
fail_if(ret != 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(ecore_test_ecore_main_loop)
|
||||
{
|
||||
Eina_Bool did = EINA_FALSE;
|
||||
Ecore_Timer *timer;
|
||||
int ret;
|
||||
|
||||
ret = ecore_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
timer = ecore_timer_add(0.0, _quit_cb, &did);
|
||||
fail_if(timer == NULL);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
fail_if(did == EINA_FALSE);
|
||||
|
||||
ret = ecore_shutdown();
|
||||
fail_if(ret != 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(ecore_test_ecore_main_loop_idler)
|
||||
{
|
||||
Eina_Bool did = EINA_FALSE;
|
||||
Ecore_Idler *idler;
|
||||
int ret;
|
||||
|
||||
ret = ecore_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
idler = ecore_idler_add(_quit_cb, &did);
|
||||
fail_if(idler == NULL);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
fail_if(did == EINA_FALSE);
|
||||
|
||||
ret = ecore_shutdown();
|
||||
fail_if(ret != 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(ecore_test_ecore_main_loop_idle_enterer)
|
||||
{
|
||||
Eina_Bool did = EINA_FALSE;
|
||||
Ecore_Idle_Enterer *idle_enterer;
|
||||
int ret;
|
||||
|
||||
ret = ecore_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
idle_enterer = ecore_idle_enterer_add(_quit_cb, &did);
|
||||
fail_if(idle_enterer == NULL);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
fail_if(did == EINA_FALSE);
|
||||
|
||||
ret = ecore_shutdown();
|
||||
fail_if(ret != 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(ecore_test_ecore_main_loop_idle_exiter)
|
||||
{
|
||||
Eina_Bool did = EINA_FALSE;
|
||||
Ecore_Timer *timer;
|
||||
Ecore_Idle_Exiter *idle_exiter;
|
||||
int ret;
|
||||
|
||||
ret = ecore_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
/* make system exit idle */
|
||||
timer = ecore_timer_add(0.0, _dummy_cb, (void *)(long)0);
|
||||
fail_if(timer == NULL);
|
||||
|
||||
idle_exiter = ecore_idle_exiter_add(_quit_cb, &did);
|
||||
fail_if(idle_exiter == NULL);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
fail_if(did == EINA_FALSE);
|
||||
|
||||
ret = ecore_shutdown();
|
||||
fail_if(ret != 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(ecore_test_ecore_main_loop_timer)
|
||||
{
|
||||
Eina_Bool did = EINA_FALSE;
|
||||
Ecore_Timer *timer;
|
||||
double start, end, elapsed;
|
||||
int ret;
|
||||
|
||||
ret = ecore_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
timer = ecore_timer_add(2.0, _quit_cb, &did);
|
||||
fail_if(timer == NULL);
|
||||
|
||||
start = ecore_time_get();
|
||||
ecore_main_loop_begin();
|
||||
end = ecore_time_get();
|
||||
elapsed = end - start;
|
||||
|
||||
fail_if(did == EINA_FALSE);
|
||||
fail_if(elapsed < 2.0);
|
||||
fail_if(elapsed > 3.0); /* 1 second "error margin" */
|
||||
|
||||
ret = ecore_shutdown();
|
||||
fail_if(ret != 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static Eina_Bool _timer3(void *data EINA_UNUSED)
|
||||
{
|
||||
/* timer 3, do nothing */
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static Eina_Bool _timer2(void *data EINA_UNUSED)
|
||||
{
|
||||
/* timer 2, quit inner mainloop */
|
||||
ecore_main_loop_quit();
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static Eina_Bool _timer1(void *data)
|
||||
{
|
||||
/* timer 1, begin inner mainloop */
|
||||
int *times = data;
|
||||
(*times)++;
|
||||
|
||||
ecore_timer_add(0.3, _timer2, NULL);
|
||||
ecore_timer_add(0.1, _timer3, NULL);
|
||||
ecore_main_loop_begin();
|
||||
|
||||
ecore_main_loop_quit();
|
||||
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
START_TEST(ecore_test_ecore_main_loop_timer_inner)
|
||||
{
|
||||
Ecore_Timer *timer;
|
||||
int ret;
|
||||
int times = 0;
|
||||
|
||||
ret = ecore_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
timer = ecore_timer_add(1.0, _timer1, ×);
|
||||
fail_if(timer == NULL);
|
||||
|
||||
/* BEGIN: outer mainloop */
|
||||
ecore_main_loop_begin();
|
||||
/*END: outer mainloop */
|
||||
|
||||
fail_if(times != 1);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static Eina_Bool
|
||||
_fd_handler_cb(void *data, Ecore_Fd_Handler *handler EINA_UNUSED)
|
||||
{
|
||||
/* FIXME: why setting val if it is overwritten just after and what is its purpose ??? */
|
||||
Eina_Bool *val = data;
|
||||
|
||||
*val = EINA_TRUE;
|
||||
ecore_main_loop_quit();
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
START_TEST(ecore_test_ecore_main_loop_fd_handler)
|
||||
{
|
||||
Eina_Bool did = EINA_FALSE;
|
||||
Ecore_Fd_Handler *fd_handler;
|
||||
int comm[2];
|
||||
int ret;
|
||||
|
||||
ret = ecore_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
ret = pipe(comm);
|
||||
fail_if(ret != 0);
|
||||
|
||||
fd_handler = ecore_main_fd_handler_add
|
||||
(comm[0], ECORE_FD_READ, _fd_handler_cb, &did, NULL, NULL);
|
||||
fail_if(fd_handler == NULL);
|
||||
|
||||
ret = write(comm[1], &did, 1);
|
||||
fail_if(ret != 1);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
close(comm[0]);
|
||||
close(comm[1]);
|
||||
|
||||
fail_if(did == EINA_FALSE);
|
||||
|
||||
ret = ecore_shutdown();
|
||||
fail_if(ret != 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static Eina_Bool
|
||||
_event_handler_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
|
||||
{
|
||||
/* FIXME: why setting val if it is overwritten just after and what is its purpose ??? */
|
||||
Eina_Bool *val = data;
|
||||
|
||||
*val = EINA_TRUE;
|
||||
ecore_main_loop_quit();
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
START_TEST(ecore_test_ecore_main_loop_event)
|
||||
{
|
||||
Eina_Bool did = EINA_FALSE;
|
||||
Ecore_Event_Handler *handler;
|
||||
Ecore_Event *event;
|
||||
int ret, type;
|
||||
|
||||
ret = ecore_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
type = ecore_event_type_new();
|
||||
fail_if(type < 1);
|
||||
|
||||
handler = ecore_event_handler_add(type, _event_handler_cb, &did);
|
||||
fail_if(handler == NULL);
|
||||
|
||||
event = ecore_event_add(type, NULL, NULL, NULL);
|
||||
fail_if(event == NULL);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
fail_if(did == EINA_FALSE);
|
||||
|
||||
ret = ecore_shutdown();
|
||||
fail_if(ret != 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static Eina_Bool
|
||||
_timer_quit_recursive(void *data EINA_UNUSED)
|
||||
{
|
||||
INF(" _timer_quit_recursive: begin");
|
||||
ecore_main_loop_quit(); /* quits inner main loop */
|
||||
INF(" _timer_quit_recursive: end");
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_event_recursive_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
|
||||
{
|
||||
static int guard = 0;
|
||||
|
||||
/* If we enter this callback more than once, it's wrong! */
|
||||
fail_if(guard != 0);
|
||||
guard++;
|
||||
|
||||
INF(" event_recursive_cb: begin");
|
||||
|
||||
ecore_timer_add(1.0, _timer_quit_recursive, NULL);
|
||||
INF(" add 1.0s timer (once) to trigger _timer_quit_recursive");
|
||||
|
||||
INF(" inner main loop begin (recurse)");
|
||||
ecore_main_loop_begin();
|
||||
INF(" inner main loop end (recurse)");
|
||||
|
||||
ecore_main_loop_quit(); /* quits outer main loop */
|
||||
|
||||
INF(" guard = %d", guard);
|
||||
INF(" event_recursive_cb: end");
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
|
||||
START_TEST(ecore_test_ecore_main_loop_event_recursive)
|
||||
{
|
||||
/* This test tests if the event handlers are really called only once when
|
||||
* recursive main loops are used and any number of events may have occurred
|
||||
* between the beginning and the end of recursive main loop.
|
||||
*/
|
||||
Ecore_Event *e;
|
||||
int type;
|
||||
int ret;
|
||||
|
||||
_log_dom = eina_log_domain_register("test", EINA_COLOR_CYAN);
|
||||
|
||||
INF("main: begin");
|
||||
ret = ecore_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
|
||||
type = ecore_event_type_new();
|
||||
ecore_event_handler_add(type, _event_recursive_cb, NULL);
|
||||
e = ecore_event_add(type, NULL, NULL, NULL);
|
||||
INF(" add event to trigger cb1: event=%p", e);
|
||||
INF(" main loop begin");
|
||||
ecore_main_loop_begin();
|
||||
INF(" main loop end");
|
||||
|
||||
INF("main: end");
|
||||
ecore_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void ecore_test_ecore(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, ecore_test_ecore_init);
|
||||
tcase_add_test(tc, ecore_test_ecore_main_loop);
|
||||
tcase_add_test(tc, ecore_test_ecore_main_loop_idler);
|
||||
tcase_add_test(tc, ecore_test_ecore_main_loop_idle_enterer);
|
||||
tcase_add_test(tc, ecore_test_ecore_main_loop_idle_exiter);
|
||||
tcase_add_test(tc, ecore_test_ecore_main_loop_timer);
|
||||
tcase_add_test(tc, ecore_test_ecore_main_loop_fd_handler);
|
||||
tcase_add_test(tc, ecore_test_ecore_main_loop_event);
|
||||
tcase_add_test(tc, ecore_test_ecore_main_loop_timer_inner);
|
||||
tcase_add_test(tc, ecore_test_ecore_main_loop_event_recursive);
|
||||
}
|
|
@ -0,0 +1,258 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <Ecore_Con.h>
|
||||
|
||||
#include "ecore_suite.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Ecore.h>
|
||||
#include <Ecore_Con.h>
|
||||
|
||||
Eina_Bool
|
||||
_add(void *data, int type EINA_UNUSED, void *ev)
|
||||
{
|
||||
fail_if (type != ECORE_CON_EVENT_CLIENT_ADD &&
|
||||
type != ECORE_CON_EVENT_SERVER_ADD);
|
||||
|
||||
/* Server */
|
||||
if (type == ECORE_CON_EVENT_CLIENT_ADD)
|
||||
{
|
||||
Ecore_Con_Event_Client_Add *event = ev;
|
||||
|
||||
fail_if (data != (void *) 1);
|
||||
fail_if (!event->client);
|
||||
|
||||
printf("Client with ip %s, port %d, connected = %d!\n",
|
||||
ecore_con_client_ip_get(event->client),
|
||||
ecore_con_client_port_get(event->client),
|
||||
ecore_con_client_connected_get(event->client));
|
||||
|
||||
ecore_con_client_timeout_set(event->client, 10);
|
||||
|
||||
}
|
||||
else if (type == ECORE_CON_EVENT_SERVER_ADD)
|
||||
{
|
||||
Ecore_Con_Event_Server_Add *event = ev;
|
||||
const char ping[] = "PING";
|
||||
int ret;
|
||||
|
||||
fail_if (data != (void *) 2);
|
||||
fail_if (!event->server);
|
||||
printf("Server with ip %s, name %s, port %d, connected = %d!\n",
|
||||
ecore_con_server_ip_get(event->server),
|
||||
ecore_con_server_name_get(event->server),
|
||||
ecore_con_server_port_get(event->server),
|
||||
ecore_con_server_connected_get(event->server));
|
||||
ret = ecore_con_server_send(event->server, ping, sizeof(ping));
|
||||
fail_if (ret != sizeof(ping));
|
||||
ecore_con_server_flush(event->server);
|
||||
}
|
||||
|
||||
return ECORE_CALLBACK_RENEW;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
_del(void *data , int type EINA_UNUSED, void *ev)
|
||||
{
|
||||
fail_if (type != ECORE_CON_EVENT_CLIENT_DEL &&
|
||||
type != ECORE_CON_EVENT_SERVER_DEL);
|
||||
|
||||
/* Server */
|
||||
if (type == ECORE_CON_EVENT_CLIENT_DEL)
|
||||
{
|
||||
Ecore_Con_Event_Client_Del *event = ev;
|
||||
|
||||
fail_if (data != (void *) 1);
|
||||
fail_if (!event->client);
|
||||
|
||||
printf("Lost client with ip %s!\n", ecore_con_client_ip_get(event->client));
|
||||
printf("Client was connected for %0.3f seconds.\n",
|
||||
ecore_con_client_uptime_get(event->client));
|
||||
|
||||
ecore_con_client_del(event->client);
|
||||
}
|
||||
else if (type == ECORE_CON_EVENT_SERVER_DEL)
|
||||
{
|
||||
Ecore_Con_Event_Server_Del *event = ev;
|
||||
|
||||
fail_if (!event->server);
|
||||
|
||||
fail_if (data != (void *) 2);
|
||||
|
||||
printf("Lost server with ip %s!\n", ecore_con_server_ip_get(event->server));
|
||||
|
||||
ecore_con_server_del(event->server);
|
||||
}
|
||||
fail ();
|
||||
|
||||
return ECORE_CALLBACK_RENEW;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
_data(void *data, int type EINA_UNUSED, void *ev)
|
||||
{
|
||||
|
||||
fail_if (type != ECORE_CON_EVENT_CLIENT_DATA &&
|
||||
type != ECORE_CON_EVENT_SERVER_DATA);
|
||||
|
||||
/* Server */
|
||||
if (type == ECORE_CON_EVENT_CLIENT_DATA)
|
||||
{
|
||||
Ecore_Con_Event_Client_Data *event = ev;
|
||||
const char pong[] = "PONG";
|
||||
int ret;
|
||||
|
||||
char fmt[128];
|
||||
fail_if (data != (void *) 1);
|
||||
|
||||
snprintf(fmt, sizeof(fmt),
|
||||
"Received %i bytes from client %s port %d:\n"
|
||||
">>>>>\n"
|
||||
"%%.%is\n"
|
||||
">>>>>\n",
|
||||
event->size, ecore_con_client_ip_get(event->client),
|
||||
ecore_con_client_port_get(event->client), event->size);
|
||||
|
||||
printf(fmt, event->data);
|
||||
fail_if (event->size != sizeof("PING"));
|
||||
fail_if (memcmp (event->data, "PING", sizeof("PING")) != 0);
|
||||
|
||||
ret = ecore_con_client_send(event->client, pong, sizeof(pong));
|
||||
fail_if (ret != sizeof(pong));
|
||||
ecore_con_client_flush(event->client);
|
||||
}
|
||||
else if (type == ECORE_CON_EVENT_SERVER_DATA)
|
||||
{
|
||||
Ecore_Con_Event_Server_Data *event = ev;
|
||||
char fmt[128];
|
||||
|
||||
fail_if (data != (void *) 2);
|
||||
|
||||
snprintf(fmt, sizeof(fmt),
|
||||
"Received %i bytes from server:\n"
|
||||
">>>>>\n"
|
||||
"%%.%is\n"
|
||||
">>>>>\n",
|
||||
event->size, event->size);
|
||||
|
||||
printf(fmt, event->data);
|
||||
fail_if (event->size != sizeof("PONG"));
|
||||
fail_if (memcmp (event->data, "PONG", sizeof("PONG")) != 0);
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
return ECORE_CALLBACK_RENEW;
|
||||
}
|
||||
|
||||
START_TEST(ecore_test_ecore_con_server)
|
||||
{
|
||||
Ecore_Con_Server *server;
|
||||
Ecore_Con_Server *client;
|
||||
Ecore_Con_Client *cl;
|
||||
const Eina_List *clients, *l;
|
||||
Ecore_Event_Handler *handlers[6];
|
||||
void *server_data = malloc (1);
|
||||
void *client_data = malloc (1);
|
||||
int ret;
|
||||
void *del_ret;
|
||||
|
||||
ret = eina_init();
|
||||
fail_if(ret != 1);
|
||||
ret = ecore_init();
|
||||
fail_if(ret != 1);
|
||||
ret = ecore_con_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
handlers[0] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD,
|
||||
_add, (void *) 1);
|
||||
fail_if(handlers[0] == NULL);
|
||||
handlers[1] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL,
|
||||
_del, (void *) 1);
|
||||
fail_if(handlers[1] == NULL);
|
||||
handlers[2] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA,
|
||||
_data, (void *) 1);
|
||||
fail_if(handlers[2] == NULL);
|
||||
|
||||
handlers[3] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD,
|
||||
_add, (void *) 2);
|
||||
fail_if(handlers[3] == NULL);
|
||||
handlers[4] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL,
|
||||
_del, (void *) 2);
|
||||
fail_if(handlers[4] == NULL);
|
||||
handlers[5] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
|
||||
_data, (void *) 2);
|
||||
fail_if(handlers[5] == NULL);
|
||||
|
||||
server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, "::1", 8080,
|
||||
server_data);
|
||||
fail_if (server == NULL);
|
||||
|
||||
ecore_con_server_timeout_set(server, 10);
|
||||
ecore_con_server_client_limit_set(server, 1, 0);
|
||||
|
||||
client = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, "::1", 8080,
|
||||
client_data);
|
||||
fail_if (client == NULL);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
clients = ecore_con_server_clients_get(server);
|
||||
printf("Clients connected to this server when exiting: %d\n",
|
||||
eina_list_count(clients));
|
||||
EINA_LIST_FOREACH(clients, l, cl)
|
||||
{
|
||||
printf("%s\n", ecore_con_client_ip_get(cl));
|
||||
}
|
||||
|
||||
printf("Server was up for %0.3f seconds\n",
|
||||
ecore_con_server_uptime_get(server));
|
||||
|
||||
del_ret = ecore_con_server_del(server);
|
||||
fail_if (del_ret != server_data);
|
||||
free (server_data);
|
||||
del_ret = ecore_con_server_del(client);
|
||||
fail_if (del_ret != client_data);
|
||||
free (client_data);
|
||||
|
||||
del_ret = ecore_event_handler_del (handlers[0]);
|
||||
fail_if (del_ret != (void *) 1);
|
||||
del_ret = ecore_event_handler_del (handlers[1]);
|
||||
fail_if (del_ret != (void *) 1);
|
||||
del_ret = ecore_event_handler_del (handlers[2]);
|
||||
fail_if (del_ret != (void *) 1);
|
||||
|
||||
del_ret = ecore_event_handler_del (handlers[3]);
|
||||
fail_if (del_ret != (void *) 2);
|
||||
del_ret = ecore_event_handler_del (handlers[4]);
|
||||
fail_if (del_ret != (void *) 2);
|
||||
del_ret = ecore_event_handler_del (handlers[5]);
|
||||
fail_if (del_ret != (void *) 2);
|
||||
|
||||
ret = ecore_con_shutdown();
|
||||
fail_if(ret != 0);
|
||||
ret = ecore_shutdown();
|
||||
fail_if(ret != 0);
|
||||
ret = eina_shutdown();
|
||||
fail_if(ret != 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(ecore_test_ecore_con_init)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ecore_con_init();
|
||||
fail_if(ret != 1);
|
||||
|
||||
ret = ecore_con_shutdown();
|
||||
fail_if(ret != 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void ecore_test_ecore_con(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, ecore_test_ecore_con_init);
|
||||
tcase_add_test(tc, ecore_test_ecore_con_server);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <Ecore_X.h>
|
||||
|
||||
#include "ecore_suite.h"
|
||||
|
||||
/* FIXME: Currently disable these tests. They are useless ATM and they just
|
||||
* make buildbot complain. Once we add useful tests here we'll also bother
|
||||
* with getting X on the server. */
|
||||
#undef HAVE_ECORE_X_XLIB
|
||||
|
||||
/* TODO: change to HAVE_ECORE_X when xcb implementation is done */
|
||||
#ifdef HAVE_ECORE_X_XLIB
|
||||
|
||||
START_TEST(ecore_test_ecore_x_init)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ecore_x_init(NULL);
|
||||
fail_if(ret != 1);
|
||||
|
||||
ret = ecore_x_shutdown();
|
||||
fail_if(ret != 0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(ecore_test_ecore_x_bell)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
ret = ecore_x_init(NULL);
|
||||
fail_if(ret != 1);
|
||||
|
||||
printf("You should hear 3 beeps now.\n");
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
ret = ecore_x_bell(0);
|
||||
fail_if(ret != EINA_TRUE);
|
||||
ecore_x_sync();
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
ecore_x_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
#endif
|
||||
|
||||
void ecore_test_ecore_x(TCase *tc EINA_UNUSED)
|
||||
{
|
||||
|
||||
/* TODO: change to HAVE_ECORE_X when xcb implementation is done */
|
||||
#ifdef HAVE_ECORE_X_XLIB
|
||||
tcase_add_test(tc, ecore_test_ecore_x_init);
|
||||
tcase_add_test(tc, ecore_test_ecore_x_bell);
|
||||
#endif
|
||||
}
|
Loading…
Reference in New Issue