diff --git a/legacy/ecore/Makefile.am b/legacy/ecore/Makefile.am index 0da3fe6758..0989683299 100644 --- a/legacy/ecore/Makefile.am +++ b/legacy/ecore/Makefile.am @@ -159,7 +159,22 @@ endif .PHONY: doc +# Documentation + 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 diff --git a/legacy/ecore/configure.ac b/legacy/ecore/configure.ac index e0f2d74bfb..154469034d 100644 --- a/legacy/ecore/configure.ac +++ b/legacy/ecore/configure.ac @@ -274,6 +274,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 @@ -1380,6 +1384,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 @@ -1511,6 +1516,8 @@ 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 echo "Documentation..........: ${build_doc}" if test "x${build_doc}" = "xyes" ; then echo " Building.............: make doc" diff --git a/legacy/ecore/m4/efl_tests.m4 b/legacy/ecore/m4/efl_tests.m4 new file mode 100644 index 0000000000..3a4dfe246f --- /dev/null +++ b/legacy/ecore/m4/efl_tests.m4 @@ -0,0 +1,43 @@ +dnl Copyright (C) 2008 Vincent Torri +dnl That code is public domain and can be freely used or copied. + +dnl Macro that check if tests programs are wanted and if yes, if +dnl the Check library is available. + +dnl Usage: EFL_CHECK_TESTS([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) +dnl Define the automake conditionnal EFL_ENABLE_TESTS + +AC_DEFUN([EFL_CHECK_TESTS], +[ + +dnl configure option + +AC_ARG_ENABLE([tests], + [AC_HELP_STRING([--enable-tests], [enable tests @<:@default=disabled@:>@])], + [ + if test "x${enableval}" = "xyes" ; then + _efl_enable_tests="yes" + else + _efl_enable_tests="no" + fi + ], + [_efl_enable_tests="no"]) + +AC_MSG_CHECKING([whether tests are built]) +AC_MSG_RESULT([${_efl_enable_tests}]) + +AC_REQUIRE([PKG_PROG_PKG_CONFIG]) + +if test "x${_efl_enable_tests}" = "xyes" ; then + PKG_CHECK_MODULES([CHECK], + [check >= 0.9.5], + [dummy="yes"], + [_efl_enable_tests="no"]) +fi + +AM_CONDITIONAL(EFL_ENABLE_TESTS, test "x${_efl_enable_tests}" = "xyes") + +AS_IF([test "x$_efl_enable_tests" = "xyes"], [$1], [$2]) +]) + +dnl End of efl_tests.m4 diff --git a/legacy/ecore/src/Makefile.am b/legacy/ecore/src/Makefile.am index a8590b2f0d..a6fc38fef0 100644 --- a/legacy/ecore/src/Makefile.am +++ b/legacy/ecore/src/Makefile.am @@ -1,3 +1,3 @@ MAINTAINERCLEANFILES = Makefile.in -SUBDIRS = lib bin +SUBDIRS = lib bin tests diff --git a/legacy/ecore/src/tests/Makefile.am b/legacy/ecore/src/tests/Makefile.am new file mode 100644 index 0000000000..005e1c91c4 --- /dev/null +++ b/legacy/ecore/src/tests/Makefile.am @@ -0,0 +1,25 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +-I$(top_srcdir)/src/lib/ecore \ +-I$(top_srcdir)/src/lib/ecore_con \ +@EINA_CFLAGS@ \ +@CHECK_CFLAGS@ + +if EFL_ENABLE_TESTS + +check_PROGRAMS = ecore_suite + +ecore_suite_SOURCES = \ +ecore_suite.c \ +ecore_test_ecore.c \ +ecore_test_ecore_con.c + +ecore_suite_LDADD = \ +@CHECK_LIBS@ \ +$(top_builddir)/src/lib/ecore/libecore.la \ +$(top_builddir)/src/lib/ecore_con/libecore_con.la + +endif + +EXTRA_DIST = ecore_suite.h diff --git a/legacy/ecore/src/tests/ecore_suite.c b/legacy/ecore/src/tests/ecore_suite.c new file mode 100644 index 0000000000..9c7e199d19 --- /dev/null +++ b/legacy/ecore/src/tests/ecore_suite.c @@ -0,0 +1,102 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include + +#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 }, + { NULL, NULL } +}; + +static void +_list_tests(void) +{ + const Ecore_Test_Case *itr; + + itr = etc; + fputs("Available Test Cases:\n", stderr); + for (; itr->test_case != NULL; 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 != NULL; ++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_NORMAL); + failed_count = srunner_ntests_failed(sr); + srunner_free(sr); + + return (failed_count == 0) ? 0 : 255; +} diff --git a/legacy/ecore/src/tests/ecore_suite.h b/legacy/ecore/src/tests/ecore_suite.h new file mode 100644 index 0000000000..2e35ee7b7c --- /dev/null +++ b/legacy/ecore/src/tests/ecore_suite.h @@ -0,0 +1,10 @@ +#ifndef _ECORE_SUITE_H +#define _ECORE_SUITE_H + +#include + +void ecore_test_ecore(TCase *tc); +void ecore_test_ecore_con(TCase *tc); + + +#endif /* _ECORE_SUITE_H */ diff --git a/legacy/ecore/src/tests/ecore_test_ecore.c b/legacy/ecore/src/tests/ecore_test_ecore.c new file mode 100644 index 0000000000..79486bc94e --- /dev/null +++ b/legacy/ecore/src/tests/ecore_test_ecore.c @@ -0,0 +1,49 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "ecore_suite.h" + +static int +_timer_cb(void *data) +{ + ecore_main_loop_quit(); +} + +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) +{ + Ecore_Timer *timer = NULL; + int ret; + + ret = ecore_init(); + fail_if(ret != 1); + + timer = ecore_timer_add(0.5, _timer_cb, NULL); + fail_if(timer == NULL); + + ecore_main_loop_begin(); + + ret = ecore_shutdown(); + fail_if(ret != 0); +} +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); +} diff --git a/legacy/ecore/src/tests/ecore_test_ecore_con.c b/legacy/ecore/src/tests/ecore_test_ecore_con.c new file mode 100644 index 0000000000..3eba6121c5 --- /dev/null +++ b/legacy/ecore/src/tests/ecore_test_ecore_con.c @@ -0,0 +1,25 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#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); +}