add unit tests framework with some examples.

pass --enable-tests to configure to enable them,
then 'make check' to run the tests.


SVN revision: 46456
This commit is contained in:
Vincent Torri 2010-02-25 08:05:56 +00:00
parent aab5142dd5
commit a02b17d2f5
9 changed files with 277 additions and 1 deletions

View File

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

View File

@ -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"

View File

@ -0,0 +1,43 @@
dnl Copyright (C) 2008 Vincent Torri <vtorri at univ-evry dot fr>
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

View File

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

View File

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

View File

@ -0,0 +1,102 @@
#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 },
{ 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;
}

View File

@ -0,0 +1,10 @@
#ifndef _ECORE_SUITE_H
#define _ECORE_SUITE_H
#include <check.h>
void ecore_test_ecore(TCase *tc);
void ecore_test_ecore_con(TCase *tc);
#endif /* _ECORE_SUITE_H */

View File

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

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