put again ecore tests in the source tree

SVN revision: 56195
This commit is contained in:
Vincent Torri 2011-01-16 18:31:21 +00:00
parent b1b5620045
commit 6aa141ea7e
9 changed files with 616 additions and 1 deletions

View File

@ -180,3 +180,17 @@ endif
doc:
@echo "entering doc/"
make -C doc doc
# Unit tests
if EFL_ENABLE_TESTS
check-local:
@./src/tests/ecore_suite
else
check-local:
@echo "reconfigure with --enable-tests"
endif

View File

@ -307,6 +307,10 @@ if test "x${want_xim}" = "xyes" ; then
AC_DEFINE([ENABLE_XIM], [1], [Enable X Input Method])
fi
# Unit tests
EFL_CHECK_TESTS([enable_tests="yes"], [enable_tests="no"])
### Checks for programs
m4_ifdef([AC_PROG_OBJC],
@ -1432,6 +1436,7 @@ src/lib/ecore_wince/Makefile
src/lib/ecore_x/Makefile
src/lib/ecore_x/xlib/Makefile
src/lib/ecore_x/xcb/Makefile
src/tests/Makefile
README
ecore.spec
$po_makefile_in
@ -1565,6 +1570,7 @@ if test "x${have_ecore_evas}" = "xyes" ; then
echo " Software 16bit WinCE.......: $have_ecore_evas_software_16_wince"
fi
echo
echo " Tests................: ${enable_tests}"
echo " Maximum log level....: ${with_max_log_level}"
echo "Documentation..........: ${build_doc}"
echo

View File

@ -1,3 +1,3 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = lib bin
SUBDIRS = lib bin tests

View File

@ -0,0 +1,34 @@
MAINTAINERCLEANFILES = Makefile.in
AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib/ecore \
-I$(top_srcdir)/src/lib/ecore_con \
-I$(top_srcdir)/src/lib/ecore_x \
@EINA_CFLAGS@ \
@CHECK_CFLAGS@
if EFL_ENABLE_TESTS
noinst_PROGRAMS = ecore_suite
check_PROGRAMS = ecore_suite
ecore_suite_SOURCES = \
ecore_suite.c \
ecore_test_ecore.c \
ecore_test_ecore_con.c \
ecore_test_ecore_x.c
ecore_suite_LDADD = \
@CHECK_LIBS@ \
$(top_builddir)/src/lib/ecore/libecore.la \
$(top_builddir)/src/lib/ecore_con/libecore_con.la
if BUILD_ECORE_X
ecore_suite_LDADD += \
$(top_builddir)/src/lib/ecore_x/libecore_x.la
endif
endif
EXTRA_DIST = ecore_suite.h

View File

@ -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;
}

View File

@ -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 */

View File

@ -0,0 +1,366 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "ecore_suite.h"
#include <Ecore.h>
#include <Eina.h>
#include <unistd.h>
#include <stdio.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)
{
/* timer 3, do nothing */
return EINA_FALSE;
}
static Eina_Bool _timer2(void *data)
{
/* 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, &times);
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 __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 __UNUSED__, void *event __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)
{
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, int type, void *event)
{
Ecore_Event *e;
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);
}

View File

@ -0,0 +1,25 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <Ecore_Con.h>
#include "ecore_suite.h"
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);
}

View File

@ -0,0 +1,56 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <Ecore_X.h>
#include "ecore_suite.h"
/* 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)
{
/* 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
}