summaryrefslogtreecommitdiff
path: root/src/tests
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 /src/tests
parent8419f51ab8928e919d1d58c0690811f0ace132cb (diff)
Introduce check for unit testing framework of Elementary
Reviewers: seoz, tasn CC: tasn, cedric Differential Revision: https://phab.enlightenment.org/D91
Diffstat (limited to 'src/tests')
-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
6 files changed, 184 insertions, 0 deletions
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}