summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyuan Choi <ryuan.choi@gmail.com>2013-11-19 13:18:02 +0000
committerTom Hacohen <tom@stosb.com>2013-11-19 13:18:02 +0000
commit640f687383f5c6d928b562eb323937d3bd07f1ad (patch)
treeb66ed7bf2783ed5c1f07dd3052926bda9a07d152
parent8419f51ab8928e919d1d58c0690811f0ace132cb (diff)
Introduce check for unit testing framework of Elementary
Reviewers: seoz, tasn CC: tasn, cedric Differential Revision: https://phab.enlightenment.org/D91
-rw-r--r--.gitignore1
-rw-r--r--configure.ac18
-rw-r--r--src/Makefile.am4
-rw-r--r--src/tests/.gitignore5
-rw-r--r--src/tests/Makefile.am37
-rw-r--r--src/tests/elm_suite.c59
-rw-r--r--src/tests/elm_suite.h9
-rw-r--r--src/tests/elm_test_check.c56
-rw-r--r--src/tests/elm_test_init.c18
9 files changed, 207 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index abdbd65fc..8a3caf14e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,6 +38,7 @@ elementary-*-doc.tar.bz2
38/ltmain.sh 38/ltmain.sh
39/missing 39/missing
40/stamp-h1 40/stamp-h1
41/test-driver
41core 42core
42cscope.* 43cscope.*
43tags 44tags
diff --git a/configure.ac b/configure.ac
index 3358d6e1e..7188d394c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -617,6 +617,17 @@ if test "x$want_elementary_debug" = "xyes"; then
617fi 617fi
618AC_SUBST(ELM_DEBUG_DEF) 618AC_SUBST(ELM_DEBUG_DEF)
619 619
620AC_ARG_WITH([tests],
621 [AC_HELP_STRING([--with-tests=none|regular],
622 [choose elementary testing method: regular or none.(coverage will be supported)@<:@default=none@:>@])],
623 [build_tests=${withval}],
624 [build_tests=none])
625
626if test "${build_tests}" = "regular"; then
627 PKG_CHECK_MODULES([CHECK], [check >= 0.9.5])
628fi
629AM_CONDITIONAL([ENABLE_ELEMENTARY_TESTS], [test "${build_tests}" = "regular"])
630
620ELM_ALLOCA_H_DEF="#undef" 631ELM_ALLOCA_H_DEF="#undef"
621AC_CHECK_HEADER(alloca.h, [ELM_ALLOCA_H_DEF="#define"]) 632AC_CHECK_HEADER(alloca.h, [ELM_ALLOCA_H_DEF="#define"])
622AC_SUBST(ELM_ALLOCA_H_DEF) 633AC_SUBST(ELM_ALLOCA_H_DEF)
@@ -714,6 +725,7 @@ src/modules/test_entry/Makefile
714src/modules/test_map/Makefile 725src/modules/test_map/Makefile
715src/edje_externals/Makefile 726src/edje_externals/Makefile
716src/examples/Makefile 727src/examples/Makefile
728src/tests/Makefile
717data/Makefile 729data/Makefile
718data/themes/Makefile 730data/themes/Makefile
719data/images/Makefile 731data/images/Makefile
@@ -777,6 +789,12 @@ echo " CPPFLAGS.................: $CPPFLAGS"
777echo " CFLAGS...................: $CFLAGS" 789echo " CFLAGS...................: $CFLAGS"
778echo " LDFLAGS..................: $LDFLAGS" 790echo " LDFLAGS..................: $LDFLAGS"
779echo 791echo
792if test "${build_tests}" = "none"; then
793echo "Tests......................: no"
794else
795echo "Tests......................: make check"
796fi
797echo
780echo "Installation...............: make install (as root if needed, with 'su' or 'sudo')" 798echo "Installation...............: make install (as root if needed, with 'su' or 'sudo')"
781echo " prefix...................: $prefix" 799echo " prefix...................: $prefix"
782echo 800echo
diff --git a/src/Makefile.am b/src/Makefile.am
index abaa75d7d..b6dda4e5e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,3 +8,7 @@ SUBDIRS += modules edje_externals
8endif 8endif
9 9
10SUBDIRS += examples 10SUBDIRS += examples
11
12if ENABLE_ELEMENTARY_TESTS
13SUBDIRS += tests
14endif
diff --git a/src/tests/.gitignore b/src/tests/.gitignore
new file mode 100644
index 000000000..4a2ff4da7
--- /dev/null
+++ b/src/tests/.gitignore
@@ -0,0 +1,5 @@
1/elm_suite
2/check-results.xml
3/elm_suite.log
4/elm_suite.trs
5/test-suite.log
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
new file mode 100644
index 000000000..49fc645ac
--- /dev/null
+++ b/src/tests/Makefile.am
@@ -0,0 +1,37 @@
1AUTOMAKE_OPTIONS = 1.4 foreign
2MAINTAINERCLEANFILES = Makefile.in
3
4TESTS = elm_suite
5check_PROGRAMS = elm_suite
6elm_suite_SOURCES = \
7 elm_suite.c \
8 elm_test_check.c \
9 elm_test_init.c
10
11elm_suite_CPPFLAGS = \
12 -DTESTS_BUILD_DIR=\"${top_builddir}/src/tests\" \
13 -I$(top_srcdir)/src/lib \
14 -I$(top_builddir)/src/lib \
15 @CHECK_CFLAGS@ \
16 @ELEMENTARY_CFLAGS@ \
17 @ELEMENTARY_X_CFLAGS@ \
18 @ELEMENTARY_FB_CFLAGS@ \
19 @ELEMENTARY_SDL_CFLAGS@ \
20 @ELEMENTARY_WIN32_CFLAGS@ \
21 @ELEMENTARY_WINCE_CFLAGS@ \
22 @ELEMENTARY_ELOCATION_CFLAGS@ \
23 @ELEMENTARY_EWEATHER_CFLAGS@ \
24 @ELEMENTARY_WEB_CFLAGS@ \
25 @ELEMENTARY_EMAP_CFLAGS@ \
26 @ELEMENTARY_WAYLAND_CFLAGS@ \
27 @EVIL_CFLAGS@
28
29elm_suite_LDADD = \
30 $(top_builddir)/src/lib/libelementary.la \
31 @CHECK_LIBS@ \
32 @ELEMENTARY_EWEATHER_LIBS@ \
33 @ELEMENTARY_ELOCATION_LIBS@ \
34 @ELEMENTARY_EMAP_LIBS@ \
35 @ELEMENTARY_LIBS@ \
36 @ELEMENTARY_WEB_LIBS@ \
37 @my_libs@
diff --git a/src/tests/elm_suite.c b/src/tests/elm_suite.c
new file mode 100644
index 000000000..d3c09236c
--- /dev/null
+++ b/src/tests/elm_suite.c
@@ -0,0 +1,59 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Elementary.h>
6#include "elm_suite.h"
7
8typedef struct _Elementary_Test_Case Elementary_Test_Case;
9
10struct _Elementary_Test_Case
11{
12 const char *test_case;
13 void (*build)(TCase *tc);
14};
15
16static const Elementary_Test_Case etc[] = {
17 { "Elementary", elm_test_init },
18 { "elm_check", elm_test_check },
19 { NULL, NULL }
20};
21
22Suite *
23elm_suite()
24{
25 TCase *tc;
26 Suite *s;
27 int i;
28
29 s = suite_create("Elementary");
30
31 for (i = 0; etc[i].test_case; ++i)
32 {
33 tc = tcase_create(etc[i].test_case);
34 etc[i].build(tc);
35 suite_add_tcase(s, tc);
36 tcase_set_timeout(tc, 0);
37 }
38
39 return s;
40}
41
42int
43main(int argc __UNUSED__, char **argv __UNUSED__)
44{
45 int failed_count;
46 Suite *s;
47 SRunner *sr;
48
49 s = elm_suite();
50 sr = srunner_create(s);
51
52 srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml");
53
54 srunner_run_all(sr, CK_ENV);
55 failed_count = srunner_ntests_failed(sr);
56 srunner_free(sr);
57
58 return (failed_count == 0) ? 0 : 255;
59}
diff --git a/src/tests/elm_suite.h b/src/tests/elm_suite.h
new file mode 100644
index 000000000..ec13e38b2
--- /dev/null
+++ b/src/tests/elm_suite.h
@@ -0,0 +1,9 @@
1#ifndef _ELM_SUITE_H
2#define _ELM_SUITE_H
3
4#include <check.h>
5
6void elm_test_init(TCase *tc);
7void elm_test_check(TCase *tc);
8
9#endif /* _ELM_SUITE_H */
diff --git a/src/tests/elm_test_check.c b/src/tests/elm_test_check.c
new file mode 100644
index 000000000..5c3eb2d08
--- /dev/null
+++ b/src/tests/elm_test_check.c
@@ -0,0 +1,56 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Elementary.h>
6#include "elm_suite.h"
7
8START_TEST (elm_check_onoff_text)
9{
10 Evas_Object *win, *check;
11
12 elm_init(1, NULL);
13 win = elm_win_add(NULL, "check", ELM_WIN_BASIC);
14
15 check = elm_check_add(win);
16 elm_object_style_set(check, "toggle");
17 elm_object_part_text_set(check, "on", "OnText");
18 elm_object_part_text_set(check, "off", "OffText");
19
20 ck_assert_str_eq(elm_object_part_text_get(check, "on"), "OnText");
21 ck_assert_str_eq(elm_object_part_text_get(check, "off"), "OffText");
22
23 elm_object_style_set(check, "default");
24 ck_assert(elm_object_part_text_get(check, "on") == NULL);
25 ck_assert(elm_object_part_text_get(check, "off") == NULL);
26
27 elm_shutdown();
28}
29END_TEST
30
31START_TEST (elm_check_state)
32{
33 Evas_Object *win, *check;
34 Eina_Bool state = EINA_TRUE;
35
36 elm_init(1, NULL);
37 win = elm_win_add(NULL, "check", ELM_WIN_BASIC);
38
39 check = elm_check_add(win);
40 elm_check_state_pointer_set(check, &state);
41 ck_assert(elm_check_state_get(check) == EINA_TRUE);
42 ck_assert(state == EINA_TRUE);
43
44 elm_check_state_set(check, EINA_FALSE);
45 ck_assert(elm_check_state_get(check) == EINA_FALSE);
46 ck_assert(state == EINA_FALSE);
47
48 elm_shutdown();
49}
50END_TEST
51
52void elm_test_check(TCase *tc)
53{
54 tcase_add_test(tc, elm_check_onoff_text);
55 tcase_add_test(tc, elm_check_state);
56}
diff --git a/src/tests/elm_test_init.c b/src/tests/elm_test_init.c
new file mode 100644
index 000000000..3e3210c9f
--- /dev/null
+++ b/src/tests/elm_test_init.c
@@ -0,0 +1,18 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Elementary.h>
6#include "elm_suite.h"
7
8START_TEST (elm_main)
9{
10 ck_assert(elm_init(1, NULL) == 1);
11 ck_assert(elm_shutdown() == 0);
12}
13END_TEST
14
15void elm_test_init(TCase *tc)
16{
17 tcase_add_test(tc, elm_main);
18}